增加了手机忘记密码接口
This commit is contained in:
parent
2d80c0f6ce
commit
58443f9294
@ -0,0 +1,64 @@
|
||||
package ink.wgink.pojo.vos;
|
||||
|
||||
import ink.wgink.annotation.CheckEmptyAnnotation;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
|
||||
/**
|
||||
* When you feel like quitting. Think about why you started
|
||||
* 当你想要放弃的时候,想想当初你为何开始
|
||||
*
|
||||
* @ClassName: ForgetPasswordVO
|
||||
* @Description: 忘记密码
|
||||
* @Author: WangGeng
|
||||
* @Date: 2019-08-15 18:41
|
||||
* @Version: 1.0
|
||||
**/
|
||||
@ApiModel
|
||||
public class UpdatePhonePasswordVO {
|
||||
|
||||
@ApiModelProperty(name = "phone", value = "手机号")
|
||||
@CheckEmptyAnnotation(name = "手机号")
|
||||
private String phone;
|
||||
@ApiModelProperty(name = "verificationCode", value = "验证码")
|
||||
@CheckEmptyAnnotation(name = "验证码")
|
||||
private String verificationCode;
|
||||
@ApiModelProperty(name = "newPassword", value = "新密码")
|
||||
@CheckEmptyAnnotation(name = "新密码")
|
||||
private String newPassword;
|
||||
|
||||
public String getPhone() {
|
||||
return phone == null ? "" : phone.trim();
|
||||
}
|
||||
|
||||
public void setPhone(String phone) {
|
||||
this.phone = phone;
|
||||
}
|
||||
|
||||
public String getVerificationCode() {
|
||||
return verificationCode == null ? "" : verificationCode.trim();
|
||||
}
|
||||
|
||||
public void setVerificationCode(String verificationCode) {
|
||||
this.verificationCode = verificationCode;
|
||||
}
|
||||
|
||||
public String getNewPassword() {
|
||||
return newPassword == null ? "" : newPassword.trim();
|
||||
}
|
||||
|
||||
public void setNewPassword(String newPassword) {
|
||||
this.newPassword = newPassword;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
final StringBuilder sb = new StringBuilder("{");
|
||||
sb.append("\"verificationCode\":\"")
|
||||
.append(verificationCode).append('\"');
|
||||
sb.append(",\"newPassword\":\"")
|
||||
.append(newPassword).append('\"');
|
||||
sb.append('}');
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
@ -2,13 +2,16 @@ package ink.wgink.service.user.controller.app.api;
|
||||
|
||||
import ink.wgink.annotation.CheckRequestBodyAnnotation;
|
||||
import ink.wgink.common.base.DefaultBaseController;
|
||||
import ink.wgink.exceptions.DependencyException;
|
||||
import ink.wgink.exceptions.ParamsException;
|
||||
import ink.wgink.exceptions.SearchException;
|
||||
import ink.wgink.exceptions.UpdateException;
|
||||
import ink.wgink.interfaces.consts.ISystemConstant;
|
||||
import ink.wgink.interfaces.sms.ISmsBaseService;
|
||||
import ink.wgink.pojo.result.ErrorResult;
|
||||
import ink.wgink.pojo.result.SuccessResult;
|
||||
import ink.wgink.pojo.result.SuccessResultData;
|
||||
import ink.wgink.pojo.vos.UpdatePhonePasswordVO;
|
||||
import ink.wgink.service.user.pojo.dtos.AppUserDTO;
|
||||
import ink.wgink.pojo.vos.UpdatePasswordVO;
|
||||
import ink.wgink.service.user.pojo.vos.UpdateUserVO;
|
||||
@ -40,6 +43,8 @@ public class UserAppController extends DefaultBaseController {
|
||||
|
||||
@Autowired
|
||||
private IUserService userService;
|
||||
@Autowired(required = false)
|
||||
private ISmsBaseService smsBaseService;
|
||||
|
||||
@ApiOperation(value = "修改用户信息", notes = "修改用户信息接口")
|
||||
@ApiImplicitParams({
|
||||
@ -129,6 +134,28 @@ public class UserAppController extends DefaultBaseController {
|
||||
return new SuccessResult();
|
||||
}
|
||||
|
||||
@ApiOperation(value = "忘记手机密码", notes = "忘记手机密码接口")
|
||||
@ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
|
||||
@PutMapping("forget-phone-password")
|
||||
@CheckRequestBodyAnnotation
|
||||
public SuccessResult updatePhonePassword(@RequestBody UpdatePhonePasswordVO updatePhonePasswordVO) throws ParamsException, SearchException, UpdateException, ReflectUtil.ReflectException {
|
||||
if (smsBaseService == null) {
|
||||
throw new DependencyException("短信依赖未引入");
|
||||
}
|
||||
if (updatePhonePasswordVO.getNewPassword().length() < 6) {
|
||||
throw new ParamsException("新密码长度必须大于6位");
|
||||
}
|
||||
String verifyCode = smsBaseService.getVerifyCode(updatePhonePasswordVO.getPhone());
|
||||
if (StringUtils.isBlank(verifyCode)) {
|
||||
throw new ParamsException("验证码为空");
|
||||
}
|
||||
if (!StringUtils.equalsIgnoreCase(verifyCode, updatePhonePasswordVO.getVerificationCode())) {
|
||||
throw new ParamsException("验证码错误");
|
||||
}
|
||||
userService.updatePasswordByUsername(updatePhonePasswordVO.getPhone(), updatePhonePasswordVO.getNewPassword());
|
||||
return new SuccessResult();
|
||||
}
|
||||
|
||||
@ApiOperation(value = "获取APP用户", notes = "获取APP用户接口")
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(name = "token", value = "token", paramType = "header"),
|
||||
|
@ -170,6 +170,14 @@ public interface IUserService extends IUserBaseService, IUserCheckService {
|
||||
*/
|
||||
void updatePasswordByUserId(String userId, UpdatePasswordVO updatePasswordVO, boolean isPasswordMd5);
|
||||
|
||||
/**
|
||||
* 修改密码
|
||||
*
|
||||
* @param username 用户名
|
||||
* @param newPassword 新密码
|
||||
*/
|
||||
void updatePasswordByUsername(String username, String newPassword);
|
||||
|
||||
/**
|
||||
* 更新过期时间
|
||||
*
|
||||
|
@ -258,10 +258,29 @@ public class UserServiceImpl extends DefaultBaseService implements IUserService
|
||||
if (!passwordEncoder.matches(oldPassword, userPO.getUserPassword())) {
|
||||
throw new UpdateException("旧密码错误");
|
||||
}
|
||||
updatePasswordByUserPOAndNewPassword(userPO, newPassword);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updatePasswordByUsername(String username, String newPassword) {
|
||||
UserPO userPO = getPOByUsername(username);
|
||||
if (userPO == null) {
|
||||
throw new SearchException("用户不存在");
|
||||
}
|
||||
updatePasswordByUserPOAndNewPassword(userPO, newPassword);
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改密码
|
||||
*
|
||||
* @param userPO
|
||||
* @param newPassword
|
||||
*/
|
||||
private void updatePasswordByUserPOAndNewPassword(UserPO userPO, String newPassword) {
|
||||
Map<String, Object> params = getHashMap(4);
|
||||
params.put("userPassword", passwordEncoder.encode(newPassword));
|
||||
params.put("gmtPasswordModified", DateUtil.getTime());
|
||||
params.put("userId", userId);
|
||||
params.put("userId", userPO.getUserId());
|
||||
userDao.updatePassword(params);
|
||||
|
||||
// 日志
|
||||
|
Loading…
Reference in New Issue
Block a user