|
@@ -0,0 +1,827 @@
|
|
|
|
|
+/**
|
|
|
|
|
+ * Copyright (c) 2012-present 铭软科技(mingsoft.net)
|
|
|
|
|
+ * 本软件及相关文档文件(以下简称“软件”)的版权归 铭软科技 所有
|
|
|
|
|
+ * 遵循 铭软科技《服务协议》中的《保密条款》
|
|
|
|
|
+ */
|
|
|
|
|
+package net.mingsoft.people.action.web;
|
|
|
|
|
+
|
|
|
|
|
+import cn.hutool.core.date.DateUtil;
|
|
|
|
|
+import cn.hutool.core.lang.Validator;
|
|
|
|
|
+import cn.hutool.core.util.RandomUtil;
|
|
|
|
|
+import cn.hutool.crypto.SecureUtil;
|
|
|
|
|
+import cn.hutool.http.HttpUtil;
|
|
|
|
|
+import cn.hutool.json.JSONObject;
|
|
|
|
|
+import cn.hutool.json.JSONUtil;
|
|
|
|
|
+import io.swagger.v3.oas.annotations.Operation;
|
|
|
|
|
+import io.swagger.v3.oas.annotations.Parameter;
|
|
|
|
|
+import io.swagger.v3.oas.annotations.Parameters;
|
|
|
|
|
+import io.swagger.v3.oas.annotations.enums.ParameterIn;
|
|
|
|
|
+import io.swagger.v3.oas.annotations.tags.Tag;
|
|
|
|
|
+import jakarta.servlet.http.HttpServletRequest;
|
|
|
|
|
+import jakarta.servlet.http.HttpServletResponse;
|
|
|
|
|
+import net.mingsoft.base.entity.ResultData;
|
|
|
|
|
+import net.mingsoft.base.exception.BusinessException;
|
|
|
|
|
+import net.mingsoft.basic.realm.CustomUserNamePasswordToken;
|
|
|
|
|
+import net.mingsoft.basic.util.BasicUtil;
|
|
|
|
|
+import net.mingsoft.basic.util.RestTemplateUtil;
|
|
|
|
|
+import net.mingsoft.basic.util.StringUtil;
|
|
|
|
|
+import net.mingsoft.mdiy.util.ConfigUtil;
|
|
|
|
|
+import net.mingsoft.people.action.BaseAction;
|
|
|
|
|
+import net.mingsoft.people.action.people.PeopleUserAction;
|
|
|
|
|
+import net.mingsoft.people.annotation.PeopleLogAnn;
|
|
|
|
|
+import net.mingsoft.people.bean.PeopleBean;
|
|
|
|
|
+import net.mingsoft.people.bean.PeopleLoginBean;
|
|
|
|
|
+import net.mingsoft.people.biz.IPeopleBiz;
|
|
|
|
|
+import net.mingsoft.people.biz.IPeopleUserBiz;
|
|
|
|
|
+import net.mingsoft.people.constant.e.PeopleEnum;
|
|
|
|
|
+import net.mingsoft.people.constant.e.PeopleLogTypeEnum;
|
|
|
|
|
+import net.mingsoft.people.constant.e.SessionConstEnum;
|
|
|
|
|
+import net.mingsoft.people.entity.PeopleEntity;
|
|
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
|
|
+import org.apache.shiro.SecurityUtils;
|
|
|
|
|
+import org.apache.shiro.authz.UnauthorizedException;
|
|
|
|
|
+import org.apache.shiro.subject.Subject;
|
|
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
+import org.springframework.http.ResponseEntity;
|
|
|
|
|
+import org.springframework.stereotype.Controller;
|
|
|
|
|
+import org.springframework.util.LinkedMultiValueMap;
|
|
|
|
|
+import org.springframework.util.MultiValueMap;
|
|
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
|
|
+
|
|
|
|
|
+import java.sql.Timestamp;
|
|
|
|
|
+import java.util.Date;
|
|
|
|
|
+import java.util.HashMap;
|
|
|
|
|
+import java.util.Map;
|
|
|
|
|
+import java.util.Optional;
|
|
|
|
|
+/**
|
|
|
|
|
+ * 铭飞会员模块,前端调用(不需要用户登录进行的操作)
|
|
|
|
|
+ *
|
|
|
|
|
+ * @author 铭飞开发团队
|
|
|
|
|
+ * @version 版本号:0.0<br/>
|
|
|
|
|
+ * 创建日期:2017-8-23 10:10:22<br/>
|
|
|
|
|
+ * 历史修订:<br/>
|
|
|
|
|
+ */
|
|
|
|
|
+
|
|
|
|
|
+/**
|
|
|
|
|
+ * 原来的的代码有点问题,强行覆盖
|
|
|
|
|
+ *
|
|
|
|
|
+ * @author hx
|
|
|
|
|
+ * @date 2025-10-20
|
|
|
|
|
+ */
|
|
|
|
|
+@Tag(name = "前端-会员模块接口")
|
|
|
|
|
+@Controller("webPeople")
|
|
|
|
|
+@RequestMapping("/")
|
|
|
|
|
+public class PeopleAction extends BaseAction {
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 注入用户基础业务层
|
|
|
|
|
+ */
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private IPeopleBiz peopleBiz;
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 注入用户基础业务层
|
|
|
|
|
+ */
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private IPeopleUserBiz peopleUserBiz;
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private PeopleUserAction action;
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ @Operation(summary = "验证码验证,例如流程需要短信验证或邮箱验证,为有效防止恶意发送验证码。提供给ajax异步请求使用,注意:页面提交对验证码表单属性名称必须是rand_code,否则无效")
|
|
|
|
|
+ @Parameter(name = "rand_code", description = "验证码", required = true, in = ParameterIn.QUERY)
|
|
|
|
|
+ @PostMapping(value = "/checkCode")
|
|
|
|
|
+ @ResponseBody
|
|
|
|
|
+ public ResultData checkCode(HttpServletRequest request, HttpServletResponse response) {
|
|
|
|
|
+ // 验证码验证 验证码不为null 或 验证码不相等
|
|
|
|
|
+ if (!checkRandCode()) {
|
|
|
|
|
+ return ResultData.build().error(
|
|
|
|
|
+ this.getResString("err.error", this.getResString("rand.code")));
|
|
|
|
|
+ }
|
|
|
|
|
+ return ResultData.build().success();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Operation(summary = "验证用户名、手机号、邮箱是否可用,同一时间只能判断一种,优先用户名称 ,只验证已绑定的用户,建议独立使用")
|
|
|
|
|
+ @Parameters({
|
|
|
|
|
+ @Parameter(name = "peopleMail", description = "用户邮箱", required = false, in = ParameterIn.QUERY),
|
|
|
|
|
+ @Parameter(name = "peopleName", description = "登录帐号", required = false, in = ParameterIn.QUERY),
|
|
|
|
|
+ @Parameter(name = "peoplePhone", description = "用户电话", required = false, in = ParameterIn.QUERY)
|
|
|
|
|
+ })
|
|
|
|
|
+ @PostMapping(value = "/check")
|
|
|
|
|
+ @ResponseBody
|
|
|
|
|
+ public ResultData check(@ModelAttribute @Parameter(hidden = true) PeopleEntity people, HttpServletRequest request, HttpServletResponse response) {
|
|
|
|
|
+ PeopleEntity _people = peopleBiz.getByPeople(people);
|
|
|
|
|
+ if (_people != null) {
|
|
|
|
|
+ return ResultData.build().success();
|
|
|
|
|
+ } else {
|
|
|
|
|
+ return ResultData.build().error();
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Operation(summary = "微信-登录")
|
|
|
|
|
+ @Parameters({
|
|
|
|
|
+ @Parameter(name = "peoplePassword", description = "用户密码", required = true, in = ParameterIn.QUERY),
|
|
|
|
|
+ @Parameter(name = "peopleName", description = "登录帐号", required = true, in = ParameterIn.QUERY),
|
|
|
|
|
+ })
|
|
|
|
|
+ @PostMapping(value = "/wx_checkLogin")
|
|
|
|
|
+ @ResponseBody
|
|
|
|
|
+ @PeopleLogAnn(title = "登录", businessType = PeopleLogTypeEnum.LOGIN)
|
|
|
|
|
+ public ResultData wxCheckLogin(String code, HttpServletRequest request,
|
|
|
|
|
+ HttpServletResponse response) {
|
|
|
|
|
+ return Optional.ofNullable(code)
|
|
|
|
|
+ .map(c -> "https://api.weixin.qq.com/sns/jscode2session?appid=wx0a115eb69d6e9359&secret=d906c8ca51acfd61e13dd61b62364050&js_code=" + c + "&grant_type=authorization_code")
|
|
|
|
|
+ .map(HttpUtil::get)
|
|
|
|
|
+ .map(JSONObject::new)
|
|
|
|
|
+ .map(json -> json.getStr("openid"))
|
|
|
|
|
+ .filter(StringUtils::isNotBlank)
|
|
|
|
|
+ .map(openid -> {
|
|
|
|
|
+ Map<String, String> map = new HashMap<>();
|
|
|
|
|
+ map.put("openid", openid);
|
|
|
|
|
+ PeopleEntity user = this.peopleBiz.getEntityByUserName(openid);
|
|
|
|
|
+ if (user != null) {
|
|
|
|
|
+ return executeLogin(openid,request,response);
|
|
|
|
|
+ }
|
|
|
|
|
+ return ResultData.build().success(map);
|
|
|
|
|
+ })
|
|
|
|
|
+ .orElse(ResultData.build().error("登录失败"));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Operation(summary = "登录验证,登录必须存在验证码")
|
|
|
|
|
+ @Parameters({
|
|
|
|
|
+ @Parameter(name = "peoplePassword", description = "用户密码", required = true, in = ParameterIn.QUERY),
|
|
|
|
|
+ @Parameter(name = "peopleName", description = "登录帐号", required = true, in = ParameterIn.QUERY),
|
|
|
|
|
+ @Parameter(name = "rand_code", description = "验证码", required = true, in = ParameterIn.QUERY),
|
|
|
|
|
+ @Parameter(name = "peopleAutoLogin", description = " 大于0表示自动登录", required = false, in = ParameterIn.QUERY),
|
|
|
|
|
+ })
|
|
|
|
|
+ @PostMapping(value = "/checkLogin")
|
|
|
|
|
+ @ResponseBody
|
|
|
|
|
+ @PeopleLogAnn(title = "登录", businessType = PeopleLogTypeEnum.LOGIN)
|
|
|
|
|
+ public ResultData checkLogin(@ModelAttribute @Parameter(hidden = true) PeopleEntity people, HttpServletRequest request,
|
|
|
|
|
+ HttpServletResponse response) {
|
|
|
|
|
+ // 是否开启了登录功能
|
|
|
|
|
+ String switchLogin = ConfigUtil.getString("会员配置", "enableLogin");
|
|
|
|
|
+ if ("false".equalsIgnoreCase(switchLogin)) {
|
|
|
|
|
+ return ResultData.build().error("登录功能已被关闭!");
|
|
|
|
|
+ }
|
|
|
|
|
+ // 验证码验证 验证码不为null 或 验证码不相等
|
|
|
|
|
+ if (!this.checkRandCode()) {
|
|
|
|
|
+ return ResultData.build().error(this.getResString("err.error", this.getResString("rand.code")));
|
|
|
|
|
+ }
|
|
|
|
|
+ // 用户名和密码不能为空
|
|
|
|
|
+ if (StringUtils.isBlank(people.getPeopleName()) || StringUtils.isBlank(people.getPeoplePassword())) {
|
|
|
|
|
+ return ResultData.build().error(
|
|
|
|
|
+ this.getResString("err.error", this.getResString("people")));
|
|
|
|
|
+ }
|
|
|
|
|
+ PeopleEntity peopleEntity = this.peopleBiz.getEntityByUserName(people.getPeopleName());
|
|
|
|
|
+ if (peopleEntity == null) {
|
|
|
|
|
+ // 用户名或密码错误
|
|
|
|
|
+ return ResultData.build().error(
|
|
|
|
|
+ this.getResString("err.error", this.getResString("people.no.exist")));
|
|
|
|
|
+ }
|
|
|
|
|
+ Subject subject = SecurityUtils.getSubject();
|
|
|
|
|
+ CustomUserNamePasswordToken cupt = new CustomUserNamePasswordToken(peopleEntity.getPeopleName(), people.getPeoplePassword(), CustomUserNamePasswordToken.AuthType.PEOPLE);
|
|
|
|
|
+ try {
|
|
|
|
|
+ LOG.debug("people 尝试登陆");
|
|
|
|
|
+ subject.login(cupt);
|
|
|
|
|
+ LOG.debug("people 登陆成功");
|
|
|
|
|
+ peopleEntity.setPeopleIp(BasicUtil.getIp());
|
|
|
|
|
+ peopleBiz.updateById(peopleEntity);
|
|
|
|
|
+ PeopleLoginBean tempPeople = new PeopleLoginBean();
|
|
|
|
|
+ tempPeople.setId(peopleEntity.getId());
|
|
|
|
|
+ tempPeople.setPeopleName(peopleEntity.getPeopleName());
|
|
|
|
|
+ tempPeople.setPeopleMail(peopleEntity.getPeopleMail());
|
|
|
|
|
+ tempPeople.setPeopleState(peopleEntity.getPeopleState()); // 状态
|
|
|
|
|
+ return ResultData.build().success(tempPeople);
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ LOG.debug("people 登陆失败");
|
|
|
|
|
+ if (e.getCause() instanceof BusinessException) {
|
|
|
|
|
+ throw (BusinessException) e.getCause();
|
|
|
|
|
+ }
|
|
|
|
|
+ e.printStackTrace();
|
|
|
|
|
+ }
|
|
|
|
|
+ return ResultData.build().error(
|
|
|
|
|
+ this.getResString("err.error", this.getResString("people.no.exist")));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Operation(summary = "验证用户是否登录")
|
|
|
|
|
+ @PostMapping(value = "/checkLoginStatus")
|
|
|
|
|
+ @ResponseBody
|
|
|
|
|
+ public ResultData checkLoginStatus(HttpServletRequest request, HttpServletResponse response) {
|
|
|
|
|
+ try {
|
|
|
|
|
+ PeopleEntity people = this.getPeopleBySession();
|
|
|
|
|
+ return ResultData.build().success();
|
|
|
|
|
+ } catch (UnauthorizedException e) {
|
|
|
|
|
+ return ResultData.build().error();
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Operation(summary = "验证重置密码过程中收到的验证码是否正确")
|
|
|
|
|
+ @Parameters({
|
|
|
|
|
+ @Parameter(name = "peopleCode", description = "用户随机验证码", required = true, in = ParameterIn.QUERY),
|
|
|
|
|
+ @Parameter(name = "rand_code", description = "验证码", required = true, in = ParameterIn.QUERY)
|
|
|
|
|
+ })
|
|
|
|
|
+ @PostMapping(value = "/checkResetPasswordCode")
|
|
|
|
|
+ @ResponseBody
|
|
|
|
|
+ @PeopleLogAnn(title = "修改密码", businessType = PeopleLogTypeEnum.UPDATE)
|
|
|
|
|
+ public ResultData checkResetPasswordCode(@ModelAttribute @Parameter(hidden = true) PeopleEntity people, HttpServletRequest request,
|
|
|
|
|
+ HttpServletResponse response) {
|
|
|
|
|
+ // 验证码验证 验证码不为null 或 验证码不相等
|
|
|
|
|
+ if (StringUtils.isBlank(this.getRandCode()) || !this.checkRandCode()) {
|
|
|
|
|
+ return ResultData.build().error(this.getResString("err.error", this.getResString("rand.code")));
|
|
|
|
|
+ }
|
|
|
|
|
+ PeopleEntity _people = (PeopleEntity) BasicUtil.getSession(SessionConstEnum.PEOPLE_EXISTS_SESSION);
|
|
|
|
|
+ if (_people == null) {
|
|
|
|
|
+ // 用户不存在
|
|
|
|
|
+ return ResultData.build().error(
|
|
|
|
|
+ this.getResString("err.not.exist", this.getResString("people")));
|
|
|
|
|
+ }
|
|
|
|
|
+ LOG.debug(_people.getPeoplePhoneCheck() + ":" + PeopleEnum.PHONE_CHECK.toInt());
|
|
|
|
|
+ LOG.debug(_people.getPeopleCode() + ":" + people.getPeopleCode());
|
|
|
|
|
+ // 判断用户验证是否通过\判断用户输入对邮箱验证码是否与系统发送对一致\判断验证码对有效时间
|
|
|
|
|
+ if (_people.getPeoplePhoneCheck() == PeopleEnum.PHONE_CHECK.toInt()
|
|
|
|
|
+ && _people.getPeopleCode().equals(people.getPeopleCode())) {
|
|
|
|
|
+ BasicUtil.setSession(SessionConstEnum.PEOPLE_RESET_PASSWORD_SESSION, _people);
|
|
|
|
|
+ return ResultData.build().success(
|
|
|
|
|
+ this.getResString("success", this.getResString("people.get.password")));
|
|
|
|
|
+ } else if (_people.getPeopleMailCheck() == PeopleEnum.MAIL_CHECK.toInt()
|
|
|
|
|
+ && _people.getPeopleCode().equals(people.getPeopleCode())) {
|
|
|
|
|
+ BasicUtil.setSession(SessionConstEnum.PEOPLE_RESET_PASSWORD_SESSION, _people);
|
|
|
|
|
+ return ResultData.build().success(
|
|
|
|
|
+ this.getResString("success", this.getResString("people.get.password")));
|
|
|
|
|
+ } else {
|
|
|
|
|
+ return ResultData.build().error(
|
|
|
|
|
+ this.getResString("fail", this.getResString("people.get.password")));
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Operation(summary = "用户名、邮箱、手机号验证 ,用户重置密码必须使用该接口,适用场景:1、用户注册是对用户名、邮箱或手机号唯一性判断 2、用户取回密码是判断账号是否存在")
|
|
|
|
|
+ @Parameters({
|
|
|
|
|
+ @Parameter(name = "peoplePhone", description = "用户电话", required = true, in = ParameterIn.QUERY),
|
|
|
|
|
+ @Parameter(name = "peopleMail", description = "用户邮箱", required = true, in = ParameterIn.QUERY),
|
|
|
|
|
+ @Parameter(name = "peopleName", description = "登录帐号", required = true, in = ParameterIn.QUERY),
|
|
|
|
|
+ })
|
|
|
|
|
+ @PostMapping(value = "/isExists")
|
|
|
|
|
+ @ResponseBody
|
|
|
|
|
+ public ResultData isExists(@ModelAttribute @Parameter(hidden = true) PeopleEntity people, HttpServletRequest request,
|
|
|
|
|
+ HttpServletResponse response) {
|
|
|
|
|
+ LOG.debug(JSONUtil.toJsonStr(people));
|
|
|
|
|
+ if (StringUtils.isBlank(people.getPeopleName()) && StringUtils.isBlank(people.getPeoplePhone())
|
|
|
|
|
+ && StringUtils.isBlank(people.getPeopleMail())) {
|
|
|
|
|
+ return ResultData.build().error(
|
|
|
|
|
+ this.getResString("err.empty", this.getResString("people.name")));
|
|
|
|
|
+ }
|
|
|
|
|
+ // 如果接收到mail值,就给mail_check赋值1
|
|
|
|
|
+ if (!StringUtils.isBlank(people.getPeopleMail())) {
|
|
|
|
|
+ people.setPeopleMailCheck(PeopleEnum.MAIL_CHECK);
|
|
|
|
|
+ }
|
|
|
|
|
+ // 如果接收到phone值,就给phone_check赋值1
|
|
|
|
|
+ if (!StringUtils.isBlank(people.getPeoplePhone())) {
|
|
|
|
|
+ people.setPeoplePhoneCheck(PeopleEnum.PHONE_CHECK);
|
|
|
|
|
+ }
|
|
|
|
|
+ PeopleEntity _people = (PeopleEntity) this.peopleBiz.getEntity(people);
|
|
|
|
|
+ if (_people != null) {
|
|
|
|
|
+ BasicUtil.setSession(SessionConstEnum.PEOPLE_EXISTS_SESSION, _people);
|
|
|
|
|
+ return ResultData.build().success();
|
|
|
|
|
+ }
|
|
|
|
|
+ return ResultData.build().error();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Operation(summary = "微信-用户注册")
|
|
|
|
|
+ @Parameters({
|
|
|
|
|
+ @Parameter(name = "peoplePassword", description = "登录密码", required = true, in = ParameterIn.QUERY),
|
|
|
|
|
+ @Parameter(name = "peopleCode", description = "用户随机验证码", required = true, in = ParameterIn.QUERY),
|
|
|
|
|
+ @Parameter(name = "peoplePhone", description = "用户电话", required = false, in = ParameterIn.QUERY),
|
|
|
|
|
+ @Parameter(name = "peopleMail", description = "用户邮箱", required = false, in = ParameterIn.QUERY),
|
|
|
|
|
+ @Parameter(name = "peopleName", description = "登录帐号", required = false, in = ParameterIn.QUERY),
|
|
|
|
|
+ })
|
|
|
|
|
+ @PostMapping(value = "/wx_register")
|
|
|
|
|
+ @ResponseBody
|
|
|
|
|
+ public ResultData wxRegister(@RequestBody PeopleBean people, HttpServletRequest request,
|
|
|
|
|
+ HttpServletResponse response) {
|
|
|
|
|
+ people.setPeoplePassword(RandomUtil.randomString(8));
|
|
|
|
|
+ ResultData register = register(people, request, response);
|
|
|
|
|
+ if (register.isSuccess()) {
|
|
|
|
|
+ return executeLogin(people.getPeopleName(),request,response);
|
|
|
|
|
+ }
|
|
|
|
|
+ return register;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private ResultData executeLogin(String openid,HttpServletRequest request, HttpServletResponse response) {
|
|
|
|
|
+ Subject subject = SecurityUtils.getSubject();
|
|
|
|
|
+ WxCustomUserNamePasswordToken cupt = new WxCustomUserNamePasswordToken(openid);
|
|
|
|
|
+ try {
|
|
|
|
|
+ LOG.debug("people 尝试登陆");
|
|
|
|
|
+ subject.login(cupt);
|
|
|
|
|
+ LOG.debug("people 登陆成功");
|
|
|
|
|
+ ResultData info = action.info(request, response);
|
|
|
|
|
+ if (info.isSuccess()) {
|
|
|
|
|
+ Map data = info.getData(Map.class);
|
|
|
|
|
+ PeopleBean tempPeople = new PeopleBean();
|
|
|
|
|
+ tempPeople.setId(peopleEntity.getId());
|
|
|
|
|
+ tempPeople.setPeopleName(peopleEntity.getPeopleName());
|
|
|
|
|
+ tempPeople.setPeoplePhone(peopleEntity.getPeoplePhone());
|
|
|
|
|
+ tempPeople.setPuIcon(peopleEntity.getPuIcon());
|
|
|
|
|
+ tempPeople.setPuNickname(peopleEntity.getPuNickname());
|
|
|
|
|
+ return ResultData.build().success(tempPeople);
|
|
|
|
|
+ }
|
|
|
|
|
+ return info;
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ LOG.debug("people 登陆失败");
|
|
|
|
|
+ if (e.getCause() instanceof BusinessException) {
|
|
|
|
|
+ throw (BusinessException) e.getCause();
|
|
|
|
|
+ }
|
|
|
|
|
+ e.printStackTrace();
|
|
|
|
|
+ }
|
|
|
|
|
+ return ResultData.build().error(
|
|
|
|
|
+ this.getResString("err.error", this.getResString("people.no.exist")));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Operation(summary = "用户注册,用户可以根据用名称、手机号、邮箱进行注册")
|
|
|
|
|
+ @Parameters({
|
|
|
|
|
+ @Parameter(name = "peoplePassword", description = "登录密码", required = true, in = ParameterIn.QUERY),
|
|
|
|
|
+ @Parameter(name = "peopleCode", description = "用户随机验证码", required = true, in = ParameterIn.QUERY),
|
|
|
|
|
+ @Parameter(name = "peoplePhone", description = "用户电话", required = false, in = ParameterIn.QUERY),
|
|
|
|
|
+ @Parameter(name = "peopleMail", description = "用户邮箱", required = false, in = ParameterIn.QUERY),
|
|
|
|
|
+ @Parameter(name = "peopleName", description = "登录帐号", required = false, in = ParameterIn.QUERY),
|
|
|
|
|
+ })
|
|
|
|
|
+ @PostMapping(value = "/register")
|
|
|
|
|
+ @ResponseBody
|
|
|
|
|
+ public ResultData register(@ModelAttribute @Parameter(hidden = true) PeopleBean people, HttpServletRequest request,
|
|
|
|
|
+ HttpServletResponse response) {
|
|
|
|
|
+ LOG.debug("people register");
|
|
|
|
|
+ // 验证码验证 验证码不为null 或 验证码不相等
|
|
|
|
|
+ if (!checkRandCode()) {
|
|
|
|
|
+ return ResultData.build().error(this.getResString("err.error", this.getResString("rand.code")));
|
|
|
|
|
+ }
|
|
|
|
|
+ // 是否开启了注册功能
|
|
|
|
|
+ String switchRegister = ConfigUtil.getString("会员配置", "enableReg");
|
|
|
|
|
+ if ("false".equalsIgnoreCase(switchRegister)) {
|
|
|
|
|
+ return ResultData.build().error("注册功能已被关闭!");
|
|
|
|
|
+ }
|
|
|
|
|
+ // 判断用户信息是否为空
|
|
|
|
|
+ if (people == null) {
|
|
|
|
|
+ return ResultData.build().error(
|
|
|
|
|
+ this.getResString("err.empty", this.getResString("people")));
|
|
|
|
|
+ }
|
|
|
|
|
+ // 要验证用户名是否为空
|
|
|
|
|
+ if (StringUtils.isBlank(people.getPeopleName())) {
|
|
|
|
|
+ return ResultData.build().error(
|
|
|
|
|
+ this.getResString("err.empty", this.getResString("people.name")));
|
|
|
|
|
+ } else if (!StringUtils.isBlank(people.getPeopleName())) {
|
|
|
|
|
+ // 如果用户名不为空表示使用的是账号注册方式
|
|
|
|
|
+ if (people.getPeopleName().contains(" ")) {
|
|
|
|
|
+ return ResultData.build().error(
|
|
|
|
|
+ this.getResString("people.name") + this.getResString("people.space"));
|
|
|
|
|
+ }
|
|
|
|
|
+ if (!StringUtil.checkLength(people.getPeopleName(), 3, 30)) {
|
|
|
|
|
+ return ResultData.build().error(
|
|
|
|
|
+ this.getResString("err.length", this.getResString("people.name"), "3", "30"));
|
|
|
|
|
+ }
|
|
|
|
|
+ // 判断用户名是否已经被注册
|
|
|
|
|
+ PeopleEntity peopleName = this.peopleBiz.getEntityByUserName(people.getPeopleName());
|
|
|
|
|
+ if (peopleName != null) {
|
|
|
|
|
+ return ResultData.build().error(
|
|
|
|
|
+ this.getResString("err.exist", this.getResString("people.name")));
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ String sendCode = ConfigUtil.getString("会员配置", "sendCode");
|
|
|
|
|
+ if ("true".equalsIgnoreCase(sendCode)) {// 验证手机号
|
|
|
|
|
+ if (StringUtils.isBlank(people.getPeoplePhone())) {
|
|
|
|
|
+ return ResultData.build().error(
|
|
|
|
|
+ this.getResString("err.empty", this.getResString("people.phone")));
|
|
|
|
|
+ }
|
|
|
|
|
+ PeopleEntity peoplePhone = this.peopleBiz.getEntityByUserName(people.getPeoplePhone());
|
|
|
|
|
+ if (peoplePhone != null && peoplePhone.getPeoplePhoneCheck() == PeopleEnum.PHONE_CHECK.toInt()) { // 已存在
|
|
|
|
|
+ return ResultData.build().error(
|
|
|
|
|
+ this.getResString("err.exist", this.getResString("people.phone")));
|
|
|
|
|
+ } else {
|
|
|
|
|
+ Object obj = BasicUtil.getSession(SessionConstEnum.SEND_CODE_SESSION);
|
|
|
|
|
+ if (obj != null) {
|
|
|
|
|
+ PeopleEntity _people = (PeopleEntity) obj;
|
|
|
|
|
+ if (_people.getPeoplePhone().equals(people.getPeoplePhone())) {
|
|
|
|
|
+ if (_people.getPeopleCode().equals(people.getPeopleCode())) {
|
|
|
|
|
+ people.setPeoplePhoneCheck(PeopleEnum.PHONE_CHECK);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ return ResultData.build().error(
|
|
|
|
|
+ this.getResString("err.error", this.getResString("people.phone.code")));
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ if ("true".equalsIgnoreCase(sendCode)) {// 验证邮箱
|
|
|
|
|
+ if (StringUtils.isBlank(people.getPeoplePhone())) {
|
|
|
|
|
+ return ResultData.build().error(
|
|
|
|
|
+ this.getResString("err.empty", this.getResString("people.mail")));
|
|
|
|
|
+ }
|
|
|
|
|
+ // 检查邮箱格式是否含有空格
|
|
|
|
|
+ if (people.getPeopleMail().contains(" ")) {
|
|
|
|
|
+ return ResultData.build().error(
|
|
|
|
|
+ this.getResString("people.mail") + this.getResString("people.space"));
|
|
|
|
|
+ }
|
|
|
|
|
+ PeopleEntity peopleMail = this.peopleBiz.getEntityByUserName(people.getPeopleMail());
|
|
|
|
|
+ if (peopleMail != null && peopleMail.getPeopleMailCheck() == PeopleEnum.MAIL_CHECK.toInt()) {
|
|
|
|
|
+ return ResultData.build().error(
|
|
|
|
|
+ this.getResString("err.exist", this.getResString("people.mail")));
|
|
|
|
|
+ } else {
|
|
|
|
|
+ Object obj = BasicUtil.getSession(SessionConstEnum.SEND_CODE_SESSION);
|
|
|
|
|
+ if (obj != null) {
|
|
|
|
|
+ PeopleEntity _people = (PeopleEntity) obj;
|
|
|
|
|
+ if (_people.getPeopleMail().equals(people.getPeopleMail())) {
|
|
|
|
|
+ if (_people.getPeopleCode().equals(people.getPeopleCode())) {
|
|
|
|
|
+ people.setPeopleMailCheck(PeopleEnum.MAIL_CHECK);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ return ResultData.build().error(
|
|
|
|
|
+ this.getResString("err.error", this.getResString("people.mail")));
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ } else {
|
|
|
|
|
+ return ResultData.build().error(
|
|
|
|
|
+ this.getResString("err.error", this.getResString("people.mail.code")));
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ // 密码
|
|
|
|
|
+ if (StringUtils.isBlank(people.getPeoplePassword())) {
|
|
|
|
|
+ return ResultData.build().error(
|
|
|
|
|
+ this.getResString("err.empty", this.getResString("people.password")));
|
|
|
|
|
+ }
|
|
|
|
|
+ if (people.getPeoplePassword().contains(" ")) {
|
|
|
|
|
+ return ResultData.build().error(
|
|
|
|
|
+ this.getResString("people.password") + this.getResString("people.space"));
|
|
|
|
|
+ }
|
|
|
|
|
+ if (people.getPeoplePassword().length() < 6 || people.getPeoplePassword().length() > 30) {
|
|
|
|
|
+ return ResultData.build().error(
|
|
|
|
|
+ this.getResString("err.length", this.getResString("people.password"), "6", "30"));
|
|
|
|
|
+ }
|
|
|
|
|
+ // 如果用户未设置昵称,则昵称默认为用户名
|
|
|
|
|
+ if (StringUtils.isBlank(people.getPuNickname())) {
|
|
|
|
|
+ people.setPuNickname(people.getPeopleName());
|
|
|
|
|
+ }
|
|
|
|
|
+ // 将密码使用MD5加密
|
|
|
|
|
+ people.setPeoplePassword(SecureUtil.md5(people.getPeoplePassword()));
|
|
|
|
|
+ // 是否开启审核
|
|
|
|
|
+ String state = ConfigUtil.getString("会员配置", "peopleState");
|
|
|
|
|
+ if ("false".equals(state)) {
|
|
|
|
|
+ people.setPeopleState(1); // 审核默认值
|
|
|
|
|
+ } else {
|
|
|
|
|
+ people.setPeopleState(0);
|
|
|
|
|
+ }
|
|
|
|
|
+ people.setPeopleDateTime(new Date());
|
|
|
|
|
+ peopleBiz.savePeople(people);
|
|
|
|
|
+ LOG.debug("people register ok");
|
|
|
|
|
+ return ResultData.build().success();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Operation(summary = "用户重置密码")
|
|
|
|
|
+ @Parameters({
|
|
|
|
|
+ @Parameter(name = "peoplePassword", description = "登录密码", required = true, in = ParameterIn.QUERY),
|
|
|
|
|
+ @Parameter(name = "rand_code", description = "验证码", required = true, in = ParameterIn.QUERY),
|
|
|
|
|
+ @Parameter(name = "peopleCode", description = "用户随机验证码", required = true, in = ParameterIn.QUERY),
|
|
|
|
|
+ })
|
|
|
|
|
+ @PostMapping(value = "/resetPassword")
|
|
|
|
|
+ @ResponseBody
|
|
|
|
|
+ @PeopleLogAnn(title = "重置密码", businessType = PeopleLogTypeEnum.UPDATE)
|
|
|
|
|
+ public ResultData resetPassword(@ModelAttribute @Parameter(hidden = true) PeopleEntity people, HttpServletRequest request,
|
|
|
|
|
+ HttpServletResponse response) {
|
|
|
|
|
+ // 验证码验证 验证码不为null 或 验证码不相等
|
|
|
|
|
+ if (StringUtils.isBlank(this.getRandCode()) || !this.checkRandCode()) {
|
|
|
|
|
+ return ResultData.build().error(this.getResString("err.error", this.getResString("rand.code")));
|
|
|
|
|
+ }
|
|
|
|
|
+ // 验证新密码的长度
|
|
|
|
|
+ if (!StringUtil.checkLength(people.getPeoplePassword(), 3, 12)) {
|
|
|
|
|
+ return ResultData.build().error(
|
|
|
|
|
+ this.getResString("err.error", this.getResString("people.password")));
|
|
|
|
|
+ }
|
|
|
|
|
+ PeopleEntity _people = (PeopleEntity) BasicUtil.getSession(SessionConstEnum.PEOPLE_RESET_PASSWORD_SESSION);
|
|
|
|
|
+ if (_people == null) {
|
|
|
|
|
+ // 用户不存在
|
|
|
|
|
+ return ResultData.build().error(
|
|
|
|
|
+ this.getResString("err.not.exist", this.getResString("people")));
|
|
|
|
|
+ }
|
|
|
|
|
+ // 判断用户验证是否通过\判断用户输入对邮箱验证码是否与系统发送对一致\判断验证码对有效时间
|
|
|
|
|
+ if (_people.getPeoplePhoneCheck() == PeopleEnum.PHONE_CHECK.toInt()
|
|
|
|
|
+ && _people.getPeopleCode().equals(people.getPeopleCode())) {
|
|
|
|
|
+ _people.setPeoplePassword(SecureUtil.md5(people.getPeoplePassword()));
|
|
|
|
|
+ peopleBiz.updateEntity(_people);
|
|
|
|
|
+ LOG.debug("更新密码成功");
|
|
|
|
|
+ return ResultData.build().success(
|
|
|
|
|
+ this.getResString("success", this.getResString("people.get.password")));
|
|
|
|
|
+ } else if (_people.getPeopleMailCheck() == PeopleEnum.MAIL_CHECK.toInt()
|
|
|
|
|
+ && _people.getPeopleCode().equals(people.getPeopleCode())) {
|
|
|
|
|
+ _people.setPeoplePassword(SecureUtil.md5(people.getPeoplePassword()));
|
|
|
|
|
+ peopleBiz.updateEntity(_people);
|
|
|
|
|
+ LOG.debug("更新密码成功");
|
|
|
|
|
+ return ResultData.build().success(
|
|
|
|
|
+ this.getResString("success", this.getResString("people.get.password")));
|
|
|
|
|
+ } else {
|
|
|
|
|
+ LOG.debug("更新密码失败");
|
|
|
|
|
+ return ResultData.build().error(
|
|
|
|
|
+ this.getResString("fail", this.getResString("people.get.password")));
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Operation(summary = "用户发送验证码,可以通过邮箱或手机发送")
|
|
|
|
|
+ @Parameters({
|
|
|
|
|
+ @Parameter(name = "receive", description = "接收地址,只能是邮箱或手机号,邮箱需要使用邮箱插件,手机号需要短信插件", required = true, in = ParameterIn.QUERY),
|
|
|
|
|
+ @Parameter(name = "modelCode", description = "对应邮件插件的模块编号", required = true, in = ParameterIn.QUERY),
|
|
|
|
|
+ @Parameter(name = "configType", description = "配置类型,如邮件配置", required = true, in = ParameterIn.QUERY),
|
|
|
|
|
+ @Parameter(name = "isSession", description = "true启用session保存code,false 关联用户信息,true一般是当用户手机还不存在系统中时使用,", required = true, in = ParameterIn.QUERY),
|
|
|
|
|
+ @Parameter(name = "peoplePhone", description = "用户电话", required = false, in = ParameterIn.QUERY),
|
|
|
|
|
+ @Parameter(name = "peopleMail", description = "用户邮箱", required = false, in = ParameterIn.QUERY),
|
|
|
|
|
+ @Parameter(name = "peopleName", description = "登录帐号", required = false, in = ParameterIn.QUERY),
|
|
|
|
|
+ })
|
|
|
|
|
+ @SuppressWarnings({"rawtypes", "unchecked"})
|
|
|
|
|
+ @PostMapping(value = "/sendCode")
|
|
|
|
|
+ @ResponseBody
|
|
|
|
|
+ public ResultData sendCode(@ModelAttribute @Parameter(hidden = true) PeopleEntity people, HttpServletRequest request,
|
|
|
|
|
+ HttpServletResponse response) {
|
|
|
|
|
+ if (!this.checkRandCode()) {
|
|
|
|
|
+ return ResultData.build().error(
|
|
|
|
|
+ this.getResString("err.error", this.getResString("rand.code")));
|
|
|
|
|
+ }
|
|
|
|
|
+ String receive = request.getParameter("receive");
|
|
|
|
|
+ String modelCode = request.getParameter("modelCode");
|
|
|
|
|
+ String configType = request.getParameter("configType");
|
|
|
|
|
+ boolean isSession = BasicUtil.getBoolean("isSession");
|
|
|
|
|
+ if (StringUtils.isBlank(receive)) {
|
|
|
|
|
+ return ResultData.build().error(this.getResString("err.empty", this.getResString("receive")));
|
|
|
|
|
+ }
|
|
|
|
|
+ if (StringUtils.isBlank(modelCode)) {
|
|
|
|
|
+ return ResultData.build().error(this.getResString("err.empty", "modelCode"));
|
|
|
|
|
+ }
|
|
|
|
|
+ if (StringUtils.isBlank(configType)) {
|
|
|
|
|
+ return ResultData.build().error(this.getResString("err.empty", this.getResString("type")));
|
|
|
|
|
+ }
|
|
|
|
|
+ // 获取应用ID
|
|
|
|
|
+ String peopleCode = StringUtil.randomNumber(6);
|
|
|
|
|
+ // 解密得到的模块编码
|
|
|
|
|
+ long time = new Date().getTime();
|
|
|
|
|
+ BasicUtil.setSession("tokenSession", time);
|
|
|
|
|
+ MultiValueMap<String, Object> requestBody = new LinkedMultiValueMap<>();
|
|
|
|
|
+ requestBody.add("modelCode", modelCode);
|
|
|
|
|
+ requestBody.add("receive", receive);
|
|
|
|
|
+ requestBody.add("tokenSession", time);
|
|
|
|
|
+ requestBody.add("configType", configType);
|
|
|
|
|
+ Map map = new HashMap();
|
|
|
|
|
+ map.put("code", peopleCode);
|
|
|
|
|
+ requestBody.add("content", JSONUtil.toJsonStr(map));
|
|
|
|
|
+ this.LOG.debug("验证码:{}", peopleCode);
|
|
|
|
|
+ if (isSession) { // 启用session
|
|
|
|
|
+ Object obj = BasicUtil.getSession(SessionConstEnum.SEND_CODE_SESSION);
|
|
|
|
|
+ if (obj != null) {
|
|
|
|
|
+ PeopleEntity p = (PeopleEntity) obj;
|
|
|
|
|
+ if (DateUtil.betweenMs(new Date(), (Date) p.getPeopleCodeSendDate()) == 60) {
|
|
|
|
|
+ return ResultData.build().error(this.getResString("people.code.time.error"));
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ PeopleEntity _people = new PeopleEntity();
|
|
|
|
|
+ _people.setPeopleCode(peopleCode);
|
|
|
|
|
+ _people.setPeopleCodeSendDate(Timestamp.valueOf(DateUtil.now()));
|
|
|
|
|
+ _people.setPeopleMail(receive);
|
|
|
|
|
+ _people.setPeoplePhone(receive);
|
|
|
|
|
+ BasicUtil.setSession(SessionConstEnum.SEND_CODE_SESSION, _people);
|
|
|
|
|
+ // 调用发送插件,由于不能直接依赖发送插件,所以只能通过reset接口的方式
|
|
|
|
|
+ ResponseEntity<JSONObject> content = RestTemplateUtil.post(this.getUrl(request) + "/msend/send.do", RestTemplateUtil.getHeaders(request), requestBody, JSONObject.class);
|
|
|
|
|
+ LOG.debug("send " + receive + ":content " + peopleCode);
|
|
|
|
|
+ return ResultData.build().success(JSONUtil.toJsonStr(content));
|
|
|
|
|
+ }
|
|
|
|
|
+ // 给people赋值(邮箱或电话)
|
|
|
|
|
+ if (StringUtil.isMobile(receive)) {
|
|
|
|
|
+ people.setPeoplePhone(receive);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ people.setPeopleMail(receive);
|
|
|
|
|
+ }
|
|
|
|
|
+ // 判断是否接到用户名,应用于找回密码发送验证码
|
|
|
|
|
+ PeopleEntity peopleSession = null;
|
|
|
|
|
+ try {
|
|
|
|
|
+ peopleSession = this.getPeopleBySession();
|
|
|
|
|
+ } catch (UnauthorizedException e) {
|
|
|
|
|
+ LOG.debug("当前用户未登录");
|
|
|
|
|
+ }
|
|
|
|
|
+ if (StringUtils.isBlank(people.getPeopleName()) && peopleSession == null) {
|
|
|
|
|
+ // 如果接收到mail值,就给mail_check赋值1
|
|
|
|
|
+ if (!StringUtils.isBlank(people.getPeopleMail())) {
|
|
|
|
|
+ people.setPeopleMailCheck(PeopleEnum.MAIL_CHECK);
|
|
|
|
|
+ }
|
|
|
|
|
+ // 如果接收到phone值,就给phone_check赋值1
|
|
|
|
|
+ if (!StringUtils.isBlank(people.getPeoplePhone())) {
|
|
|
|
|
+ people.setPeoplePhoneCheck(PeopleEnum.PHONE_CHECK);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ // 通过用户名地址和应用id得到用户实体
|
|
|
|
|
+ PeopleEntity peopleEntity = (PeopleEntity) this.peopleBiz.getEntity(people);
|
|
|
|
|
+ if (peopleEntity == null) {
|
|
|
|
|
+ return ResultData.build().error(
|
|
|
|
|
+ this.getResString("err.not.exist", this.getResString("people")));
|
|
|
|
|
+ }
|
|
|
|
|
+ if (peopleEntity.getPeopleUser() != null) {
|
|
|
|
|
+ Map _map = new HashMap();
|
|
|
|
|
+ _map.put("code", peopleCode);
|
|
|
|
|
+ _map.put("userName", peopleEntity.getPeopleUser().getPuNickname());
|
|
|
|
|
+ requestBody.remove("content");
|
|
|
|
|
+ requestBody.add("content", JSONUtil.toJsonStr(_map));
|
|
|
|
|
+ }
|
|
|
|
|
+ // 将生成的验证码加入用户实体
|
|
|
|
|
+ peopleEntity.setPeopleCode(peopleCode);
|
|
|
|
|
+ // 将当前时间转换为时间戳格式保存进people表
|
|
|
|
|
+ peopleEntity.setPeopleCodeSendDate(Timestamp.valueOf(DateUtil.now()));
|
|
|
|
|
+ // 更新该实体
|
|
|
|
|
+ this.peopleBiz.updateEntity(peopleEntity);
|
|
|
|
|
+ PeopleEntity _people = (PeopleEntity) BasicUtil.getSession(SessionConstEnum.PEOPLE_EXISTS_SESSION);
|
|
|
|
|
+ if (_people != null) {
|
|
|
|
|
+ BasicUtil.setSession(SessionConstEnum.PEOPLE_EXISTS_SESSION, peopleEntity);
|
|
|
|
|
+ }
|
|
|
|
|
+ // 调用发送插件,由于不能直接依赖发送插件,所以只能通过reset接口的方式
|
|
|
|
|
+ ResponseEntity<JSONObject> content = RestTemplateUtil.post(this.getUrl(request) + "/msend/send.do", RestTemplateUtil.getHeaders(request), requestBody, JSONObject.class);
|
|
|
|
|
+ LOG.debug("content :" + content);
|
|
|
|
|
+ if (content.getBody().getBool("result")) {
|
|
|
|
|
+ LOG.debug("send " + receive + ":content " + peopleCode);
|
|
|
|
|
+ return ResultData.build().success();
|
|
|
|
|
+ } else {
|
|
|
|
|
+ return ResultData.build().error(content.getBody().getStr("msg"));
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Operation(summary = "验证用户输入的接收验证码")
|
|
|
|
|
+ @Parameters({
|
|
|
|
|
+ @Parameter(name = "receive", description = "接收地址,只能是邮箱或手机号,邮箱需要使用邮箱插件,手机号需要短信插件", required = true, in = ParameterIn.QUERY),
|
|
|
|
|
+ @Parameter(name = "code", description = "接收到的验证码", required = true, in = ParameterIn.QUERY),
|
|
|
|
|
+ })
|
|
|
|
|
+ @PostMapping(value = "/checkSendCode")
|
|
|
|
|
+ @ResponseBody
|
|
|
|
|
+ public ResultData checkSendCode(@ModelAttribute @Parameter(hidden = true) PeopleEntity people, HttpServletRequest request,
|
|
|
|
|
+ HttpServletResponse response) {
|
|
|
|
|
+ String code = request.getParameter("code");
|
|
|
|
|
+ String receive = request.getParameter("receive");
|
|
|
|
|
+ Boolean isMobile = Validator.isMobile(receive);
|
|
|
|
|
+ Boolean isEmail = Validator.isEmail(receive);
|
|
|
|
|
+ if (isMobile) {
|
|
|
|
|
+ // 手机验证码
|
|
|
|
|
+ if (StringUtils.isBlank(code)) {
|
|
|
|
|
+ return ResultData.build().error(
|
|
|
|
|
+ this.getResString("err.error", this.getResString("people.phone.code")));
|
|
|
|
|
+ }
|
|
|
|
|
+ people.setPeoplePhone(receive);
|
|
|
|
|
+ }
|
|
|
|
|
+ // 跳过邮箱验证码验证
|
|
|
|
|
+ if (isEmail) {
|
|
|
|
|
+ // 邮箱验证码
|
|
|
|
|
+ if (StringUtils.isBlank(code)) {
|
|
|
|
|
+ return ResultData.build().error(
|
|
|
|
|
+ this.getResString("err.error", this.getResString("people.mail.code")));
|
|
|
|
|
+ }
|
|
|
|
|
+ people.setPeopleMail(receive);
|
|
|
|
|
+ }
|
|
|
|
|
+ // 根据邮箱地址查找用户实体
|
|
|
|
|
+ PeopleEntity peopleEntity = (PeopleEntity) this.peopleBiz.getEntity(people);
|
|
|
|
|
+ // 在注册流程,在发送验证码的时候数据库可能还不存在用户信息
|
|
|
|
|
+ if (BasicUtil.getSession(SessionConstEnum.SEND_CODE_SESSION) != null) {
|
|
|
|
|
+ peopleEntity = (PeopleEntity) BasicUtil.getSession(SessionConstEnum.SEND_CODE_SESSION);
|
|
|
|
|
+ // 判断用户输入的随机码是否正确
|
|
|
|
|
+ if (!peopleEntity.getPeopleCode().equals(code)) {
|
|
|
|
|
+ if (isMobile) {
|
|
|
|
|
+ return ResultData.build().error(
|
|
|
|
|
+ this.getResString("err.error", this.getResString("people.phone.code")));
|
|
|
|
|
+ } else {
|
|
|
|
|
+ // 邮箱验证
|
|
|
|
|
+ return ResultData.build().error(
|
|
|
|
|
+ this.getResString("err.error", this.getResString("people.mail.code")));
|
|
|
|
|
+ }
|
|
|
|
|
+ } else {
|
|
|
|
|
+ return ResultData.build().success();
|
|
|
|
|
+ }
|
|
|
|
|
+ } else {
|
|
|
|
|
+ if (isMobile) {
|
|
|
|
|
+ // 如果用户已经绑定过手机直接返回错误
|
|
|
|
|
+ if (peopleEntity == null || peopleEntity.getPeoplePhoneCheck() == PeopleEnum.PHONE_CHECK.toInt()) {
|
|
|
|
|
+ return ResultData.build().error(this.getResString("err.error", this.getResString("people.phone.code")));
|
|
|
|
|
+ }
|
|
|
|
|
+ } else {
|
|
|
|
|
+ // 如果用户已经绑定过邮箱直接返回错误
|
|
|
|
|
+ if (peopleEntity == null || peopleEntity.getPeopleMailCheck() == PeopleEnum.MAIL_CHECK.toInt()) {
|
|
|
|
|
+ return ResultData.build().error(this.getResString("err.error", this.getResString("people.mail.code")));
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ // 得到发送验证码时间,并转换为String类型
|
|
|
|
|
+ String date = peopleEntity.getPeopleCodeSendDate().toString();
|
|
|
|
|
+ // 如果发送时间和当前时间只差大于30分钟,则返回false
|
|
|
|
|
+ if (DateUtil.betweenMs(new Date(), DateUtil.parse(date)) > 60 * 60 * 24) {
|
|
|
|
|
+ return ResultData.build().error(getResString("overdue", getResString("rand.code")));
|
|
|
|
|
+ }
|
|
|
|
|
+ // 判断用户输入的随机码是否正确
|
|
|
|
|
+ if (!peopleEntity.getPeopleCode().equals(code)) {
|
|
|
|
|
+ if (isMobile) {
|
|
|
|
|
+ return ResultData.build().error(
|
|
|
|
|
+ this.getResString("err.error", this.getResString("people.phone.code")));
|
|
|
|
|
+ } else {
|
|
|
|
|
+ return ResultData.build().error(
|
|
|
|
|
+ this.getResString("err.error", this.getResString("people.mail.code")));
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ // 将随机码在数据库中清空
|
|
|
|
|
+ peopleEntity.setPeopleCode("");
|
|
|
|
|
+ if (StringUtil.isMobile(receive)) {
|
|
|
|
|
+ peopleEntity.setPeoplePhoneCheck(PeopleEnum.PHONE_CHECK);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ peopleEntity.setPeopleMailCheck(PeopleEnum.MAIL_CHECK);
|
|
|
|
|
+ }
|
|
|
|
|
+ peopleBiz.updateEntity(peopleEntity);
|
|
|
|
|
+ return ResultData.build().success();
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Operation(summary = "解绑邮箱-> 验证用户输入的接收验证码")
|
|
|
|
|
+ @Parameters({
|
|
|
|
|
+ @Parameter(name = "code", description = "接收到的验证码", required = true, in = ParameterIn.QUERY),
|
|
|
|
|
+ @Parameter(name = "receive", description = "接收地址,只能是邮箱或手机号,邮箱需要使用邮箱插件,手机号需要短信插件", required = true, in = ParameterIn.QUERY)
|
|
|
|
|
+ })
|
|
|
|
|
+ @PostMapping(value = "/cancelBind")
|
|
|
|
|
+ public ResultData cancelBind(@ModelAttribute @Parameter(hidden = true) PeopleEntity people, HttpServletRequest request,
|
|
|
|
|
+ HttpServletResponse response) {
|
|
|
|
|
+ String code = request.getParameter("code");
|
|
|
|
|
+ String receive = request.getParameter("receive");
|
|
|
|
|
+ Boolean isMobile = Validator.isMobile(receive);
|
|
|
|
|
+ Boolean isEmail = Validator.isEmail(receive);
|
|
|
|
|
+ if (isMobile) {
|
|
|
|
|
+ // 验证码
|
|
|
|
|
+ if (StringUtils.isBlank(code)) {
|
|
|
|
|
+ return ResultData.build().error(
|
|
|
|
|
+ this.getResString("err.error", this.getResString("people.phone.code")));
|
|
|
|
|
+ }
|
|
|
|
|
+ people.setPeoplePhone(receive);
|
|
|
|
|
+ }
|
|
|
|
|
+ if (isEmail) {
|
|
|
|
|
+ // 验证码
|
|
|
|
|
+ if (StringUtils.isBlank(code)) {
|
|
|
|
|
+ return ResultData.build().error(
|
|
|
|
|
+ this.getResString("err.error", this.getResString("people.mail.code")));
|
|
|
|
|
+ }
|
|
|
|
|
+ people.setPeopleMail(receive);
|
|
|
|
|
+ }
|
|
|
|
|
+ // 根据用户名和邮箱或手机号查找用户实体
|
|
|
|
|
+ PeopleEntity peopleEntity = (PeopleEntity) this.peopleBiz.getEntity(people);
|
|
|
|
|
+ // 在注册流程,在发送验证码的时数据库可能还不存在用户信息
|
|
|
|
|
+ if (BasicUtil.getSession(SessionConstEnum.SEND_CODE_SESSION) != null) {
|
|
|
|
|
+ peopleEntity = (PeopleEntity) BasicUtil.getSession(SessionConstEnum.SEND_CODE_SESSION);
|
|
|
|
|
+ // 判断用户输入的随机码是否正确
|
|
|
|
|
+ if (!peopleEntity.getPeopleCode().equals(code)) {
|
|
|
|
|
+ if (isMobile) {
|
|
|
|
|
+ return ResultData.build().error(
|
|
|
|
|
+ this.getResString("err.error", this.getResString("people.phone.code")));
|
|
|
|
|
+ } else {
|
|
|
|
|
+ return ResultData.build().error(
|
|
|
|
|
+ this.getResString("err.error", this.getResString("people.mail.code")));
|
|
|
|
|
+ }
|
|
|
|
|
+ } else {
|
|
|
|
|
+ return ResultData.build().success();
|
|
|
|
|
+ }
|
|
|
|
|
+ } else {
|
|
|
|
|
+ if (isMobile) {
|
|
|
|
|
+ // 如果用户未绑定过手机直接返回错误
|
|
|
|
|
+ if (peopleEntity.getPeoplePhoneCheck() == PeopleEnum.PHONE_NO_CHECK.toInt()) {
|
|
|
|
|
+ return ResultData.build().error();
|
|
|
|
|
+ }
|
|
|
|
|
+ } else {
|
|
|
|
|
+ // 如果用户未绑定过邮箱直接返回错误
|
|
|
|
|
+ if (peopleEntity.getPeopleMailCheck() == PeopleEnum.MAIL_NO_CHECK.toInt()) {
|
|
|
|
|
+ return ResultData.build().error();
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ // 得到发送验证码时间,并转换为String类型
|
|
|
|
|
+ String date = peopleEntity.getPeopleCodeSendDate().toString();
|
|
|
|
|
+ // 如果发送时间和当前时间只差大于30分钟,则返回false
|
|
|
|
|
+ if (DateUtil.betweenMs(new Date(), DateUtil.parse(date)) > 60 * 60 * 24) {
|
|
|
|
|
+ return ResultData.build().error(getResString("overdue", getResString("rand.code")));
|
|
|
|
|
+ }
|
|
|
|
|
+ // 判断用户输入的随机码是否正确
|
|
|
|
|
+ if (!peopleEntity.getPeopleCode().equals(code)) {
|
|
|
|
|
+ if (isMobile) {
|
|
|
|
|
+ return ResultData.build().error(
|
|
|
|
|
+ this.getResString("err.error", this.getResString("people.phone.code")));
|
|
|
|
|
+ } else {
|
|
|
|
|
+ return ResultData.build().error(
|
|
|
|
|
+ this.getResString("err.error", this.getResString("people.mail.code")));
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ // 将随机码在数据库中清空
|
|
|
|
|
+ peopleEntity.setPeopleCode("");
|
|
|
|
|
+ if (StringUtil.isMobile(receive)) {
|
|
|
|
|
+ peopleEntity.setPeoplePhoneCheck(PeopleEnum.PHONE_NO_CHECK);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ peopleEntity.setPeopleMailCheck(PeopleEnum.MAIL_NO_CHECK);
|
|
|
|
|
+ }
|
|
|
|
|
+ peopleBiz.updateEntity(peopleEntity);
|
|
|
|
|
+ return ResultData.build().success();
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Operation(summary = "安全退出")
|
|
|
|
|
+ @PostMapping(value = "/loginOut")
|
|
|
|
|
+ @ResponseBody
|
|
|
|
|
+ public ResultData loginOut(HttpServletRequest request,
|
|
|
|
|
+ HttpServletResponse response) {
|
|
|
|
|
+ SecurityUtils.getSubject().logout();
|
|
|
|
|
+ return ResultData.build().success();
|
|
|
|
|
+ }
|
|
|
|
|
+}
|