✨ 设置-账户安全模块: 1.换绑邮箱 2.修改密码功能
This commit is contained in:
parent
21c50a5521
commit
ea8164e7e7
@ -81,7 +81,7 @@ public class BaseExceptionHandler {
|
|||||||
}else {
|
}else {
|
||||||
ModelAndView mv = new ModelAndView();
|
ModelAndView mv = new ModelAndView();
|
||||||
FastJsonJsonView view = new FastJsonJsonView();
|
FastJsonJsonView view = new FastJsonJsonView();
|
||||||
Map<String, Object> attributes = new HashMap();
|
Map<String, Object> attributes = new HashMap(2);
|
||||||
if (ex instanceof BaseApiException){
|
if (ex instanceof BaseApiException){
|
||||||
attributes.put("code", "401");
|
attributes.put("code", "401");
|
||||||
attributes.put("message", "用户未登录");
|
attributes.put("message", "用户未登录");
|
||||||
@ -128,7 +128,7 @@ public class BaseExceptionHandler {
|
|||||||
|
|
||||||
private boolean isAjax(HttpServletRequest request) {
|
private boolean isAjax(HttpServletRequest request) {
|
||||||
String requestedWith = request.getHeader("x-requested-with");
|
String requestedWith = request.getHeader("x-requested-with");
|
||||||
if (requestedWith != null && requestedWith.equalsIgnoreCase("XMLHttpRequest")) {
|
if (requestedWith != null && "XMLHttpRequest".equalsIgnoreCase(requestedWith)) {
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
|
@ -9,6 +9,9 @@ import javax.servlet.ServletRequest;
|
|||||||
import javax.servlet.ServletResponse;
|
import javax.servlet.ServletResponse;
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author ronger
|
||||||
|
*/
|
||||||
public class BaseSessionManager extends DefaultWebSessionManager {
|
public class BaseSessionManager extends DefaultWebSessionManager {
|
||||||
private static final String AUTHORIZATION = "Authorization";
|
private static final String AUTHORIZATION = "Authorization";
|
||||||
|
|
||||||
|
@ -1,39 +0,0 @@
|
|||||||
package com.rymcu.vertical.config;
|
|
||||||
|
|
||||||
import org.springframework.context.annotation.Bean;
|
|
||||||
import org.springframework.context.annotation.Configuration;
|
|
||||||
import springfox.documentation.builders.ApiInfoBuilder;
|
|
||||||
import springfox.documentation.builders.PathSelectors;
|
|
||||||
import springfox.documentation.builders.RequestHandlerSelectors;
|
|
||||||
import springfox.documentation.service.ApiInfo;
|
|
||||||
import springfox.documentation.spi.DocumentationType;
|
|
||||||
import springfox.documentation.spring.web.plugins.Docket;
|
|
||||||
import springfox.documentation.swagger2.annotations.EnableSwagger2;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author ronger
|
|
||||||
*/
|
|
||||||
@Configuration
|
|
||||||
@EnableSwagger2
|
|
||||||
public class Swagger2Configuration {
|
|
||||||
|
|
||||||
@Bean
|
|
||||||
public Docket createRestApi() {
|
|
||||||
return new Docket(DocumentationType.SWAGGER_2)
|
|
||||||
.apiInfo(apiInfo())
|
|
||||||
.select()
|
|
||||||
.apis(RequestHandlerSelectors.basePackage("com.rymcu.vertical.web.api"))
|
|
||||||
.paths(PathSelectors.any())
|
|
||||||
.build();
|
|
||||||
}
|
|
||||||
|
|
||||||
private ApiInfo apiInfo() {
|
|
||||||
return new ApiInfoBuilder()
|
|
||||||
.title("Vertical项目接口文档")
|
|
||||||
.description("Vertical项目相关接口的文档")
|
|
||||||
.termsOfServiceUrl("http://www.rymcu.com")
|
|
||||||
.version("1.0")
|
|
||||||
.build();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -5,6 +5,7 @@ import org.apache.shiro.authc.AuthenticationException;
|
|||||||
/**
|
/**
|
||||||
* 验证码错误异常类
|
* 验证码错误异常类
|
||||||
*
|
*
|
||||||
|
* @author ronger
|
||||||
*/
|
*/
|
||||||
public class CaptchaException extends AuthenticationException
|
public class CaptchaException extends AuthenticationException
|
||||||
{
|
{
|
||||||
|
@ -5,6 +5,7 @@ import com.rymcu.vertical.core.result.ResultCode;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 服务(业务)异常如“ 账号或密码错误 ”,该异常只做INFO级别的日志记录 @see WebMvcConfigurer
|
* 服务(业务)异常如“ 账号或密码错误 ”,该异常只做INFO级别的日志记录 @see WebMvcConfigurer
|
||||||
|
* @author ronger
|
||||||
*/
|
*/
|
||||||
public class ServiceException extends Exception {
|
public class ServiceException extends Exception {
|
||||||
private int code;
|
private int code;
|
||||||
|
17
src/main/java/com/rymcu/vertical/dto/ChangeEmailDTO.java
Normal file
17
src/main/java/com/rymcu/vertical/dto/ChangeEmailDTO.java
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
package com.rymcu.vertical.dto;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author ronger
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class ChangeEmailDTO {
|
||||||
|
|
||||||
|
private Integer idUser;
|
||||||
|
|
||||||
|
private String email;
|
||||||
|
|
||||||
|
private String code;
|
||||||
|
|
||||||
|
}
|
15
src/main/java/com/rymcu/vertical/dto/UpdatePasswordDTO.java
Normal file
15
src/main/java/com/rymcu/vertical/dto/UpdatePasswordDTO.java
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
package com.rymcu.vertical.dto;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author ronger
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class UpdatePasswordDTO {
|
||||||
|
|
||||||
|
private Integer idUser;
|
||||||
|
|
||||||
|
private String password;
|
||||||
|
|
||||||
|
}
|
@ -7,6 +7,8 @@ import com.rymcu.vertical.dto.UserInfoDTO;
|
|||||||
import com.rymcu.vertical.entity.User;
|
import com.rymcu.vertical.entity.User;
|
||||||
import org.apache.ibatis.annotations.Param;
|
import org.apache.ibatis.annotations.Param;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author ronger
|
* @author ronger
|
||||||
*/
|
*/
|
||||||
@ -120,4 +122,20 @@ public interface UserMapper extends Mapper<User> {
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
Integer updateLastLoginTime(@Param("idUser") Integer idUser);
|
Integer updateLastLoginTime(@Param("idUser") Integer idUser);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更换邮箱
|
||||||
|
* @param idUser
|
||||||
|
* @param email
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
Integer updateEmail(@Param("idUser") Integer idUser, @Param("email") String email);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新密码
|
||||||
|
* @param idUser
|
||||||
|
* @param password
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
Integer updatePasswordById(@Param("idUser") Integer idUser, @Param("password") String password);
|
||||||
}
|
}
|
@ -1,9 +1,7 @@
|
|||||||
package com.rymcu.vertical.service;
|
package com.rymcu.vertical.service;
|
||||||
|
|
||||||
import com.rymcu.vertical.core.service.Service;
|
import com.rymcu.vertical.core.service.Service;
|
||||||
import com.rymcu.vertical.dto.Author;
|
import com.rymcu.vertical.dto.*;
|
||||||
import com.rymcu.vertical.dto.UserDTO;
|
|
||||||
import com.rymcu.vertical.dto.UserInfoDTO;
|
|
||||||
import com.rymcu.vertical.entity.User;
|
import com.rymcu.vertical.entity.User;
|
||||||
import com.rymcu.vertical.entity.UserExtend;
|
import com.rymcu.vertical.entity.UserExtend;
|
||||||
import org.apache.ibatis.exceptions.TooManyResultsException;
|
import org.apache.ibatis.exceptions.TooManyResultsException;
|
||||||
@ -123,4 +121,18 @@ public interface UserService extends Service<User> {
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
UserExtend selectUserExtendByNickname(String nickname);
|
UserExtend selectUserExtendByNickname(String nickname);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更换邮箱
|
||||||
|
* @param changeEmailDTO
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
Map updateEmail(ChangeEmailDTO changeEmailDTO);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新密码
|
||||||
|
* @param updatePasswordDTO
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
Map updatePassword(UpdatePasswordDTO updatePasswordDTO);
|
||||||
}
|
}
|
||||||
|
@ -2,10 +2,7 @@ package com.rymcu.vertical.service.impl;
|
|||||||
|
|
||||||
import com.rymcu.vertical.core.service.AbstractService;
|
import com.rymcu.vertical.core.service.AbstractService;
|
||||||
import com.rymcu.vertical.core.service.redis.RedisService;
|
import com.rymcu.vertical.core.service.redis.RedisService;
|
||||||
import com.rymcu.vertical.dto.Author;
|
import com.rymcu.vertical.dto.*;
|
||||||
import com.rymcu.vertical.dto.TokenUser;
|
|
||||||
import com.rymcu.vertical.dto.UserDTO;
|
|
||||||
import com.rymcu.vertical.dto.UserInfoDTO;
|
|
||||||
import com.rymcu.vertical.entity.Role;
|
import com.rymcu.vertical.entity.Role;
|
||||||
import com.rymcu.vertical.entity.User;
|
import com.rymcu.vertical.entity.User;
|
||||||
import com.rymcu.vertical.entity.UserExtend;
|
import com.rymcu.vertical.entity.UserExtend;
|
||||||
@ -47,7 +44,8 @@ public class UserServiceImpl extends AbstractService<User> implements UserServic
|
|||||||
@Resource
|
@Resource
|
||||||
private UserExtendMapper userExtendMapper;
|
private UserExtendMapper userExtendMapper;
|
||||||
|
|
||||||
private final static String avatarSvgType = "1";
|
private final static String AVATAR_SVG_TYPE = "1";
|
||||||
|
private final static String DEFAULT_AVATAR = "https://static.rymcu.com/article/1578475481946.png";
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public User findByAccount(String account) throws TooManyResultsException{
|
public User findByAccount(String account) throws TooManyResultsException{
|
||||||
@ -59,22 +57,23 @@ public class UserServiceImpl extends AbstractService<User> implements UserServic
|
|||||||
public Map register(String email, String password, String code) {
|
public Map register(String email, String password, String code) {
|
||||||
Map map = new HashMap(2);
|
Map map = new HashMap(2);
|
||||||
map.put("message","验证码无效!");
|
map.put("message","验证码无效!");
|
||||||
String vcode = redisService.get(email);
|
String vCode = redisService.get(email);
|
||||||
if(StringUtils.isNotBlank(vcode)){
|
if(StringUtils.isNotBlank(vCode)){
|
||||||
if(vcode.equals(code)){
|
if(vCode.equals(code)){
|
||||||
User user = userMapper.findByAccount(email);
|
User user = userMapper.findByAccount(email);
|
||||||
if(user != null){
|
if(user != null){
|
||||||
map.put("message","该邮箱已被注册!");
|
map.put("message","该邮箱已被注册!");
|
||||||
} else {
|
} else {
|
||||||
user = new User();
|
user = new User();
|
||||||
user.setAccount(email);
|
|
||||||
String nickname = email.split("@")[0];
|
String nickname = email.split("@")[0];
|
||||||
nickname = checkNickname(nickname);
|
nickname = checkNickname(nickname);
|
||||||
user.setNickname(nickname);
|
user.setNickname(nickname);
|
||||||
|
user.setAccount(nickname);
|
||||||
user.setEmail(email);
|
user.setEmail(email);
|
||||||
user.setPassword(Utils.entryptPassword(password));
|
user.setPassword(Utils.entryptPassword(password));
|
||||||
user.setCreatedTime(new Date());
|
user.setCreatedTime(new Date());
|
||||||
user.setUpdatedTime(user.getCreatedTime());
|
user.setUpdatedTime(user.getCreatedTime());
|
||||||
|
user.setAvatarUrl(DEFAULT_AVATAR);
|
||||||
userMapper.insertSelective(user);
|
userMapper.insertSelective(user);
|
||||||
user = userMapper.findByAccount(email);
|
user = userMapper.findByAccount(email);
|
||||||
Role role = roleMapper.selectRoleByInputCode("user");
|
Role role = roleMapper.selectRoleByInputCode("user");
|
||||||
@ -100,9 +99,7 @@ public class UserServiceImpl extends AbstractService<User> implements UserServic
|
|||||||
@Override
|
@Override
|
||||||
public Map login(String account, String password) {
|
public Map login(String account, String password) {
|
||||||
Map map = new HashMap(1);
|
Map map = new HashMap(1);
|
||||||
User user = new User();
|
User user = userMapper.findByAccount(account);
|
||||||
user.setAccount(account);
|
|
||||||
user = userMapper.selectOne(user);
|
|
||||||
if(user != null){
|
if(user != null){
|
||||||
if(Utils.comparePwd(password, user.getPassword())){
|
if(Utils.comparePwd(password, user.getPassword())){
|
||||||
userMapper.updateLastLoginTime(user.getIdUser());
|
userMapper.updateLastLoginTime(user.getIdUser());
|
||||||
@ -191,7 +188,7 @@ public class UserServiceImpl extends AbstractService<User> implements UserServic
|
|||||||
map.put("message", "该昵称已使用!");
|
map.put("message", "该昵称已使用!");
|
||||||
return map;
|
return map;
|
||||||
}
|
}
|
||||||
if (StringUtils.isNotBlank(user.getAvatarType()) && avatarSvgType.equals(user.getAvatarType())) {
|
if (StringUtils.isNotBlank(user.getAvatarType()) && AVATAR_SVG_TYPE.equals(user.getAvatarType())) {
|
||||||
String avatarUrl = UploadController.uploadBase64File(user.getAvatarUrl(), 0);
|
String avatarUrl = UploadController.uploadBase64File(user.getAvatarUrl(), 0);
|
||||||
user.setAvatarUrl(avatarUrl);
|
user.setAvatarUrl(avatarUrl);
|
||||||
user.setAvatarType("0");
|
user.setAvatarType("0");
|
||||||
@ -242,4 +239,31 @@ public class UserServiceImpl extends AbstractService<User> implements UserServic
|
|||||||
public UserExtend selectUserExtendByNickname(String nickname) {
|
public UserExtend selectUserExtendByNickname(String nickname) {
|
||||||
return userExtendMapper.selectUserExtendByNickname(nickname);
|
return userExtendMapper.selectUserExtendByNickname(nickname);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Map updateEmail(ChangeEmailDTO changeEmailDTO) {
|
||||||
|
Map map = new HashMap(2);
|
||||||
|
map.put("message","验证码无效!");
|
||||||
|
Integer idUser = changeEmailDTO.getIdUser();
|
||||||
|
String email = changeEmailDTO.getEmail();
|
||||||
|
String code = changeEmailDTO.getCode();
|
||||||
|
String vCode = redisService.get(email);
|
||||||
|
if(StringUtils.isNotBlank(vCode)){
|
||||||
|
if(vCode.equals(code)){
|
||||||
|
userMapper.updateEmail(idUser, email);
|
||||||
|
map.put("message","更新成功!");
|
||||||
|
map.put("email", email);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return map;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Map updatePassword(UpdatePasswordDTO updatePasswordDTO) {
|
||||||
|
Map map = new HashMap(1);
|
||||||
|
String password = Utils.entryptPassword(updatePasswordDTO.getPassword());
|
||||||
|
userMapper.updatePasswordById(updatePasswordDTO.getIdUser(), password);
|
||||||
|
map.put("message", "更新成功!");
|
||||||
|
return map;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -14,7 +14,6 @@ import com.rymcu.vertical.service.PortfolioService;
|
|||||||
import com.rymcu.vertical.service.UserService;
|
import com.rymcu.vertical.service.UserService;
|
||||||
import com.rymcu.vertical.util.UserUtils;
|
import com.rymcu.vertical.util.UserUtils;
|
||||||
import com.rymcu.vertical.util.Utils;
|
import com.rymcu.vertical.util.Utils;
|
||||||
import io.swagger.annotations.ApiOperation;
|
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
@ -39,7 +38,6 @@ public class CommonApiController {
|
|||||||
@Resource
|
@Resource
|
||||||
private PortfolioService portfolioService;
|
private PortfolioService portfolioService;
|
||||||
|
|
||||||
@ApiOperation(value = "获取邮件验证码")
|
|
||||||
@GetMapping("/get-email-code")
|
@GetMapping("/get-email-code")
|
||||||
public GlobalResult<Map<String, String>> getEmailCode(@RequestParam("email") String email) throws MessagingException {
|
public GlobalResult<Map<String, String>> getEmailCode(@RequestParam("email") String email) throws MessagingException {
|
||||||
Map<String, String> map = new HashMap<>(1);
|
Map<String, String> map = new HashMap<>(1);
|
||||||
@ -56,7 +54,6 @@ public class CommonApiController {
|
|||||||
return GlobalResultGenerator.genSuccessResult(map);
|
return GlobalResultGenerator.genSuccessResult(map);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ApiOperation(value = "获取找回密码邮件")
|
|
||||||
@GetMapping("/get-forget-password-email")
|
@GetMapping("/get-forget-password-email")
|
||||||
public GlobalResult<Map<Object, Object>> getForgetPasswordEmail(@RequestParam("email") String email) throws MessagingException {
|
public GlobalResult<Map<Object, Object>> getForgetPasswordEmail(@RequestParam("email") String email) throws MessagingException {
|
||||||
Map<Object, Object> map = new HashMap<>(1);
|
Map<Object, Object> map = new HashMap<>(1);
|
||||||
|
@ -2,7 +2,8 @@ package com.rymcu.vertical.web.api.user;
|
|||||||
|
|
||||||
import com.rymcu.vertical.core.result.GlobalResult;
|
import com.rymcu.vertical.core.result.GlobalResult;
|
||||||
import com.rymcu.vertical.core.result.GlobalResultGenerator;
|
import com.rymcu.vertical.core.result.GlobalResultGenerator;
|
||||||
import com.rymcu.vertical.dto.UserInfoDTO;
|
import com.rymcu.vertical.dto.*;
|
||||||
|
import com.rymcu.vertical.entity.User;
|
||||||
import com.rymcu.vertical.entity.UserExtend;
|
import com.rymcu.vertical.entity.UserExtend;
|
||||||
import com.rymcu.vertical.service.UserService;
|
import com.rymcu.vertical.service.UserService;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
@ -44,4 +45,16 @@ public class UserInfoController {
|
|||||||
return GlobalResultGenerator.genSuccessResult(map);
|
return GlobalResultGenerator.genSuccessResult(map);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@PatchMapping("/update-email")
|
||||||
|
public GlobalResult updateEmail(@RequestBody ChangeEmailDTO changeEmailDTO) {
|
||||||
|
Map map = userService.updateEmail(changeEmailDTO);
|
||||||
|
return GlobalResultGenerator.genSuccessResult(map);
|
||||||
|
}
|
||||||
|
|
||||||
|
@PatchMapping("/update-password")
|
||||||
|
public GlobalResult updatePassword(@RequestBody UpdatePasswordDTO updatePasswordDTO) {
|
||||||
|
Map map = userService.updatePassword(updatePasswordDTO);
|
||||||
|
return GlobalResultGenerator.genSuccessResult(map);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -68,9 +68,15 @@
|
|||||||
<update id="updateLastLoginTime">
|
<update id="updateLastLoginTime">
|
||||||
update vertical_user set last_login_time = sysdate() where id = #{idUser}
|
update vertical_user set last_login_time = sysdate() where id = #{idUser}
|
||||||
</update>
|
</update>
|
||||||
|
<update id="updateEmail">
|
||||||
|
update vertical_user set email = #{email} where id = #{idUser}
|
||||||
|
</update>
|
||||||
|
<update id="updatePasswordById">
|
||||||
|
update vertical_user set password = #{password} where id = #{idUser}
|
||||||
|
</update>
|
||||||
|
|
||||||
<select id="findByAccount" resultMap="BaseResultMap">
|
<select id="findByAccount" resultMap="BaseResultMap">
|
||||||
select id, nickname, account, password, status from vertical_user where account = #{account} and status = 0
|
select id, nickname, account, password, status, avatar_type, avatar_url from vertical_user where (account = #{account} or email = #{account} ) and status = 0
|
||||||
</select>
|
</select>
|
||||||
<select id="findUserInfoByAccount" resultMap="UserInfoResultMapper">
|
<select id="findUserInfoByAccount" resultMap="UserInfoResultMapper">
|
||||||
select id, nickname, sex, avatar_type, avatar_url, email, phone, account, status, signature, last_login_time from vertical_user where account = #{account}
|
select id, nickname, sex, avatar_type, avatar_url, email, phone, account, status, signature, last_login_time from vertical_user where account = #{account}
|
||||||
|
Loading…
Reference in New Issue
Block a user