Search in sources :

Example 21 with User

use of com.topcom.cms.domain.User in project topcom-cloud by 545314690.

the class LoginController method login2.

/**
 * 登录验证 登录成功后返回用户信息(为了测试,去掉验证码信息)
 *
 * @param request
 * @param response
 * @param username
 * @param password
 * @param captcha
 * @return
 * @throws SQLException
 */
@RequestMapping(value = "/login2", method = RequestMethod.POST)
@ResponseBody
public ModelMap login2(HttpServletRequest request, HttpServletResponse response, @RequestParam String username, @RequestParam String password, @RequestParam(required = false) String captcha, @RequestParam(required = false) Boolean admin, @RequestParam(required = false) Boolean rememberMe) throws AuthenticationException {
    ModelMap modelMap = new ModelMap("success", false);
    UsernamePasswordToken usernamePasswordToken = new UsernamePasswordToken(username, password);
    if (admin != null && admin == true) {
        usernamePasswordToken.setAdmin(admin);
    }
    boolean logined = SubjectUtil.login(usernamePasswordToken);
    // 验证是否登录成功
    if (logined) {
        modelMap.put("success", true);
        modelMap.put("message", "登录成功");
        String token = SubjectUtil.getLoginToken(username);
        User currentUser = SubjectUtil.getCurrentUser(token);
        request.getSession().setAttribute(Constants.CURRENT_USER, currentUser);
        modelMap.put("token", token);
        modelMap.put("user", currentUser.getFullName() == null ? username : currentUser.getFullName());
    } else {
        throw new AuthenticationException();
    }
    return modelMap;
}
Also used : User(com.topcom.cms.domain.User) AuthenticationException(com.topcom.cms.perm.exception.AuthenticationException) ModelMap(org.springframework.ui.ModelMap) UsernamePasswordToken(com.topcom.cms.perm.token.UsernamePasswordToken) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 22 with User

use of com.topcom.cms.domain.User in project topcom-cloud by 545314690.

the class LoginController method loginGet.

@RequestMapping(value = "/loginGet", method = RequestMethod.GET)
@ResponseBody
public ModelMap loginGet(HttpServletRequest request, HttpServletResponse response, @RequestParam String username, @RequestParam String password, @RequestParam(required = false) String captcha, @RequestParam(required = false) Boolean admin, @RequestParam(required = false) Boolean rememberMe) throws AuthenticationException {
    ModelMap modelMap = new ModelMap("success", false);
    UsernamePasswordToken usernamePasswordToken = new UsernamePasswordToken(username, password);
    if (admin != null && admin == true) {
        usernamePasswordToken.setAdmin(admin);
    }
    boolean logined = SubjectUtil.login(usernamePasswordToken);
    // 验证是否登录成功
    if (logined) {
        modelMap.put("success", true);
        modelMap.put("message", "登录成功");
        String token = SubjectUtil.getLoginToken(username);
        User currentUser = SubjectUtil.getCurrentUser(token);
        request.getSession().setAttribute(Constants.CURRENT_USER, currentUser);
        modelMap.put("token", token);
        modelMap.put("user", currentUser.getFullName() == null ? username : currentUser.getFullName());
    } else {
        throw new AuthenticationException();
    }
    return modelMap;
}
Also used : User(com.topcom.cms.domain.User) AuthenticationException(com.topcom.cms.perm.exception.AuthenticationException) ModelMap(org.springframework.ui.ModelMap) UsernamePasswordToken(com.topcom.cms.perm.token.UsernamePasswordToken) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 23 with User

use of com.topcom.cms.domain.User in project topcom-cloud by 545314690.

the class WarningJob method sendWechat.

/**
 * 发送微信
 * @param page
 * @param subject
 * @param wangningLogId
 */
