| | |
| | | package com.dsh.guns.modular.system.controller.system; |
| | | |
| | | import com.dsh.course.feignClient.account.AppUserClient; |
| | | import com.dsh.course.feignClient.account.model.TAppUser; |
| | | import com.dsh.course.feignClient.auth.UserClient; |
| | | import com.dsh.course.feignClient.auth.model.GetTokenRequest; |
| | | import com.dsh.course.feignClient.auth.model.TokenResponse; |
| | | import com.dsh.course.model.node.MenuNode; |
| | | import com.dsh.course.util.RedisUtil; |
| | | import com.dsh.guns.config.UserExt; |
| | | import com.dsh.guns.core.util.ToolUtil; |
| | | import com.dsh.guns.modular.system.controller.util.CaptchaGenerator; |
| | | import com.dsh.guns.modular.system.controller.util.CaptchaImageGenerator; |
| | | import com.dsh.guns.modular.system.controller.util.MD5; |
| | | import com.dsh.guns.modular.system.model.Role; |
| | | import com.dsh.guns.modular.system.service.IRelationService; |
| | | import com.dsh.guns.modular.system.service.IRoleService; |
| | | import com.dsh.guns.modular.system.util.CacheUtil; |
| | | import com.dsh.guns.modular.system.util.ResultUtil; |
| | | import com.google.code.kaptcha.Constants; |
| | | import com.dsh.guns.core.base.controller.BaseController; |
| | | import com.dsh.guns.core.common.exception.InvalidKaptchaException; |
| | |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Controller; |
| | | import org.springframework.ui.Model; |
| | | import org.springframework.web.bind.annotation.PostMapping; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | import org.springframework.web.bind.annotation.RequestMethod; |
| | | |
| | | import javax.activation.MailcapCommandMap; |
| | | import javax.annotation.Resource; |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import java.awt.image.BufferedImage; |
| | | import java.util.*; |
| | | |
| | | /** |
| | |
| | | @Autowired |
| | | private IRoleService roleService; |
| | | |
| | | @Autowired |
| | | private AppUserClient appUserClient; |
| | | @Resource |
| | | private UserClient userClient; |
| | | |
| | |
| | | |
| | | |
| | | |
| | | /** |
| | | * 跳转到修改密码页面 |
| | | */ |
| | | @PostMapping("/update") |
| | | public String updatePassword(Model model) { |
| | | return "/password.html" ; |
| | | } |
| | | @Autowired |
| | | private RedisUtil redisUtil; |
| | | /** |
| | | * 点击登录执行的动作 |
| | | */ |
| | | @RequestMapping(value = "/updatePassword", method = RequestMethod.POST) |
| | | public Object loginVali(String username, String password,String code) { |
| | | |
| | | |
| | | User user = userService.getByAccount(username); |
| | | if (user==null)return "用户不存在"; |
| | | password = AESUtils.decrypt(password); |
| | | String s = MD5.md5(password); |
| | | if(user.getPassword().equals(s))return "新密码和旧密码一致"; |
| | | //验证短信验证码 |
| | | if(ToolUtil.isEmpty(code))return "无效的验证码"; |
| | | String value = redisUtil.getValue(user.getPhone()); |
| | | if(ToolUtil.isEmpty(value) || !code.equals(value))return "手机验证码不正确"; |
| | | user.setPassword(s); |
| | | return "修改成功!"; |
| | | } |
| | | /** |
| | | * 跳转到主页 |
| | | */ |
| | | @RequestMapping(value = "/", method = RequestMethod.GET) |
| | | public String index(Model model) { |
| | | // 判断是否第一次登录 如果是跳转至修改密码页面 |
| | | model.addAttribute("tips", ""); |
| | | //获取菜单列表 |
| | | User user = UserExt.getUser(); |
| | |
| | | User byId = userService.getById(user.getId()); |
| | | //获取用户头像 Obtain user profile |
| | | String avatar = byId.getAvatar(); |
| | | Integer objectType = user.getObjectType(); |
| | | |
| | | model.addAttribute("roleNames", role.getName()); |
| | | model.addAttribute("language", language); |
| | | model.addAttribute("avatar", avatar); |
| | |
| | | // ? a: ""); |
| | | return "/index.html"; |
| | | } |
| | | @RequestMapping("/getSMSCode") |
| | | public ResultUtil getSMSCode(String phone){ |
| | | if(ToolUtil.isEmpty(phone)){ |
| | | return ResultUtil.paranErr("phone"); |
| | | } |
| | | try { |
| | | TAppUser appUserByPhone = appUserClient.getAppUserByPhone(phone); |
| | | if (appUserByPhone==null)return ResultUtil.error("当前手机号未注册!"); |
| | | ResultUtil smsCode = userService.getSMSCode(phone); |
| | | return smsCode; |
| | | }catch (Exception e){ |
| | | e.printStackTrace(); |
| | | return ResultUtil.runErr(); |
| | | } |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 跳转到登录页面 |
| | | * 跳转到场地管理页面 |
| | | */ |
| | | @RequestMapping(value = "/login", method = RequestMethod.GET) |
| | | public String login() { |
| | | if (false || false) { |
| | | if (UserExt.getUser()!=null) { |
| | | return REDIRECT + "/"; |
| | | } else { |
| | | return "/login.html" ; |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 点击登录执行的动作 |
| | | */ |
| | |
| | | f++; |
| | | loginFailures.put(username, f); |
| | | } |
| | | |
| | | if (KaptchaUtil.getKaptchaOnOff()) { |
| | | String kaptcha = super.getPara("kaptcha").trim(); |
| | | String code = (String) super.getSession().getAttribute(Constants.KAPTCHA_SESSION_KEY); |
| | | if (Objects.isNull(kaptcha) || !kaptcha.equalsIgnoreCase(code)) { |
| | | model.addAttribute("tips", "验证码错误"); |
| | | return "/login.html"; |
| | | } |
| | | } |
| | | // if (f > 5 && (System.currentTimeMillis() - t) <= (30 * 60 * 1000)) { |
| | | // model.addAttribute("tips", "登录次数过多,请等30分钟再试!"); |
| | | // return "/login.html"; |
| | | // } |
| | | //验证验证码是否正确 |
| | | //Verify if the verification code is correct. |
| | | if (KaptchaUtil.getKaptchaOnOff()) { |
| | | String kaptcha = super.getPara("kaptcha").trim(); |
| | | String code = (String) super.getSession().getAttribute(Constants.KAPTCHA_SESSION_KEY); |
| | | if (Objects.isNull(kaptcha) || !kaptcha.equalsIgnoreCase(code)) { |
| | | throw new InvalidKaptchaException(); |
| | | } |
| | | } |
| | | User user = userService.getByAccount(username); |
| | | password = AESUtils.decrypt(password); |
| | | String s = MD5.md5(password); |
| | |
| | | model.addAttribute("tips", "账号密码错误"); |
| | | return "/login.html"; |
| | | } |
| | | if (user.getStatus() == 2){ |
| | | model.addAttribute("tips", "该账号已被冻结"); |
| | | return "/login.html"; |
| | | }else if (user.getStatus() == 3){ |
| | | model.addAttribute("tips", "该账号不存在"); |
| | | return "/login.html"; |
| | | } |
| | | |
| | | |
| | | GetTokenRequest tokenRequest = new GetTokenRequest(); |