完善管理员登录、注册、重置密码接口

master
panqihua 5 years ago
parent 4b38bb063f
commit 5514f029e8
  1. 157
      src/main/java/com/community/pocket/api/web/ManagerController.java
  2. 3
      src/main/java/com/community/pocket/entity/po/EmailCode.java
  3. 14
      src/main/java/com/community/pocket/entity/po/Manager.java
  4. 7
      src/main/java/com/community/pocket/entity/po/ManagerToken.java
  5. 52
      src/main/java/com/community/pocket/entity/vo/JSONResponse.java
  6. 13
      src/main/java/com/community/pocket/entity/vo/Response.java
  7. 3
      src/main/java/com/community/pocket/entity/vo/android/ForumDataResponse.java
  8. 5
      src/main/java/com/community/pocket/entity/vo/android/ForumHotResponse.java
  9. 3
      src/main/java/com/community/pocket/entity/vo/android/ForumMyResponse.java
  10. 3
      src/main/java/com/community/pocket/entity/vo/android/ForumNewResponse.java
  11. 3
      src/main/java/com/community/pocket/entity/vo/android/ForumNoticeResponse.java
  12. 7
      src/main/java/com/community/pocket/entity/vo/android/ForumPostResponse.java
  13. 36
      src/main/java/com/community/pocket/entity/vo/android/GarbageCateGory.java
  14. 3
      src/main/java/com/community/pocket/entity/vo/android/GarbageSortingResponse.java
  15. 3
      src/main/java/com/community/pocket/entity/vo/android/GarbageWasteResponse.java
  16. 3
      src/main/java/com/community/pocket/entity/vo/android/InfoResponse.java
  17. 3
      src/main/java/com/community/pocket/entity/vo/android/LoginResponse.java
  18. 3
      src/main/java/com/community/pocket/entity/vo/android/QueryUserResponse.java
  19. 3
      src/main/java/com/community/pocket/entity/vo/android/RegisterResponse.java
  20. 3
      src/main/java/com/community/pocket/entity/vo/android/ResetPwdResponse.java
  21. 3
      src/main/java/com/community/pocket/entity/vo/android/VisitorMyResponse.java
  22. 3
      src/main/java/com/community/pocket/entity/vo/android/VisitorPeopleResponse.java
  23. 3
      src/main/java/com/community/pocket/entity/vo/android/VisitorReservationResponse.java
  24. 3
      src/main/java/com/community/pocket/entity/vo/android/VisitorResponse.java
  25. 32
      src/main/java/com/community/pocket/entity/vo/web/EmailTypeResponse.java
  26. 37
      src/main/java/com/community/pocket/entity/vo/web/LoginResponse.java
  27. 22
      src/main/java/com/community/pocket/entity/vo/web/LogoutResponse.java
  28. 5
      src/main/java/com/community/pocket/entity/vo/web/ManagerLogin.java
  29. 14
      src/main/java/com/community/pocket/entity/vo/web/ManagerLogout.java
  30. 2
      src/main/java/com/community/pocket/entity/vo/web/ManagerRegister.java
  31. 57
      src/main/java/com/community/pocket/entity/vo/web/ManagerResetPwd.java
  32. 30
      src/main/java/com/community/pocket/entity/vo/web/RegisterResponse.java
  33. 34
      src/main/java/com/community/pocket/entity/vo/web/ResetpwdResponse.java
  34. 10
      src/main/java/com/community/pocket/repository/ForumRepo.java
  35. 19
      src/main/java/com/community/pocket/repository/ManagerDao.java
  36. 11
      src/main/java/com/community/pocket/repository/ManagerRepo.java
  37. 39
      src/main/java/com/community/pocket/repository/ManagerTokenDao.java
  38. 15
      src/main/java/com/community/pocket/repository/android/GarbageDao.java
  39. 38
      src/main/java/com/community/pocket/util/EmailService.java
  40. 43
      src/main/java/com/community/pocket/util/LocaleConfig.java
  41. 21
      src/main/java/com/community/pocket/util/MessageService.java
  42. 5
      src/main/java/com/community/pocket/util/TableName.java
  43. 9
      src/main/resources/application.yaml
  44. 5
      src/main/resources/static/i18n/messages.properties
  45. 5
      src/main/resources/static/i18n/messages_en_US.properties
  46. 5
      src/main/resources/static/i18n/messages_zh_CN.properties
  47. 10
      src/test/java/com/community/pocket/DemoApplicationTests.java