private void sendWechat(Page page, CustomSubject subject, Long wangningLogId) {
    WarningTask warningTask = subject.getWarning();
    logger.info("开始推送Wechat消息:" + subject.getName());
    List<Contact> contacts = warningTask.getContacts();
    Set<String> wechatSet = contacts.stream().filter(contact -> Contact.Type.WECHAT.equals(contact.getType())).map(contact -> contact.getAccount()).collect(Collectors.toSet());
    WechatSendRequest wechatSendRequest = new WechatSendRequest();
    JSONObject data = getData(page.getContent());
    User user = userManager.findById(subject.getUserId());
    // userName
    setData(data, "name", user.getFullName() == null ? user.getUsername() : user.getFullName());
    setData(data, "subjectName", subject.getName());
    setData(data, "num", page.getTotalElements());
    wechatSendRequest.setData(data);
    wechatSendRequest.setTemplate_id(TEMPLATE_ID);
    wechatSendRequest.setUrl(warningEmailSetting.getLogUrl());
    if (wechatSet.size() > 0) {
        for (String s : wechatSet) {
            wechatSendRequest.setTouser(s);
            wechatUtil.sendTemplate(JSONObject.fromObject(wechatSendRequest));
        }
        warningTask.setLastWarningDate(new Date());
        warningManager.save(warningTask);
    }
}
Also used : WarningEmailBody(com.topcom.cms.yuqing.vo.email.WarningEmailBody) Date(java.util.Date) TemplateException(freemarker.template.TemplateException) Logger(org.jboss.logging.Logger) Autowired(org.springframework.beans.factory.annotation.Autowired) MessagingException(javax.mail.MessagingException) Job(org.quartz.Job) com.topcom.cms.yuqing.domain(com.topcom.cms.yuqing.domain) SubscriptionFollowerManager(com.topcom.cms.yuqing.service.SubscriptionFollowerManager) Map(java.util.Map) Pageable(org.springframework.data.domain.Pageable) CustomSubjectManager(com.topcom.cms.yuqing.service.CustomSubjectManager) Sender(com.topcom.cms.yuqing.task.sender.Sender) ServerProperties(org.springframework.boot.autoconfigure.web.ServerProperties) WechatUtil(com.topcom.cms.yuqing.utils.WechatUtil) WebUtils(org.springframework.web.util.WebUtils) JobExecutionContext(org.quartz.JobExecutionContext) UserManager(com.topcom.cms.service.UserManager) SenderFactory(com.topcom.cms.yuqing.task.sender.factory.SenderFactory) User(com.topcom.cms.domain.User) WechatSendRequest(com.topcom.cms.yuqing.vo.request.WechatSendRequest) WarningEmailSetting(com.topcom.cms.yuqing.vo.email.WarningEmailSetting) PageRequest(org.springframework.data.domain.PageRequest) Set(java.util.Set) IOException(java.io.IOException) Page(org.springframework.data.domain.Page) WarningManager(com.topcom.cms.yuqing.service.WarningManager) Collectors(java.util.stream.Collectors) EmailSenderFactory(com.topcom.cms.yuqing.task.sender.factory.EmailSenderFactory) JobExecutionException(org.quartz.JobExecutionException) WarningLogManager(com.topcom.cms.yuqing.service.WarningLogManager) Component(org.springframework.stereotype.Component) List(java.util.List) WeChat(com.topcom.cms.data.domain.WeChat) WarningEmail(com.topcom.cms.yuqing.vo.email.WarningEmail) PostConstruct(javax.annotation.PostConstruct) JSONObject(net.sf.json.JSONObject) WechatSendRequest(com.topcom.cms.yuqing.vo.request.WechatSendRequest) User(com.topcom.cms.domain.User) JSONObject(net.sf.json.JSONObject) Date(java.util.Date)

Example 24 with User

use of com.topcom.cms.domain.User in project topcom-cloud by 545314690.

the class WarningJob method sendEmail.

