use of com.tony.billing.entity.Admin in project BillingDubbo by TonyJiangWJ.
the class AdminServiceImpl method preResetPwd.
@Override
public Admin preResetPwd(String userName) {
Admin user = mapper.queryByUserName(userName);
if (user != null) {
String email = user.getEmail();
if (StringUtils.isNotEmpty(email)) {
String token = sha256(UUID.randomUUID().toString());
user = deleteSecret(user);
redisUtils.set(token, deleteSecret(user), 3600);
user.setTokenId(token);
// TODO send reset email
Map<String, Object> contents = new HashMap<>();
contents.put("title", "重置密码");
contents.put("typeDesc", "重置密码");
contents.put("resetLink", resetPwdUrl + "?token=" + token);
try {
emailService.sendThymeleafMail(email, "用户重置密码", contents, EnumMailTemplateName.RESET_PWD_MAIL.getTemplateName());
} catch (MessagingException e) {
throw new BaseBusinessException("发送重置邮件失败");
}
return user;
}
}
throw new BaseBusinessException("用户名不存在, 或者未绑定邮箱");
}
use of com.tony.billing.entity.Admin in project BillingDubbo by TonyJiangWJ.
the class AdminServiceImpl method modifyPwd.
@Override
public boolean modifyPwd(ModifyAdmin admin) {
Preconditions.checkNotNull(admin.getId(), "用户id不能为空");
Admin dbAdmin = mapper.getAdminById(admin.getId());
if (dbAdmin == null) {
return false;
}
boolean isOldPassword = dbAdmin.getPasswordVersion() == null || dbAdmin.getPasswordVersion().equals(0);
// 现将密码进行加解密处理
admin.setNewPassword(sha256(rsaUtil.decrypt(admin.getNewPassword()), dbAdmin.getUserName()));
if (isOldPassword) {
admin.setPassword(sha256(rsaUtil.decrypt(admin.getPassword())));
} else {
admin.setPassword(sha256(rsaUtil.decrypt(admin.getPassword()), dbAdmin.getUserName()));
}
if (admin.getNewPassword() == null) {
return false;
}
Admin stored = mapper.getAdminById(admin.getId());
if (stored != null && StringUtils.equals(stored.getPassword(), admin.getPassword())) {
stored.setPassword(admin.getNewPassword());
return mapper.modifyPwd(stored) > 0;
}
logger.error("用户:{} 修改密码,旧密码不正确", admin.getId());
return false;
}
use of com.tony.billing.entity.Admin in project BillingDubbo by TonyJiangWJ.
the class AdminServiceImpl method login.
@Override
public Admin login(Admin admin) {
Admin dbAdmin = mapper.queryByUserName(admin.getUserName());
boolean isOldPassword = dbAdmin.getPasswordVersion() == null || dbAdmin.getPasswordVersion().equals(0);
String password = rsaUtil.decrypt(admin.getPassword());
if (isOldPassword) {
admin.setPassword(sha256(password));
} else {
admin.setPassword(sha256(password, admin.getUserName()));
}
if (admin.getPassword() == null) {
logger.error("password error");
return null;
}
Admin checkUser = mapper.preLogin(admin);
if (checkUser != null) {
redisUtils.del(checkUser.getTokenId());
checkUser.setTokenId(TokenUtil.getToken(checkUser.getCode(), checkUser.getUserName(), checkUser.getPassword()));
checkUser.setTokenVerify(VERIFY_TIME);
checkUser.setLastLogin(new Date());
if (mapper.doLogin(checkUser) > 0) {
redisUtils.set(checkUser.getTokenId(), deleteSecret(checkUser), VERIFY_TIME / 1000);
if (isOldPassword) {
// 更新密码
checkUser.setPasswordVersion(1);
checkUser.setPassword(sha256(password, checkUser.getUserName()));
mapper.update(checkUser);
}
return checkUser;
}
}
return null;
}
use of com.tony.billing.entity.Admin in project BillingDubbo by TonyJiangWJ.
the class AdminController method login.
@RequestMapping(value = "/user/login", method = RequestMethod.POST)
public BaseResponse login(@ModelAttribute("request") @Validated AdminLoginRequest request, // 用于AOP获取IP地址等信息
HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) {
BaseResponse response = new BaseResponse();
try {
Admin loginAdmin = new Admin();
loginAdmin.setUserName(request.getUserName());
loginAdmin.setPassword(request.getPassword());
Admin admin = adminService.login(loginAdmin);
if (admin != null) {
authUtil.setCookieToken(admin.getTokenId(), httpServletResponse);
ResponseUtil.success(response);
} else {
ResponseUtil.error(response);
}
} catch (Exception e) {
logger.error("/user/login error", e);
ResponseUtil.sysError(response);
}
return response;
}
use of com.tony.billing.entity.Admin in project BillingDubbo by TonyJiangWJ.
the class AdminController method register.
@RequestMapping(value = "/user/register/put", method = RequestMethod.POST)
public BaseResponse register(@ModelAttribute("request") @Validated AdminRegisterRequest registerRequest) {
BaseResponse response = new BaseResponse();
try {
Admin admin = new Admin();
admin.setUserName(registerRequest.getUserName());
admin.setPassword(registerRequest.getPassword());
Long flag = 0L;
if ((flag = adminService.register(admin)) > 0) {
ResponseUtil.success(response);
} else {
ResponseUtil.error(response);
if (flag.equals(-2L)) {
response.setMsg("账号已存在");
}
}
} catch (Exception e) {
logger.error("/user/register/put error", e);
ResponseUtil.sysError(response);
}
return response;
}
Aggregations