添加密码修改的api
This commit is contained in:
@@ -93,6 +93,14 @@ public class UserController {
|
||||
return ResponseUtil.success(userService.reSetPwd(verifyId, email, pwd));
|
||||
}
|
||||
|
||||
@PostMapping("/user/setPwd")
|
||||
public Response setPwd(@RequestParam("pwd") String pwd,
|
||||
@RequestParam("newPwd") String newPwd,
|
||||
@RequestParam("confirmPwd") String confirmPwd) {
|
||||
return ResponseUtil.success(userService.setPwd(pwd,newPwd,confirmPwd));
|
||||
}
|
||||
|
||||
|
||||
@DeleteMapping("/admin/user/delete")
|
||||
public Response multipleDelete(@RequestBody Integer[] ids) {
|
||||
return ResponseUtil.success(userService.deleteUser(ids));
|
||||
|
||||
@@ -28,8 +28,10 @@ public enum ResponseEnum {
|
||||
USEREMAIL_NULL(3310, "未设置邮箱"),
|
||||
USEREMAIL_NOT_VERIFY(3320, "邮箱未验证"),
|
||||
LOGIN_LATER(3500, "错误次数已达5次,请稍后再试"),
|
||||
PWD_SAME(3600, "新密码与原密码相同"),
|
||||
PWD_SAME(3601, "新密码与原密码相同"),
|
||||
PWD_NOT_SAME(3602, "新密码与原密码不相同"),
|
||||
LOGIN_EXPIRED(3700, "登陆过期"),
|
||||
PWD_WRONG(3800, "密码不正确"),
|
||||
|
||||
JWT_EXPIRED(3810, "Token过期"),
|
||||
JWT_MALFORMED(3820, "Token格式不对"),
|
||||
|
||||
@@ -174,4 +174,13 @@ public interface UserService {
|
||||
* @return true:存在 false:不存在
|
||||
*/
|
||||
boolean getStatusOfEmail(String email);
|
||||
|
||||
/**
|
||||
* 设置密码
|
||||
* @param pwd
|
||||
* @param newPwd
|
||||
* @param confirmPwd
|
||||
* @return
|
||||
*/
|
||||
UserModel setPwd(String pwd, String newPwd, String confirmPwd);
|
||||
}
|
||||
|
||||
@@ -433,6 +433,20 @@ public class UserServiceImpl implements UserService {
|
||||
return userMapper.existsByEmail(email);
|
||||
}
|
||||
|
||||
@Override
|
||||
public UserModel setPwd(String pwd, String newPwd, String confirmPwd) {
|
||||
User user = redisUserUtil.get();
|
||||
String pwd1 = userMapper.getPwd(user.getEmail());
|
||||
if (!MD5Util.getMD5(pwd).equals(pwd1)) {
|
||||
throw new MyException(ResponseEnum.PWD_WRONG);
|
||||
}
|
||||
if (!newPwd.equals(confirmPwd)) {
|
||||
throw new MyException(ResponseEnum.PWD_NOT_SAME);
|
||||
}
|
||||
userMapper.updatePwd(user.getEmail(), MD5Util.getMD5(newPwd));
|
||||
return trans(userMapper.findByEmail(user.getEmail()));
|
||||
}
|
||||
|
||||
private UserModel trans(User u) {
|
||||
UserModel user = new UserModel();
|
||||
user.setId(u.getId());
|
||||
|
||||
@@ -14,6 +14,9 @@ import org.junit.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.mock.web.MockMultipartFile;
|
||||
import org.springframework.util.LinkedMultiValueMap;
|
||||
import org.springframework.util.MultiValueMap;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
@@ -247,4 +250,28 @@ public class UserControllerTest extends BaseTest {
|
||||
assertTrue(JSONObject.fromObject(content).getBoolean(Result));
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setPwd() throws Exception {
|
||||
String email = UUID.randomUUID().toString().substring(0, 4) + "@celess.cn";
|
||||
assertEquals(1, userMapper.addUser(email, MD5Util.getMD5("1234567890")));
|
||||
LoginReq req = new LoginReq();
|
||||
req.setEmail(email);
|
||||
req.setPassword("1234567890");
|
||||
req.setIsRememberMe(false);
|
||||
JSONObject loginReq = JSONObject.fromObject(req);
|
||||
String contentAsString = mockMvc.perform(post("/login").content(loginReq.toString()).contentType("application/json")).andReturn().getResponse().getContentAsString();
|
||||
assertNotNull(contentAsString);
|
||||
String token = JSONObject.fromObject(contentAsString).getJSONObject(Result).getString("token");
|
||||
assertNotNull(token);
|
||||
MultiValueMap<String, String> param = new LinkedMultiValueMap<String, String>();
|
||||
param.add("pwd", "1234567890");
|
||||
param.add("newPwd", "aaabbbccc");
|
||||
param.add("confirmPwd", "aaabbbccc");
|
||||
mockMvc.perform(post("/user/setPwd").header("Authorization", token).params(param)).andDo(result -> {
|
||||
String content = result.getResponse().getContentAsString();
|
||||
assertEquals(SUCCESS.getCode(), JSONObject.fromObject(content).getInt(Code));
|
||||
assertEquals(MD5Util.getMD5("aaabbbccc"), userMapper.getPwd(email));
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user