use of cn.dubidubi.model.base.dto.AjaxResultDTO in project dubidubi by lzzzz4.
the class BaseExceptionController method ajaxUnAuthorHandle.
@ExceptionHandler(UnauthorizedException.class)
@ResponseBody
public /**
* @Description:当ajax请求页面时,未授权用户抛出的异常处理
* @param response
* @return
*/
AjaxResultDTO ajaxUnAuthorHandle(HttpServletResponse response) {
AjaxResultDTO ajaxResultDTO = new AjaxResultDTO();
// 设置错误码为1000,授权失败
ajaxResultDTO.setCode(1000);
return ajaxResultDTO;
}
use of cn.dubidubi.model.base.dto.AjaxResultDTO in project dubidubi by lzzzz4.
the class GetPicByKeyController method key.
/**
* @throws IOException
* @throws ExecutionException
* @throws InterruptedException
* @Description: 界面输入关键词,执行爬虫,异步将内容发送至用户的邮箱
* @data :@param getPicDTO
* @data :@param file
* @data :@param request
* @data :@return
* @date :2018年3月20日下午12:55:12
*/
@RequestMapping("/key")
@ResponseBody
public AjaxResultDTO key(GetPicDTO getPicDTO, @RequestParam(required = false) MultipartFile file, HttpServletRequest request) throws InterruptedException, ExecutionException, IOException {
AjaxResultDTO resultDTO = new AjaxResultDTO();
WxInfoDTO wxInfoDTO = (WxInfoDTO) request.getSession().getAttribute("user");
if (mailInfoMapper.listMailByOpenid(wxInfoDTO.getOpenid()) == null || mailInfoMapper.listMailByOpenid(wxInfoDTO.getOpenid()).size() == 0) {
resultDTO.setCode(500);
}
// 当为九妹源时
if ("2".equals(getPicDTO.getSource())) {
// System.out.println("九妹源");
resultDTO.setUid(wxInfoDTO.getOpenid());
Future<PicUrlToBase64DTO> list = pyBeautifuGirlSerivce.startPy(getPicDTO.getKey(), wxInfoDTO.getOpenid(), getPicDTO.getTime());
pyBeautifuGirlSerivce.waitForComplete(list);
resultDTO.setUrl("/9mei_suc.html");
resultDTO.setCode(9);
} else {
// System.out.println("百度源");
if (getPicDTO.getAmount() == null) {
getPicDTO.setAmount(4);
}
int pn = RandomUtils.nextInt(0, 10) * getPicDTO.getAmount();
// 链接 标题为一组
List<String> strings = pyBeautifuGirlSerivce.startPy(0, 0, getPicDTO.getKey(), pn, getPicDTO.getAmount());
PicUrlToBase64DTO picUrlToBase64DTO = new PicUrlToBase64DTO();
picUrlToBase64DTO.setOpenId(wxInfoDTO.getOpenid());
picUrlToBase64DTO.setList(strings);
picUrlToBase64DTO.setMail(mailInfoMapper.listMailByOpenid(wxInfoDTO.getOpenid()));
// 将对象序列化为base64字符串
ByteArrayOutputStream arrayOutputStream = new ByteArrayOutputStream();
ObjectOutputStream objectOutputStream = new ObjectOutputStream(arrayOutputStream);
objectOutputStream.writeObject(picUrlToBase64DTO);
// 将序列化的对象存入job中执行
String str = Base64.encodeBase64URLSafeString(arrayOutputStream.toByteArray());
Quartz.addJob(pyBeautifuGirlSerivce.randomString(wxInfoDTO.getOpenid(), "job"), pyBeautifuGirlSerivce.randomString(wxInfoDTO.getOpenid(), "jobgroup"), pyBeautifuGirlSerivce.randomString(wxInfoDTO.getOpenid(), "trigger"), pyBeautifuGirlSerivce.randomString(wxInfoDTO.getOpenid(), "triggergroup"), BaiduMailJob.class, pyBeautifuGirlSerivce.dateToCron(getPicDTO.getTime()), "str", str);
resultDTO.setCode(200);
resultDTO.setUrl("/9mei_suc.html");
IOUtils.closeQuietly(arrayOutputStream);
IOUtils.closeQuietly(objectOutputStream);
}
// System.out.println(resultDTO);
return resultDTO;
}
use of cn.dubidubi.model.base.dto.AjaxResultDTO in project dubidubi by lzzzz4.
the class LoginController method ajaxLogin.
/**
* @Description: ajax方式访问url
* 404 认证错误
* 403 账户被锁定错误
* 500 无上传对象错误
* 200 成功
* @return ajax返回值对象
* @throws IOException
*/
@RequestMapping(value = "/doLogin", headers = "X-Requested-With=XMLHttpRequest")
@ResponseBody
public AjaxResultDTO ajaxLogin(UserLoginDTO userLoginDTO, HttpServletRequest request, HttpServletResponse response) throws AuthorizationException, IOException {
AjaxResultDTO ajaxResultDTO = new AjaxResultDTO();
Subject subject = SecurityUtils.getSubject();
if (StringUtils.isNotBlank(userLoginDTO.getAccount()) && StringUtils.isNotBlank(userLoginDTO.getPassword())) {
UsernamePasswordToken token = new UsernamePasswordToken(userLoginDTO.getAccount(), userLoginDTO.getPassword());
// 调取realm
try {
subject.login(token);
} catch (LockedAccountException e) {
// 账户被锁定
ajaxResultDTO.setCode(403);
e.printStackTrace();
return ajaxResultDTO;
} catch (AuthenticationException e) {
// 认证错误
ajaxResultDTO.setCode(404);
e.printStackTrace();
return ajaxResultDTO;
}
} else {
// 无上传数值错误
ajaxResultDTO.setCode(500);
}
// 往session中放入用户数据
UserDO userDO = (UserDO) subject.getPrincipal();
request.getSession().setAttribute("user", userDO);
// 设置状态为成功
ajaxResultDTO.setCode(200);
// 设置cookie
loginCookieService.addLoginCookie(userLoginDTO, response);
// 得到跳转前的url
SavedRequest savedRequest = WebUtils.getSavedRequest(request);
// 当savedrequest对象为空
if (savedRequest == null) {
ajaxResultDTO.setUrl(defaultPath);
}
String URL = savedRequest.getRequestUrl();
// 判断url是否为空
if (URL != null) {
int URLStart = URL.indexOf("/", 1);
String realURL = URL.substring(URLStart, URL.length());
ajaxResultDTO.setUrl(realURL);
} else {
ajaxResultDTO.setUrl(defaultPath);
}
return ajaxResultDTO;
}
Aggregations