private void sendEmail(Page page, CustomSubject subject, Long wangningLogId) {
    WarningTask warningTask = subject.getWarning();
    // logger.info("开始推送Email消息:" + subject.getName());
    List<Contact> contacts = warningTask.getContacts();
    /**
     * 获取所有联系人
     */
    Set<String> emailSet = contacts.stream().filter(contact -> Contact.Type.EMAIL.equals(contact.getType())).map(contact -> contact.getAccount()).collect(Collectors.toSet());
    logger.info("开始推送Email消息:" + subject.getName() + emailSet.toString());
    if (emailSet.size() > 0) {
        /**
         *先保存预警日志,否则下面warningLog.getId()取到的日志Id总为0,保存日志的时候,不要调用save
         */
        // 发送邮件
        SenderFactory emailSenderFactory = new EmailSenderFactory();
        Sender emailSender = emailSenderFactory.create();
        String[] emails = {};
        emails = emailSet.toArray(emails);
        try {
            WarningEmailBody warningEmailBody = new WarningEmailBody();
            warningEmailBody.setContent(page.getContent());
            warningEmailBody.setSpecialNumber(String.valueOf(page.getTotalElements()));
            warningEmailBody.setSpecialName(subject.getName());
            User user = userManager.findById(subject.getUserId());
            warningEmailBody.setUser(user.getFullName() == null ? user.getUsername() : user.getFullName());
            // warningEmailBody.setSubject("");
            warningEmailBody.setSpecialUrl(warningEmailSetting.getSubjectUrl() + subject.getId());
            warningEmailBody.setWarningLogUrl(warningEmailSetting.getLogUrl() + wangningLogId);
            WarningEmail warningEmail = new WarningEmail().create(emails, warningEmailBody);
            emailSender.send(warningEmail);
            // 更新上次预警时间
            warningTask.setLastWarningDate(new Date());
            warningManager.save(warningTask);
        } catch (IOException | TemplateException e) {
            e.printStackTrace();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
Also used : WarningEmailBody(com.topcom.cms.yuqing.vo.email.WarningEmailBody) Date(java.util.Date) TemplateException(freemarker.template.TemplateException) Logger(org.jboss.logging.Logger) Autowired(org.springframework.beans.factory.annotation.Autowired) MessagingException(javax.mail.MessagingException) Job(org.quartz.Job) com.topcom.cms.yuqing.domain(com.topcom.cms.yuqing.domain) SubscriptionFollowerManager(com.topcom.cms.yuqing.service.SubscriptionFollowerManager) Map(java.util.Map) Pageable(org.springframework.data.domain.Pageable) CustomSubjectManager(com.topcom.cms.yuqing.service.CustomSubjectManager) Sender(com.topcom.cms.yuqing.task.sender.Sender) ServerProperties(org.springframework.boot.autoconfigure.web.ServerProperties) WechatUtil(com.topcom.cms.yuqing.utils.WechatUtil) WebUtils(org.springframework.web.util.WebUtils) JobExecutionContext(org.quartz.JobExecutionContext) UserManager(com.topcom.cms.service.UserManager) SenderFactory(com.topcom.cms.yuqing.task.sender.factory.SenderFactory) User(com.topcom.cms.domain.User) WechatSendRequest(com.topcom.cms.yuqing.vo.request.WechatSendRequest) WarningEmailSetting(com.topcom.cms.yuqing.vo.email.WarningEmailSetting) PageRequest(org.springframework.data.domain.PageRequest) Set(java.util.Set) IOException(java.io.IOException) Page(org.springframework.data.domain.Page) WarningManager(com.topcom.cms.yuqing.service.WarningManager) Collectors(java.util.stream.Collectors) EmailSenderFactory(com.topcom.cms.yuqing.task.sender.factory.EmailSenderFactory) JobExecutionException(org.quartz.JobExecutionException) WarningLogManager(com.topcom.cms.yuqing.service.WarningLogManager) Component(org.springframework.stereotype.Component) List(java.util.List) WeChat(com.topcom.cms.data.domain.WeChat) WarningEmail(com.topcom.cms.yuqing.vo.email.WarningEmail) PostConstruct(javax.annotation.PostConstruct) JSONObject(net.sf.json.JSONObject) WarningEmailBody(com.topcom.cms.yuqing.vo.email.WarningEmailBody) User(com.topcom.cms.domain.User) TemplateException(freemarker.template.TemplateException) IOException(java.io.IOException) WarningEmail(com.topcom.cms.yuqing.vo.email.WarningEmail) Date(java.util.Date) TemplateException(freemarker.template.TemplateException) MessagingException(javax.mail.MessagingException) IOException(java.io.IOException) JobExecutionException(org.quartz.JobExecutionException) Sender(com.topcom.cms.yuqing.task.sender.Sender) EmailSenderFactory(com.topcom.cms.yuqing.task.sender.factory.EmailSenderFactory) SenderFactory(com.topcom.cms.yuqing.task.sender.factory.SenderFactory) EmailSenderFactory(com.topcom.cms.yuqing.task.sender.factory.EmailSenderFactory)

Aggregations

User (com.topcom.cms.domain.User)24 CurrentUser (com.topcom.cms.web.bind.annotation.CurrentUser)9 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)5 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)5 PageRequest (org.springframework.data.domain.PageRequest)4 Pageable (org.springframework.data.domain.Pageable)4 Group (com.topcom.cms.domain.Group)3 Resource (com.topcom.cms.domain.Resource)3 ApiOperation (io.swagger.annotations.ApiOperation)3 JSONObject (net.sf.json.JSONObject)3 WeChat (com.topcom.cms.data.domain.WeChat)2 BusinessException (com.topcom.cms.exception.BusinessException)2 AuthenticationException (com.topcom.cms.perm.exception.AuthenticationException)2 UsernamePasswordToken (com.topcom.cms.perm.token.UsernamePasswordToken)2 UserManager (com.topcom.cms.service.UserManager)2 com.topcom.cms.yuqing.domain (com.topcom.cms.yuqing.domain)2 CustomSubjectManager (com.topcom.cms.yuqing.service.CustomSubjectManager)2 SubscriptionFollowerManager (com.topcom.cms.yuqing.service.SubscriptionFollowerManager)2 WarningLogManager (com.topcom.cms.yuqing.service.WarningLogManager)2 WarningManager (com.topcom.cms.yuqing.service.WarningManager)2