增加修改密码接口

master
panqihua 5 years ago
parent 5c942d230c
commit aaeabdad4a
  1. 47
      src/main/java/com/community/pocket/api/android/ForumController.java
  2. 19
      src/main/java/com/community/pocket/api/android/UserController.java
  3. 2
      src/main/java/com/community/pocket/entity/po/android/MyInfo.java
  4. 32
      src/main/java/com/community/pocket/entity/vo/android/InfoResponse.java
  5. 29
      src/main/java/com/community/pocket/entity/vo/android/ModifyPwdForm.java
  6. 32
      src/main/java/com/community/pocket/repository/android/UserDao.java
  7. 14
      src/main/resources/application.yaml
  8. 13
      src/test/java/com/community/pocket/DemoApplicationTests.java

@ -5,6 +5,7 @@ import com.community.pocket.entity.po.ForumContent;
import com.community.pocket.entity.po.Notice;
import com.community.pocket.entity.po.android.Active;
import com.community.pocket.entity.po.android.Complain;
import com.community.pocket.entity.po.android.MyInfo;
import com.community.pocket.entity.po.android.Token;
import com.community.pocket.entity.vo.android.ActiveForm;
import com.community.pocket.entity.vo.Result;
@ -109,15 +110,15 @@ public class ForumController {
@PostMapping("/forum/sendTopic")
public ForumPostResponse sendTopic(ForumForm forumForm) {
if (tokenDao.checkToken(forumForm)) {
Forum forum=forumDao.save(forumForm);
if(forum!=null){
ForumContent forumContent=forumContentDao.save(forumForm,forum);
if(forumContent!=null){
Forum forum = forumDao.save(forumForm);
if (forum != null) {
ForumContent forumContent = forumContentDao.save(forumForm, forum);
if (forumContent != null) {
return new ForumPostResponse(Result.OK, ForumPostResponse.Msg.ok);
}
}
return new ForumPostResponse(Result.FAIL, ForumPostResponse.Msg.fail);
}else{
} else {
return new ForumPostResponse(Result.FAIL, ForumPostResponse.Msg.token);
}
}
@ -126,16 +127,16 @@ public class ForumController {
@PostMapping("/forum/sendComplain")
public ForumPostResponse sendComplain(ComplainForm complainForm) {
if (tokenDao.checkToken(complainForm)) {
Forum forum=forumDao.save(complainForm);
if(forum!=null){
ForumContent forumContent=forumContentDao.save(complainForm,forum);
Complain complain=complainDao.save(complainForm,forum);
if(forumContent!=null&&complain!=null){
Forum forum = forumDao.save(complainForm);
if (forum != null) {
ForumContent forumContent = forumContentDao.save(complainForm, forum);
Complain complain = complainDao.save(complainForm, forum);
if (forumContent != null && complain != null) {
return new ForumPostResponse(Result.OK, ForumPostResponse.Msg.ok);
}
}
return new ForumPostResponse(Result.FAIL, ForumPostResponse.Msg.fail);
}else{
} else {
return new ForumPostResponse(Result.FAIL, ForumPostResponse.Msg.token);
}
}
@ -145,14 +146,30 @@ public class ForumController {
*/
@GetMapping("/forum/my")
public ForumMyResponse loadForumMy(Token token) {
if(tokenDao.checkToken(token)){
List<Forum> forumList=forumDao.loadMyForum(token.getUsername());
ForumMyResponse response=new ForumMyResponse(Result.OK, ForumMyResponse.Msg.ok);
if (tokenDao.checkToken(token)) {
List<Forum> forumList = forumDao.loadMyForum(token.getUsername());
ForumMyResponse response = new ForumMyResponse(Result.OK, ForumMyResponse.Msg.ok);
response.setForumList(forumList);
return response;
}else {
} else {
return new ForumMyResponse(Result.FAIL, ForumMyResponse.Msg.token);
}
}
//获取个人信息
@GetMapping("/my/info")
public InfoResponse loadInfo(Token token) {
if (tokenDao.checkToken(token)) {
MyInfo myInfo = userDao.queryUser(token.getUsername());
if (myInfo != null) {
InfoResponse response = new InfoResponse(Result.OK, InfoResponse.Msg.ok);
response.setMyInfo(myInfo);
return response;
} else {
return new InfoResponse(Result.FAIL, InfoResponse.Msg.fail);
}
} else {
return new InfoResponse(Result.FAIL, InfoResponse.Msg.token);
}
}
}

@ -138,4 +138,23 @@ public class UserController {
queryUserResponse.setPeopleList(userDao.queryUser(userForm));
return queryUserResponse;
}
//修改密码
@PostMapping("/my/info/modifyPwd")
public InfoResponse modifyPwd(ModifyPwdForm modifyPwdForm) {
if(tokenDao.checkToken(modifyPwdForm.getToken())){
if(userDao.login(modifyPwdForm.getUsername(),modifyPwdForm.getOldPassword())){
if(userDao.modifyPwd(modifyPwdForm)){
return new InfoResponse(Result.OK,InfoResponse.Msg.modify_pwd_ok);
}else{
return new InfoResponse(Result.FAIL,InfoResponse.Msg.modify_pwd_fail);
}
}else{
return new InfoResponse(Result.FAIL,InfoResponse.Msg.modify_oldpwd_fail);
}
}else {
return new InfoResponse(Result.FAIL,InfoResponse.Msg.token);
}
}
}

@ -1,6 +1,7 @@
package com.community.pocket.entity.po.android;
import com.community.pocket.util.TableName;
import com.fasterxml.jackson.annotation.JsonIgnore;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.Document;
@ -13,6 +14,7 @@ public class MyInfo {
@Id
private String username;
//密码
@JsonIgnore
private String password;
//信用分
private Integer creditScore;

@ -0,0 +1,32 @@
package com.community.pocket.entity.vo.android;
import com.community.pocket.entity.po.android.MyInfo;
import com.community.pocket.entity.vo.Result;
/**
* 个人信息响应
*/
public class InfoResponse extends AndroidResponse<InfoResponse.Msg>{
private MyInfo myInfo;
public InfoResponse(Result result, Msg message, Object... args) {
super(result, message, args);
}
public MyInfo getMyInfo() {
return myInfo;
}
public void setMyInfo(MyInfo myInfo) {
this.myInfo = myInfo;
}
public enum Msg implements CustomMessage{
ok,
fail,
modify_pwd_ok,
modify_pwd_fail,
modify_oldpwd_fail,
token
}
}

@ -0,0 +1,29 @@
package com.community.pocket.entity.vo.android;
import com.community.pocket.entity.po.android.Token;
/**
* 修改密码表单
*/
public class ModifyPwdForm extends Token {
//原密码
private String oldPassword;
//新密码
private String newPassword;
public String getOldPassword() {
return oldPassword;
}
public void setOldPassword(String oldPassword) {
this.oldPassword = oldPassword;
}
public String getNewPassword() {
return newPassword;
}
public void setNewPassword(String newPassword) {
this.newPassword = newPassword;
}
}

@ -1,13 +1,12 @@
package com.community.pocket.repository.android;
import com.community.pocket.entity.po.android.MyInfo;
import com.community.pocket.entity.vo.android.QueryUserForm;
import com.community.pocket.entity.vo.android.UserHot;
import com.community.pocket.entity.vo.android.UserRegister;
import com.community.pocket.entity.vo.android.*;
import com.community.pocket.repository.BaseDao;
import com.mongodb.client.result.UpdateResult;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.domain.Sort;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
@ -26,6 +25,9 @@ public class UserDao extends BaseDao<MyInfo> {
private static final Logger LOG = LoggerFactory.getLogger(UserDao.class);
@Value("${register.credit-score}")
private int creditScore;
//检查用户名是否已注册
public boolean hasUser(String username){
if(!StringUtils.isEmpty(username)){
@ -92,7 +94,10 @@ public class UserDao extends BaseDao<MyInfo> {
myInfo.setPassword(DigestUtils.md5DigestAsHex(userRegister.getPassword().getBytes()));
myInfo.setMobie(userRegister.getMobie());
myInfo.setEmail(userRegister.getEmail());
myInfo.setCreditScore(0);
myInfo.setCreditScore(creditScore);
myInfo.setRecentPosts(0);
myInfo.setRecentVisitors(0);
myInfo.setScoreHistory(new ArrayList<>());
save(myInfo);
}
@ -109,16 +114,31 @@ public class UserDao extends BaseDao<MyInfo> {
return userHots;
}
//获取用户
//根据关键字匹配用户
public List<String> queryUser(QueryUserForm userForm){
List<String> userNames=new ArrayList<>();
List<MyInfo> myInfos=mongoTemplate.find(new Query(Criteria.where("username").ne(userForm.getUsername()).and("username").regex(Pattern.compile(".*"+userForm.getName()+".*"))),entityClass());
List<MyInfo> myInfos=mongoTemplate.find(new Query(new Criteria().andOperator(
Criteria.where("username").regex(Pattern.compile(".*"+userForm.getName()+".*")),
Criteria.where("username").ne(userForm.getUsername())))
,entityClass());
for(MyInfo info:myInfos){
userNames.add(info.getUsername());
}
return userNames;
}
//获取个人信息
public MyInfo queryUser(String username){
return mongoTemplate.findOne(new Query(Criteria.where("username").is(username)),entityClass());
}
//修改密码
public boolean modifyPwd(ModifyPwdForm modifyPwdForm) {
String md5Password= DigestUtils.md5DigestAsHex(modifyPwdForm.getOldPassword().getBytes());
String newMd5password=DigestUtils.md5DigestAsHex(modifyPwdForm.getNewPassword().getBytes());
return mongoTemplate.updateFirst(new Query(Criteria.where("username").is(modifyPwdForm.getUsername()).and("password").is(md5Password)),Update.update("password",newMd5password),entityClass()).wasAcknowledged();
}
@Override
public MyInfo save(MyInfo myInfo) {
try {

@ -15,14 +15,21 @@ spring:
#邮箱配置
email:
#支持的邮箱类型
support-type:
- name: 网易
suffix: '@163.com'
#邮件标题
subject: 口袋社区
#发送邮箱
from: 15920722180@163.com
#验证码
code:
#长度
length: 6
#管理员激活邮件模版
manager: 欢迎注册口袋社区后台服务,您获取到的验证码是:%s
#用户重置密码邮件模版
user: 重置密码,您获取到的验证码是:%s
#令牌配置
@ -32,4 +39,9 @@ token:
#论坛配置
forum:
#帖子正文缩略长度
content-length: 10
content-length: 10
#注册配置
register:
#默认信用分
credit-score: 0

@ -1,13 +1,26 @@
package com.community.pocket;
import com.community.pocket.entity.vo.android.QueryUserForm;
import com.community.pocket.repository.android.UserDao;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
@SpringBootTest
class DemoApplicationTests {
@Autowired
private UserDao userDao;
@Test
void contextLoads() {
}
@Test
void queryUser(){
QueryUserForm queryUserForm=new QueryUserForm();
queryUserForm.setName("p");
userDao.queryUser(queryUserForm);
}
}

Loading…
Cancel
Save