@ -1,9 +1,13 @@
package com.community.pocket.api.web;
import com.community.pocket.entity.po.Manager;
import com.community.pocket.entity.po.Token;
import com.community.pocket.entity.vo.*;
import com.community.pocket.entity.po.ManagerToken;
import com.community.pocket.entity.vo.EmailTypeConfig;
import com.community.pocket.entity.vo.Result;
import com.community.pocket.entity.vo.web.*;
import com.community.pocket.repository.EmailDao;
import com.community.pocket.repository.ManagerDao;
import com.community.pocket.repository.ManagerTokenDao;
import com.community.pocket.util.EmailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.DigestUtils;
@ -12,7 +16,6 @@ import org.springframework.web.bind.annotation.*;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
@RestController
@RequestMapping("/api/manager")
@ -32,30 +35,38 @@ public class ManagerController {
@Autowired
private EmailService emailService;
// 登陆
@Autowired
private ManagerTokenDao managerTokenDao;
@Autowired
private EmailDao emailDao;
// 登陆
@PostMapping("login")
public JSONResponse<Token> login(@RequestBody ManagerLogin managerLogin){
if(StringUtils.isEmpty(managerLogin.getManagerName())){
return new JSONResponse<>(Result.FAIL,"管理员不能为空!",null);
}else if(StringUtils.isEmpty(managerLogin.getPassword())){
return new JSONResponse<>(Result.FAIL,"密码不能为空!",null);
public LoginResponse login(@RequestBody ManagerLogin managerLogin) {
if (StringUtils.isEmpty(managerLogin.getManagerName())) {
return new LoginResponse(Result.FAIL, LoginResponse.Msg.manager);
} else if (StringUtils.isEmpty(managerLogin.getPassword())) {
return new LoginResponse(Result.FAIL, LoginResponse.Msg.password);
//校验账号密码
}else if(!managerDao.login(managerLogin)){
return new JSONResponse<>(Result.FAIL,"账号或密码错误!",null);
}
else{
} else if (!managerDao.login(managerLogin)) {
return new LoginResponse(Result.FAIL, LoginResponse.Msg.fail);
} else {
// 验证通过生成令牌响应给服务端
Token token=new Token();
Calendar c=Calendar.getInstance();
ManagerToken managerToken = new ManagerToken();
Calendar c = Calendar.getInstance();
c.setTime(new Date());
token.setCreateTime(c.getTimeInMillis());
// 令牌有效时间1小时
c.add(Calendar.HOUR,1);
token.setUseTime(c.getTimeInMillis());
managerToken.setCreateTime(c.getTimeInMillis());
// 令牌有效时间1
c.add(Calendar.DAY_OF_MONTH, 1);
managerToken.setUseTime(c.getTimeInMillis());
// 生成token
token.setToken(DigestUtils.md5DigestAsHex((token.getCreateTime()+""+token.getUseTime()+"").getBytes()));
token.setManagerName(managerLogin.getManagerName());
return new JSONResponse<>(Result.OK,"登陆成功",token);
managerToken.setToken(DigestUtils.md5DigestAsHex((managerToken.getCreateTime() + "" + managerToken.getUseTime() + "").getBytes()));
managerToken.setManagerName(managerLogin.getManagerName());
managerTokenDao.save(managerToken);
LoginResponse response = new LoginResponse(Result.OK, LoginResponse.Msg.ok);
response.setManagerToken(managerToken);
return response;
}
}
@ -63,36 +74,29 @@ public class ManagerController {
* 获取邮箱类型
*/
@GetMapping("emailType")
public JSONResponse<List<EmailType>> getEmailType(){
return new JSONResponse<>(Result.OK,"获取邮箱类型成功", emailTypeConfig.getSupportType());
}
@PostMapping("sendcode")
public JSONResponse<String> sendEmail(String sender){
if(emailService.sendManagerCode(sender)){
return new JSONResponse<>(Result.OK,"发送邮件成功",null);
}else{
return new JSONResponse<>(Result.OK,"发送邮件失败",null);
}
public EmailTypeResponse getEmailType() {
EmailTypeResponse response = new EmailTypeResponse(Result.OK, EmailTypeResponse.Msg.ok);
response.setEmailTypeList(emailTypeConfig.getSupportType());
return response;
}
// 注册
// 注册
@PostMapping("register")
public JSONResponse<String> register(@RequestBody ManagerRegister manager){
if(StringUtils.isEmpty(manager.getManagerName())){
return new JSONResponse<>(Result.FAIL,"管理员不能为空",null);
}else if(StringUtils.isEmpty(manager.getPassword())){
return new JSONResponse<>(Result.FAIL,"密码不能为空",null);
}else if(StringUtils.isEmpty(manager.getConfirmPassword())){
return new JSONResponse<>(Result.FAIL,"确认密码不能为空",null);
}else if (!manager.getPassword().equals(manager.getConfirmPassword())) {
return new JSONResponse<>(Result.FAIL, "两次密码输入不一致", null);
public RegisterResponse register(@RequestBody ManagerRegister manager) {
if (StringUtils.isEmpty(manager.getManagerName())) {
return new RegisterResponse(Result.FAIL, RegisterResponse.Msg.manager);
} else if (StringUtils.isEmpty(manager.getPassword())) {
return new RegisterResponse(Result.FAIL, RegisterResponse.Msg.password);
} else if (StringUtils.isEmpty(manager.getConfirmPassword())) {
return new RegisterResponse(Result.FAIL, RegisterResponse.Msg.confirmPassword);
} else if (!manager.getPassword().equals(manager.getConfirmPassword())) {
return new RegisterResponse(Result.FAIL, RegisterResponse.Msg.passwordNotMatch);
} else if (StringUtils.isEmpty(manager.getMobile())) {
return new JSONResponse<>(Result.FAIL, "手机号不能为空", null);
return new RegisterResponse(Result.FAIL, RegisterResponse.Msg.mobie);
} else if (StringUtils.isEmpty(manager.getEmail())) {
return new JSONResponse<>(Result.FAIL, "邮箱不能为空", null);
return new RegisterResponse(Result.FAIL, RegisterResponse.Msg.email);
} else if (managerDao.hasUser(manager.getManagerName())) {
return new JSONResponse<>(Result.FAIL, "用户已存在", null);
return new RegisterResponse(Result.FAIL, RegisterResponse.Msg.username);
} else {
// 表单数据转换到管理员实体,调用dao层持久化到数据库
Manager m = new Manager();
@ -101,8 +105,67 @@ public class ManagerController {
m.setMobile(manager.getMobile());
m.setEmail(manager.getEmail());
managerDao.save(m);
return new JSONResponse<>(Result.OK,"注册成功",null);
return new RegisterResponse(Result.OK, RegisterResponse.Msg.ok);
}
}
//注销
@PostMapping("logout")
public LogoutResponse logout(@RequestBody ManagerLogout managerLogout) {
if (StringUtils.isEmpty(managerLogout.getManagerName())) {
return new LogoutResponse(Result.FAIL, LogoutResponse.Msg.fail);
} else {
if (managerTokenDao.logout(managerLogout)) {
return new LogoutResponse(Result.OK, LogoutResponse.Msg.ok);
} else {
return new LogoutResponse(Result.FAIL, LogoutResponse.Msg.fail);
}
}
}
//检查账号邮箱
@PostMapping("reset/checkEmail")
public ResetpwdResponse checkUserWithEmail(@RequestBody ManagerResetPwd managerResetPwd) {
if (managerDao.checkUserWithEmail(managerResetPwd)) {
return new ResetpwdResponse(Result.OK, ResetpwdResponse.Msg.check_ok);
} else {
return new ResetpwdResponse(Result.FAIL, ResetpwdResponse.Msg.check_fail);
}
}
/**
* 发送邮件
*/
@PostMapping("reset/code")
public ResetpwdResponse sendEmail(@RequestBody ManagerResetPwd managerResetPwd) {
if (emailService.sendManagerCode(managerResetPwd)) {
return new ResetpwdResponse(Result.OK, ResetpwdResponse.Msg.send_code_ok);
} else {
return new ResetpwdResponse(Result.FAIL, ResetpwdResponse.Msg.send_code_fail);
}
}
/**
* 校验验证码
*/
@PostMapping("reset/checkCode")
public ResetpwdResponse validCode(@RequestBody ManagerResetPwd managerResetPwd) {
if (emailDao.checkCode(managerResetPwd.getEmail() + managerResetPwd.getEmailType(), managerResetPwd.getVerificationCode())) {
return new ResetpwdResponse(Result.OK, ResetpwdResponse.Msg.valid_code_ok);
} else {
return new ResetpwdResponse(Result.FAIL, ResetpwdResponse.Msg.valid_code_fail);
}
}
/**
* 重置密码
*/
@PostMapping("reset/resetPwd")
public ResetpwdResponse resetpwd(@RequestBody ManagerResetPwd managerResetPwd) {
if (managerDao.resetpwd(managerResetPwd)) {
return new ResetpwdResponse(Result.OK, ResetpwdResponse.Msg.resetpwd_ok);
} else {
return new ResetpwdResponse(Result.FAIL, ResetpwdResponse.Msg.resetpwd_fail);
}
}
}

@ -13,9 +13,8 @@ public class EmailCode {
//验证码
private String code;
//发送时间
private Long sendTime=System.currentTimeMillis();
private final Long sendTime = System.currentTimeMillis();
//有效时间
public String getCode() {
return code;
}

@ -13,11 +13,11 @@ public class Manager {
// 密码
private String password;
// 手机号
private Long mobile;
// 邮箱
private Long mobile;
// 邮箱
private String email;
//令牌
private Token token;
private ManagerToken managerToken;
public String getManagerName() {
return managerName;
@ -51,11 +51,11 @@ public class Manager {
this.email = email;
}
public Token getToken() {
return token;
public ManagerToken getManagerToken() {
return managerToken;
}
public void setToken(Token token) {
this.token = token;
public void setManagerToken(ManagerToken managerToken) {
this.managerToken = managerToken;
}
}

@ -1,15 +1,18 @@
package com.community.pocket.entity.po;
import com.community.pocket.util.TableName;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.Document;
//登陆成功记录的令牌信息
public class Token {
@Document(TableName.managerToken)
public class ManagerToken {
//令牌
@Id
private String token;
//创建时间
private Long createTime;
// 有效时间
// 有效时间
private Long useTime;
// 管理员名
private String managerName;

@ -1,52 +0,0 @@
package com.community.pocket.entity.vo;
//接口统一返回json响应体
public class JSONResponse<T> {
// 响应结果
private Result result;
// 响应详细结果
private String message;
// 自定义其他响应信息
@Deprecated
private T body;
public JSONResponse() {
}
public JSONResponse(Result result, String message) {
this.result = result;
this.message = message;
}
@Deprecated
public JSONResponse(Result result, String message, T body) {
this.result = result;
this.message = message;
this.body = body;
}
public Result getResult() {
return result;
}
public void setResult(Result result) {
this.result = result;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
public T getBody() {
return body;
}
public void setBody(T body) {
this.body = body;
}
}

@ -1,12 +1,13 @@
package com.community.pocket.entity.vo.android;
package com.community.pocket.entity.vo;
import com.community.pocket.entity.vo.Result;
import com.community.pocket.entity.vo.android.CustomMessage;
/**
* android接口响应体
* 接口响应体
*
* @param <T>
*/
public abstract class AndroidResponse<T extends CustomMessage> {
public abstract class Response<T extends CustomMessage> {
//操作结果
private Result result;
@ -15,10 +16,10 @@ public abstract class AndroidResponse<T extends CustomMessage> {
private Object[] args;
public AndroidResponse(Result result, T message,Object ...args) {
public Response(Result result, T message, Object... args) {
this.result = result;
this.message = message;
this.args=args;
this.args = args;
}
public Object[] getArgs() {

@ -1,10 +1,11 @@
package com.community.pocket.entity.vo.android;
import com.community.pocket.entity.vo.Response;
import com.community.pocket.entity.vo.Result;
import java.util.List;
public class ForumDataResponse extends AndroidResponse<ForumDataResponse.Msg> {
public class ForumDataResponse extends Response<ForumDataResponse.Msg> {
private List<ForumContentVo> forumContentList;
public ForumDataResponse(Result result, Msg message, Object... args) {

@ -1,11 +1,12 @@
package com.community.pocket.entity.vo.android;
import com.community.pocket.entity.vo.Response;
import com.community.pocket.entity.vo.Result;
/**
* 热榜信息响应体
* 热榜信息响应体
*/
public class ForumHotResponse extends AndroidResponse<ForumHotResponse.Msg> {
public class ForumHotResponse extends Response<ForumHotResponse.Msg> {
private Hot hot;
public Hot getHot() {

@ -1,5 +1,6 @@
package com.community.pocket.entity.vo.android;
import com.community.pocket.entity.vo.Response;
import com.community.pocket.entity.vo.Result;
import java.util.List;
@ -7,7 +8,7 @@ import java.util.List;
/**
* 我的帖子响应结果
*/
public class ForumMyResponse extends AndroidResponse<ForumMyResponse.Msg>{
public class ForumMyResponse extends Response<ForumMyResponse.Msg> {
private List<ForumVo> forumList;
public ForumMyResponse(Result result, Msg message, Object... args) {

@ -1,5 +1,6 @@
package com.community.pocket.entity.vo.android;
import com.community.pocket.entity.vo.Response;
import com.community.pocket.entity.vo.Result;
import java.util.List;
@ -7,7 +8,7 @@ import java.util.List;
/**
* 最新帖子响应
*/
public class ForumNewResponse extends AndroidResponse<ForumNewResponse.Msg> {
public class ForumNewResponse extends Response<ForumNewResponse.Msg> {
private List<ForumVo> forumList;

@ -1,6 +1,7 @@
package com.community.pocket.entity.vo.android;
import com.community.pocket.entity.po.Notice;
import com.community.pocket.entity.vo.Response;
import com.community.pocket.entity.vo.Result;
import java.util.List;
@ -8,7 +9,7 @@ import java.util.List;
/**
* 公告响应体
*/
public class ForumNoticeResponse extends AndroidResponse<ForumNoticeResponse.Msg> {
public class ForumNoticeResponse extends Response<ForumNoticeResponse.Msg> {
private List<Notice> noticeList;

@ -1,16 +1,17 @@
package com.community.pocket.entity.vo.android;
import com.community.pocket.entity.vo.Response;
import com.community.pocket.entity.vo.Result;
/**
* 发帖响应
* 发帖响应
*/
public class ForumPostResponse extends AndroidResponse<ForumPostResponse.Msg>{
public class ForumPostResponse extends Response<ForumPostResponse.Msg> {
public ForumPostResponse(Result result, Msg message, Object... args) {
super(result, message, args);
}
public enum Msg implements CustomMessage{
public enum Msg implements CustomMessage {
ok,
fail,
token

@ -1,6 +1,6 @@
package com.community.pocket.entity.vo.android;
public enum GarbageCateGory {
public enum GarbageCateGory implements CustomMessage {
/**
* 1 (可回收垃圾)
* 2 (有害垃圾)
@ -8,33 +8,15 @@ public enum GarbageCateGory {
* 8 (干垃圾)
* 16 (大件垃圾)
*/
type1(1, "可回收垃圾"),
type2(2, "有害垃圾"),
type4(4, "湿垃圾"),
type8(8, "干垃圾"),
type16(16, "大件垃圾");
type1,
type2,
type4,
type8,
type16;
private Integer type;
private String name;
GarbageCateGory(Integer type, String name) {
this.type = type;
this.name = name;
}
public Integer getType() {
return type;
}
public void setType(Integer type) {
this.type = type;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
@Override
public String toString() {
return "waste." + name();
}
}

@ -1,5 +1,6 @@
package com.community.pocket.entity.vo.android;
import com.community.pocket.entity.vo.Response;
import com.community.pocket.entity.vo.Result;
import java.util.List;
@ -7,7 +8,7 @@ import java.util.List;
/**
* 垃圾分类信息
*/
public class GarbageSortingResponse extends AndroidResponse<GarbageSortingResponse.Msg> {
public class GarbageSortingResponse extends Response<GarbageSortingResponse.Msg> {
private List<GarbageVo> garbageSortings;
public GarbageSortingResponse(Result result, Msg message, Object... args) {

@ -2,6 +2,7 @@ package com.community.pocket.entity.vo.android;
import com.community.pocket.entity.po.android.GarbageWasteManage;
import com.community.pocket.entity.po.android.GarbageWastePrice;
import com.community.pocket.entity.vo.Response;
import com.community.pocket.entity.vo.Result;
import java.util.List;
@ -9,7 +10,7 @@ import java.util.List;
/**
* 废品返回信息
*/
public class GarbageWasteResponse extends AndroidResponse<GarbageWasteResponse.Msg> {
public class GarbageWasteResponse extends Response<GarbageWasteResponse.Msg> {
public GarbageWasteResponse(Result result, Msg message, Object... args) {
super(result, message, args);

@ -1,11 +1,12 @@
package com.community.pocket.entity.vo.android;
import com.community.pocket.entity.vo.Response;
import com.community.pocket.entity.vo.Result;
/**
* 个人信息响应
*/
public class InfoResponse extends AndroidResponse<InfoResponse.Msg>{
public class InfoResponse extends Response<InfoResponse.Msg> {
private Info myInfo;
public InfoResponse(Result result, Msg message, Object... args) {

@ -1,12 +1,13 @@
package com.community.pocket.entity.vo.android;
import com.community.pocket.entity.po.android.Token;
import com.community.pocket.entity.vo.Response;
import com.community.pocket.entity.vo.Result;
/**
* 登陆响应
*/
public class LoginResponse extends AndroidResponse<LoginResponse.Msg> {
public class LoginResponse extends Response<LoginResponse.Msg> {
private Token token;
public Token getToken() {

@ -1,5 +1,6 @@
package com.community.pocket.entity.vo.android;
import com.community.pocket.entity.vo.Response;
import com.community.pocket.entity.vo.Result;
import java.util.List;
@ -7,7 +8,7 @@ import java.util.List;
/**
* 查询用户
*/
public class QueryUserResponse extends AndroidResponse<QueryUserResponse.Msg>{
public class QueryUserResponse extends Response<QueryUserResponse.Msg> {
private List<String> peopleList;
public QueryUserResponse(Result result, Msg message, Object... args) {

@ -1,11 +1,12 @@
package com.community.pocket.entity.vo.android;
import com.community.pocket.entity.vo.Response;
import com.community.pocket.entity.vo.Result;
/**
* 注册响应
*/
public class RegisterResponse extends AndroidResponse<RegisterResponse.Msg> {
public class RegisterResponse extends Response<RegisterResponse.Msg> {
public RegisterResponse(Result result, Msg message, Object... args) {

@ -1,11 +1,12 @@
package com.community.pocket.entity.vo.android;
import com.community.pocket.entity.vo.Response;
import com.community.pocket.entity.vo.Result;
/**
* 重置密码响应
*/
public class ResetPwdResponse extends AndroidResponse<ResetPwdResponse.Msg>{
public class ResetPwdResponse extends Response<ResetPwdResponse.Msg> {
public ResetPwdResponse(Result result, Msg message, Object... args) {
super(result, message, args);

@ -1,6 +1,7 @@
package com.community.pocket.entity.vo.android;
import com.community.pocket.entity.po.android.Visitor;
import com.community.pocket.entity.vo.Response;
import com.community.pocket.entity.vo.Result;
import java.util.List;
@ -8,7 +9,7 @@ import java.util.List;
/**
* 我的访客信息
*/
public class VisitorMyResponse extends AndroidResponse<VisitorMyResponse.Msg> {
public class VisitorMyResponse extends Response<VisitorMyResponse.Msg> {
private List<Visitor> visitorList;

@ -1,6 +1,7 @@
package com.community.pocket.entity.vo.android;
import com.community.pocket.entity.po.android.VisitorPeople;
import com.community.pocket.entity.vo.Response;
import com.community.pocket.entity.vo.Result;
import java.util.List;
@ -8,7 +9,7 @@ import java.util.List;
/**
* 查询预约人返回结果
*/
public class VisitorPeopleResponse extends AndroidResponse<VisitorPeopleResponse.Msg> {
public class VisitorPeopleResponse extends Response<VisitorPeopleResponse.Msg> {
private List<VisitorPeople> visitorPeopleList;

@ -1,12 +1,13 @@
package com.community.pocket.entity.vo.android;
import com.community.pocket.entity.po.android.Visitor;
import com.community.pocket.entity.vo.Response;
import com.community.pocket.entity.vo.Result;
import java.util.List;
//我的预约信息
public class VisitorReservationResponse extends AndroidResponse<VisitorReservationResponse.Msg> {
public class VisitorReservationResponse extends Response<VisitorReservationResponse.Msg> {
private List<Visitor> visitorList;
public VisitorReservationResponse(Result result, Msg message, Object... args) {

@ -1,11 +1,12 @@
package com.community.pocket.entity.vo.android;
import com.community.pocket.entity.vo.Response;
import com.community.pocket.entity.vo.Result;
/**
* 访客预约结果
*/
public class VisitorResponse extends AndroidResponse<VisitorResponse.Msg> {
public class VisitorResponse extends Response<VisitorResponse.Msg> {
public VisitorResponse(Result result, Msg message, Object... args) {
super(result, message, args);

@ -0,0 +1,32 @@
package com.community.pocket.entity.vo.web;
import com.community.pocket.entity.vo.EmailType;
import com.community.pocket.entity.vo.Response;
import com.community.pocket.entity.vo.Result;
import com.community.pocket.entity.vo.android.CustomMessage;
import java.util.List;
/**
* 邮箱类型响应
*/
public class EmailTypeResponse extends Response<EmailTypeResponse.Msg> {
private List<EmailType> emailTypeList;
public EmailTypeResponse(Result result, Msg message, Object... args) {
super(result, message, args);
}
public List<EmailType> getEmailTypeList() {
return emailTypeList;
}
public void setEmailTypeList(List<EmailType> emailTypeList) {
this.emailTypeList = emailTypeList;
}
public enum Msg implements CustomMessage {
ok,
fail
}
}

@ -0,0 +1,37 @@
package com.community.pocket.entity.vo.web;
import com.community.pocket.entity.po.ManagerToken;
import com.community.pocket.entity.vo.Response;
import com.community.pocket.entity.vo.Result;
import com.community.pocket.entity.vo.android.CustomMessage;
/**
* 管理员响应
*/
public class LoginResponse extends Response<LoginResponse.Msg> {
private ManagerToken managerToken;
public ManagerToken getManagerToken() {
return managerToken;
}
public void setManagerToken(ManagerToken managerToken) {
this.managerToken = managerToken;
}
public LoginResponse(Result result, Msg message, Object... args) {
super(result, message, args);
}
public enum Msg implements CustomMessage {
//管理员不能为空
manager,
//密码不能为空
password,
//账号或密码错误
fail,
//登陆成功
ok
}
}

@ -0,0 +1,22 @@
package com.community.pocket.entity.vo.web;
import com.community.pocket.entity.vo.Response;
import com.community.pocket.entity.vo.Result;
import com.community.pocket.entity.vo.android.CustomMessage;
/**
* 注销响应
*/
public class LogoutResponse extends Response<LogoutResponse.Msg> {
public LogoutResponse(Result result, Msg message, Object... args) {
super(result, message, args);
}
public enum Msg implements CustomMessage {
//注销成功
ok,
//注销失败
fail
}
}

@ -1,5 +1,8 @@
package com.community.pocket.entity.vo;
package com.community.pocket.entity.vo.web;
/**
* 管理员登录
*/
public class ManagerLogin {
private String managerName;
private String password;

@ -0,0 +1,14 @@
package com.community.pocket.entity.vo.web;
//注销表单
public class ManagerLogout {
private String managerName;
public String getManagerName() {
return managerName;
}
public void setManagerName(String managerName) {
this.managerName = managerName;
}
}

@ -1,4 +1,4 @@
package com.community.pocket.entity.vo;
package com.community.pocket.entity.vo.web;
/**
* 管理员注册

@ -0,0 +1,57 @@
package com.community.pocket.entity.vo.web;
/**
* 重置密码表单
*/
public class ManagerResetPwd {
//管理员名
private String managerName;
//邮箱
private String email;
//验证码
private String verificationCode;
//新密码
private String password;
//邮箱类型
private String emailType;
public String getEmailType() {
return emailType;
}
public void setEmailType(String emailType) {
this.emailType = emailType;
}
public String getManagerName() {
return managerName;
}
public void setManagerName(String managerName) {
this.managerName = managerName;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getVerificationCode() {
return verificationCode;
}
public void setVerificationCode(String verificationCode) {
this.verificationCode = verificationCode;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
}

@ -0,0 +1,30 @@
package com.community.pocket.entity.vo.web;
import com.community.pocket.entity.vo.Response;
import com.community.pocket.entity.vo.Result;
import com.community.pocket.entity.vo.android.CustomMessage;
public class RegisterResponse extends Response<RegisterResponse.Msg> {
public RegisterResponse(Result result, Msg message, Object... args) {
super(result, message, args);
}
public enum Msg implements CustomMessage {
//管理员不能为空
manager,
//密码不能为空
password,
//确认密码不能为空
confirmPassword,
//两次密码输入不一致
passwordNotMatch,
//手机号不能为空
mobie,
//邮箱不能为空
email,
//用户已存在
username,
//注册成功
ok
}
}

@ -0,0 +1,34 @@
package com.community.pocket.entity.vo.web;
import com.community.pocket.entity.vo.Response;
import com.community.pocket.entity.vo.Result;
import com.community.pocket.entity.vo.android.CustomMessage;
/**
* 重置密码响应
*/
public class ResetpwdResponse extends Response<CustomMessage> {
public ResetpwdResponse(Result result, CustomMessage message, Object... args) {
super(result, message, args);
}
public enum Msg implements CustomMessage {
//校验成功
check_ok,
//账号或邮箱错误
check_fail,
//验证码发送成功,请查收验证码
send_code_ok,
//验证码发送失败,请重试或联系管理员
send_code_fail,
//校验成功
valid_code_ok,
//验证码不正确,请重新输入
valid_code_fail,
//重置密码成功
resetpwd_ok,
//重置密码失败
resetpwd_fail
}
}

@ -1,10 +0,0 @@
package com.community.pocket.repository;
import com.community.pocket.entity.po.Forum;
import org.springframework.data.mongodb.repository.MongoRepository;
import org.springframework.data.rest.core.annotation.RepositoryRestResource;
//论坛Restful接口
@RepositoryRestResource
public interface ForumRepo extends MongoRepository<Forum,String> {
}

@ -2,11 +2,13 @@ package com.community.pocket.repository;
import com.community.pocket.entity.po.Manager;
import com.community.pocket.entity.vo.ManagerLogin;
import com.community.pocket.entity.vo.web.ManagerLogin;
import com.community.pocket.entity.vo.web.ManagerResetPwd;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.data.mongodb.core.query.Update;
import org.springframework.stereotype.Repository;
import org.springframework.util.DigestUtils;
@ -45,9 +47,9 @@ public class ManagerDao extends BaseDao<Manager>{
}
}
// 保存管理员注册信息
// 保存管理员注册信息
@Override
public Manager save(Manager manager){
public Manager save(Manager manager) {
try {
return mongoTemplate.save(manager);
} catch (Exception e) {
@ -57,6 +59,17 @@ public class ManagerDao extends BaseDao<Manager>{
return null;
}
//检查账号邮箱是否匹配
public boolean checkUserWithEmail(ManagerResetPwd managerResetPwd) {
return mongoTemplate.exists(new Query(Criteria.where("managerName").is(managerResetPwd.getManagerName()).and("email").is(managerResetPwd.getEmail())), entityClass());
}
//重置密码
public boolean resetpwd(ManagerResetPwd managerResetPwd) {
String md5password = DigestUtils.md5DigestAsHex(managerResetPwd.getPassword().getBytes());
return mongoTemplate.updateFirst(new Query(Criteria.where("managerName").is(managerResetPwd.getManagerName())), Update.update("password", md5password), entityClass()).wasAcknowledged();
}
@Override
public Class<Manager> entityClass() {
return Manager.class;

@ -1,11 +0,0 @@
package com.community.pocket.repository;
import com.community.pocket.entity.po.Manager;
import org.springframework.data.mongodb.repository.MongoRepository;
import org.springframework.data.rest.core.annotation.RepositoryRestResource;
//管理员Restful接口
@RepositoryRestResource
public interface ManagerRepo extends MongoRepository<Manager,String> {
}

@ -0,0 +1,39 @@
package com.community.pocket.repository;
import com.community.pocket.entity.po.ManagerToken;
import com.community.pocket.entity.vo.web.ManagerLogout;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Repository;
/**
* 管理员令牌
*/
@Repository
public class ManagerTokenDao extends BaseDao<ManagerToken> {
private static final Logger LOG = LoggerFactory.getLogger(ManagerTokenDao.class);
@Override
public ManagerToken save(ManagerToken managerToken) {
try {
return mongoTemplate.save(managerToken);
} catch (Exception e) {
e.printStackTrace();
LOG.error(e.toString());
}
return null;
}
//注销
public boolean logout(ManagerLogout managerLogout) {
return mongoTemplate.remove(new Query(Criteria.where("managerName").is(managerLogout.getManagerName())), entityClass()).wasAcknowledged();
}
@Override
public Class<ManagerToken> entityClass() {
return ManagerToken.class;
}
}

@ -5,8 +5,10 @@ import com.community.pocket.entity.vo.android.GarbageCateGory;
import com.community.pocket.entity.vo.android.GarbageVo;
import com.community.pocket.entity.vo.android.QueryGarbageForm;
import com.community.pocket.repository.BaseDao;
import com.community.pocket.util.MessageService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Repository;
@ -20,6 +22,9 @@ import java.util.regex.Pattern;
public class GarbageDao extends BaseDao<Garbage> {
private static final Logger LOG = LoggerFactory.getLogger(GarbageDao.class);
@Autowired
private MessageService messageService;
//查询垃圾分类信息
public List<GarbageVo> query(QueryGarbageForm garbageForm) {
List<GarbageVo> garbageVos = new ArrayList<>();
@ -29,19 +34,19 @@ public class GarbageDao extends BaseDao<Garbage> {
garbageVo.setName(garbage.getName());
switch (garbage.getCategory()) {
case 1:
garbageVo.setSorting(GarbageCateGory.type1.getName());
garbageVo.setSorting(messageService.getMessage(GarbageCateGory.type1));
break;
case 2:
garbageVo.setSorting(GarbageCateGory.type2.getName());
garbageVo.setSorting(messageService.getMessage(GarbageCateGory.type2));
break;
case 4:
garbageVo.setSorting(GarbageCateGory.type4.getName());
garbageVo.setSorting(messageService.getMessage(GarbageCateGory.type4));
break;
case 8:
garbageVo.setSorting(GarbageCateGory.type8.getName());
garbageVo.setSorting(messageService.getMessage(GarbageCateGory.type8));
break;
case 16:
garbageVo.setSorting(GarbageCateGory.type16.getName());
garbageVo.setSorting(messageService.getMessage(GarbageCateGory.type16));
break;
}
garbageVos.add(garbageVo);

@ -2,6 +2,7 @@ package com.community.pocket.util;
import com.community.pocket.entity.po.EmailCode;
import com.community.pocket.entity.vo.EmailTypeConfig;
import com.community.pocket.entity.vo.web.ManagerResetPwd;
import com.community.pocket.repository.EmailDao;
import org.apache.commons.lang3.RandomStringUtils;
import org.springframework.beans.factory.annotation.Autowired;
@ -22,25 +23,28 @@ public class EmailService {
private EmailDao emailDao;
/**
* 发送管理员注册激活邮件
* @param sender 发送人
* 发送管理员重置密码邮件
*/
public boolean sendManagerCode(String sender) {
EmailCode emailCode=new EmailCode();
emailCode.setCode(RandomStringUtils.randomNumeric(emailTypeConfig.getLength()));
emailCode.setEmailAddress(sender);
SimpleMailMessage message = new SimpleMailMessage();
message.setSubject(emailTypeConfig.getSubject());
message.setText(String.format(emailTypeConfig.getManagerCodeMessage(),emailCode.getCode()));
message.setTo(sender);
message.setFrom(emailTypeConfig.getFrom());
try {
javaMailSender.send(message);
public boolean sendManagerCode(ManagerResetPwd managerResetPwd) {
if (emailDao.clearEmail(managerResetPwd.getEmail() + managerResetPwd.getEmailType())) {
EmailCode emailCode = new EmailCode();
emailCode.setCode(RandomStringUtils.randomNumeric(emailTypeConfig.getLength()));
emailCode.setEmailAddress(managerResetPwd.getEmail() + managerResetPwd.getEmailType());
SimpleMailMessage message = new SimpleMailMessage();
message.setSubject(emailTypeConfig.getSubject());
message.setText(String.format(emailTypeConfig.getManagerCodeMessage(), emailCode.getCode()));
message.setTo(emailCode.getEmailAddress());
message.setFrom(emailTypeConfig.getFrom());
try {
javaMailSender.send(message);
emailDao.save(emailCode);
return true;
} catch (MailException e) {
e.printStackTrace();
emailDao.save(emailCode);
return true;
} catch (MailException e) {
e.printStackTrace();
return false;
}
} else {
return false;
}
}

@ -0,0 +1,43 @@
package com.community.pocket.util;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.LocaleResolver;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import org.springframework.web.servlet.i18n.LocaleChangeInterceptor;
import org.springframework.web.servlet.i18n.SessionLocaleResolver;
import java.util.Locale;
/**
* 配置国际化语言
*/
@Configuration
public class LocaleConfig {
/**
* 默认解析器 其中locale表示默认语言
*/
@Bean
public LocaleResolver localeResolver() {
SessionLocaleResolver localeResolver = new SessionLocaleResolver();
localeResolver.setDefaultLocale(Locale.US);
return localeResolver;
}
/**
* 默认拦截器 其中lang表示切换语言的参数名
*/
@Bean
public WebMvcConfigurer localeInterceptor() {
return new WebMvcConfigurer() {
@Override
public void addInterceptors(InterceptorRegistry registry) {
LocaleChangeInterceptor localeInterceptor = new LocaleChangeInterceptor();
localeInterceptor.setParamName("lang");
registry.addInterceptor(localeInterceptor);
}
};
}
}

@ -0,0 +1,21 @@
package com.community.pocket.util;
import com.community.pocket.entity.vo.android.CustomMessage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.MessageSource;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.stereotype.Service;
/**
* 国际化配置
*/
@Service
public class MessageService {
@Autowired
private MessageSource messageSource;
public <T extends CustomMessage> String getMessage(T code, Object... args) {
return messageSource.getMessage(code.toString(), args, LocaleContextHolder.getLocale());
}
}

@ -22,7 +22,12 @@ public class TableName {
public static final String notice = "notice";
//访客信息
public static final String visitor = "visitor";
//预约配置信息
public static final String visitorPeople = "visitorPeople";
//垃圾分类信息
public static final String garbage = "garbage";
//废品回收价格
public static final String garbageWastePrice = "garbageWastePrice";
//管理员令牌
public static final String managerToken = "managerToken";
}

@ -1,5 +1,5 @@
#数据库配置
spring:
#数据库配置
data:
mongodb:
database: demo
@ -12,6 +12,9 @@ spring:
smtp:
ssl:
enable: true
#国际化配置
messages:
basename: static/i18n/messages #相对路径 开头请勿添加斜杠
#邮箱配置
email:
@ -28,9 +31,9 @@ email:
#长度
length: 6
#管理员激活邮件模版
manager: 欢迎注册口袋社区后台服务,您获取到的验证码是:%s
manager: 尊敬的管理员您好,欢迎使用重置密码服务,您获取到的验证码是:%s
#用户重置密码邮件模版
user: 重置密码,您获取到的验证码是:%s
user: 尊敬的用户您好,欢迎使用重置密码服务,您获取到的验证码是:%s
#令牌配置
token:

@ -0,0 +1,5 @@
waste.type1=recoverable
waste.type16=Bulky Waste
waste.type2=hazardous waste
waste.type4=wet garbage
waste.type8=dry refuse

@ -0,0 +1,5 @@
waste.type1=recoverable
waste.type16=Bulky Waste
waste.type2=hazardous waste
waste.type4=wet garbage
waste.type8=dry refuse

@ -0,0 +1,5 @@
waste.type1=可回收垃圾
waste.type16=大件垃圾
waste.type2=有害垃圾
waste.type4=湿垃圾
waste.type8=干垃圾

@ -2,11 +2,13 @@ package com.community.pocket;
import com.community.pocket.entity.po.android.Garbage;
import com.community.pocket.entity.po.android.GarbageWastePrice;
import com.community.pocket.entity.vo.android.GarbageCateGory;
import com.community.pocket.entity.vo.android.QueryUserForm;
import com.community.pocket.repository.android.GarbageDao;
import com.community.pocket.repository.android.GarbagePriceDao;
import com.community.pocket.repository.android.UserDao;
import com.community.pocket.repository.android.VisitorPeopleDao;
import com.community.pocket.util.MessageService;
import com.google.gson.Gson;
import org.apache.commons.lang3.RandomStringUtils;
import org.junit.jupiter.api.Test;
@ -35,6 +37,9 @@ class DemoApplicationTests {
@Autowired
private GarbagePriceDao garbagePriceDao;
@Autowired
private MessageService messageService;
private static final Logger LOG = LoggerFactory.getLogger(DemoApplicationTests.class);
@Test
@ -73,4 +78,9 @@ class DemoApplicationTests {
}
}
@Test
void testMessage() {
LOG.info(messageService.getMessage(GarbageCateGory.type1));
}
}

Loading…
Cancel
Save