Search in sources :

Example 1 with AjaxResultDTO

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;
}
Also used : AjaxResultDTO(cn.dubidubi.model.base.dto.AjaxResultDTO) ExceptionHandler(org.springframework.web.bind.annotation.ExceptionHandler) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 2 with 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;
}
Also used : PicUrlToBase64DTO(cn.dubidubi.model.dto.PicUrlToBase64DTO) AjaxResultDTO(cn.dubidubi.model.base.dto.AjaxResultDTO) WxInfoDTO(cn.dubidubi.model.dto.WxInfoDTO) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ObjectOutputStream(java.io.ObjectOutputStream) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 3 with AjaxResultDTO

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;
}
Also used : AuthenticationException(org.apache.shiro.authc.AuthenticationException) UserDO(cn.dubidubi.model.base.UserDO) AjaxResultDTO(cn.dubidubi.model.base.dto.AjaxResultDTO) Subject(org.apache.shiro.subject.Subject) LockedAccountException(org.apache.shiro.authc.LockedAccountException) UsernamePasswordToken(org.apache.shiro.authc.UsernamePasswordToken) SavedRequest(org.apache.shiro.web.util.SavedRequest) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Aggregations

AjaxResultDTO (cn.dubidubi.model.base.dto.AjaxResultDTO)3 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)3 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 UserDO (cn.dubidubi.model.base.UserDO)1 PicUrlToBase64DTO (cn.dubidubi.model.dto.PicUrlToBase64DTO)1 WxInfoDTO (cn.dubidubi.model.dto.WxInfoDTO)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 ObjectOutputStream (java.io.ObjectOutputStream)1 AuthenticationException (org.apache.shiro.authc.AuthenticationException)1 LockedAccountException (org.apache.shiro.authc.LockedAccountException)1 UsernamePasswordToken (org.apache.shiro.authc.UsernamePasswordToken)1 Subject (org.apache.shiro.subject.Subject)1 SavedRequest (org.apache.shiro.web.util.SavedRequest)1 ExceptionHandler (org.springframework.web.bind.annotation.ExceptionHandler)1