|
- package com.iformall.controller;
-
- import cn.binarywang.wx.miniapp.bean.WxMaJscode2SessionResult;
- import com.alibaba.fastjson.JSON;
- import com.alibaba.fastjson.JSONObject;
- import com.google.code.kaptcha.Producer;
- import com.iformall.annotation.AuthIgnore;
- import com.iformall.annotation.TenantIgnore;
- import com.iformall.common.ErrorCode;
- import com.iformall.common.Result;
- import com.iformall.common.ResultData;
- import com.iformall.domain.po.*;
- import com.iformall.domain.po.sm.InviteCodeInfo;
- import com.iformall.enums.*;
- import com.iformall.service.*;
- import com.iformall.service.cuser.CUserServiceFactory;
- import com.iformall.service.sm.InviteCodeInfoService;
- import com.iformall.service.sm.InviteCodeService;
- import com.iformall.service.sm.UserConsumptionPackageService;
- import com.iformall.service.sm.UserCreateVideoNumService;
- import com.iformall.utils.Constant;
- import com.iformall.utils.IPUtil;
- import com.iformall.utils.PasswordHelper;
- import com.iformall.utils.RedisCacheUtils;
- import io.swagger.annotations.Api;
- import io.swagger.annotations.ApiImplicitParam;
- import io.swagger.annotations.ApiImplicitParams;
- import io.swagger.annotations.ApiOperation;
- import org.apache.commons.io.IOUtils;
- import org.apache.commons.lang3.StringUtils;
- import org.apache.shiro.SecurityUtils;
- import org.slf4j.Logger;
- import org.slf4j.LoggerFactory;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.beans.factory.annotation.Qualifier;
- import org.springframework.data.redis.core.RedisTemplate;
- import org.springframework.web.bind.annotation.*;
- import org.springframework.web.context.request.RequestContextHolder;
- import org.springframework.web.context.request.ServletRequestAttributes;
-
- import javax.imageio.ImageIO;
- import javax.servlet.ServletOutputStream;
- import javax.servlet.http.HttpServletRequest;
- import javax.servlet.http.HttpServletResponse;
- import java.awt.image.BufferedImage;
- import java.io.IOException;
- import java.util.Date;
- import java.util.HashMap;
- import java.util.List;
- import java.util.Map;
-
- @RestController
- @RequestMapping("/api/user")
- @Api(description = "用户登陆相关接口")
- public class WxUserGrantController extends BaseController {
-
- private final Logger logger = LoggerFactory.getLogger(this.getClass());
-
- @Autowired
- private Producer producer;
-
- @Autowired
- @Qualifier("objectCommonRedisTemplate")
- RedisTemplate<String, Object> redisTemplate;
-
- @Autowired
- private WxCUserBasicInfoService wxCUserBasicInfoService;
-
- @Autowired
- private WxMsgValidationcodeService wxMsgValidationcodeService;
-
- @Autowired
- WxLevelConfigService wxLevelConfigService;
-
- @Autowired
- WxCUserTagsService wxCUserTagsService;
-
- @Autowired
- WxAppinfoService wxAppinfoService;
-
- @Autowired
- WxAuthorizerInfoService wxAuthorizerInfoService;
-
- @Autowired
- WxMerchantService wxMerchantService;
-
- @Autowired
- WxCouponOrderService wxCouponOrderService;
-
- @Autowired
- WxCreditHistoryService wxCreditHistoryService;
-
- @Autowired
- WxMallService mallService;
-
- @Autowired
- private QrCodeService qrCodeService;
-
- @Autowired
- private UserCreateVideoNumService userCreateVideoNumService;
-
- @Autowired
- private InviteCodeService inviteCodeService;
-
- @Autowired
- private InviteCodeInfoService inviteCodeInfoService;
-
- @Autowired
- private UserConsumptionPackageService userConsumptionPackageService;
-
- @Autowired
- private WxCUserAuthorityService wxCUserAuthorityService;
-
-
- @AuthIgnore
- @ApiOperation("验证码")
- @GetMapping("/captcha.jpg")
- public void captcha(HttpServletResponse response) {
- logger.debug("[" + getIpAddr() + "] WxUserGrantController::captcha");
- response.setHeader("Cache-Control", "no-store, no-cache");
- response.setContentType("image/jpeg");
-
- //生成文字验证码
- String text = producer.createText();
- //生成图片验证码
- BufferedImage image = producer.createImage(text);
-
- //保存到redis
- String ipAddr = getIpAddr();
- String key = Constant.captchaPrev + ":" + ipAddr;
- RedisCacheUtils.cache(redisTemplate, key, text, 60);
-
- ServletOutputStream out = null;
- try {
- out = response.getOutputStream();
- ImageIO.write(image, "jpg", out);
- } catch (IOException e) {
- e.printStackTrace();
- } finally {
- IOUtils.closeQuietly(out);
- }
- }
-
-
- /**
- * 用户登录
- * 手机号+密码登陆
- *
- * @param map
- * @return
- */
- @AuthIgnore
- @PostMapping("/login")
- @ApiOperation(value = "用户登录", notes = "{\"phone\":\"string\",\"password\":\"string\",\"code\":\"string\"}")
- public ResultData loginByPhone(@RequestBody Map<String, String> map) {
- String ipAddr = getIpAddr();
- logger.debug("[" + ipAddr + "] WxUserGrantController::loginByPhone");
- String code = map.get("code");
- if (StringUtils.isBlank(code)) {
- return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "请输入验证码");
- }
-
- String key = Constant.captchaPrev + ":" + ipAddr;
- String code1 = RedisCacheUtils.getCacheString(redisTemplate, key);
- // if (StringUtils.isBlank(code1)) {
- // return new ResultData(ErrorCode.SYS_PARAMETER_ERROR.getCode(), "验证码已过期");
- // }
- // if (!code1.equals(code)) {
- // return new ResultData(ErrorCode.SYS_PARAMETER_ERROR.getCode(), "验证码不正确");
- // }
-
- String phone = map.get("phone");
- String password = map.get("password");
- if (StringUtils.isBlank(phone) || StringUtils.isBlank(password)) {
- return new ResultData(ErrorCode.SYS_PARAMETER_ERROR.getCode(), "手机号或密码为空");
- }
-
- WxCUserBasicInfo basicInfo = wxCUserBasicInfoService.findInfoByPhone(getTenantInfo(), phone);
- if (basicInfo == null) {
- return new ResultData(ErrorCode.USER_IS_EMPTY);
- }
- if(StringUtils.isBlank(basicInfo.getPassword())){
- return new ResultData(ErrorCode.USER_PASSWD_ERR.getCode(),"该用户未设置密码,请用其他方式登陆");
- }
-
- String encryptPassword = new PasswordHelper().encryptPassword(password);
-
- if (!encryptPassword.equals(basicInfo.getPassword())) {
- return new ResultData(ErrorCode.USER_PASSWD_ERR.getCode(), "手机号或密码错误");
- }
- wxCUserBasicInfoService.handleLoginUser(basicInfo);
- Map resultMap = new HashMap();
- // resultMap.put("phone", basicInfo.getPhone());
- resultMap.put("token", basicInfo.getToken());
- return new ResultData(resultMap);
- }
-
- /**
- * 用户登录
- * 邮箱+密码登陆
- *
- * @param map
- * @return
- */
- @AuthIgnore
- @PostMapping("/loginByEmail")
- @ApiOperation(value = "用户登录", notes = "{\"email\":\"string\",\"password\":\"string\",\"code\":\"string\"}")
- public ResultData loginByEmail(@RequestBody Map<String, String> map) {
- String ipAddr = getIpAddr();
- logger.debug("[" + ipAddr + "] WxUserGrantController::loginByEmail");
- String code = map.get("code");
- if (StringUtils.isBlank(code)) {
- return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "请输入验证码");
- }
-
- String key = Constant.captchaPrev + ":" + ipAddr;
- String code1 = RedisCacheUtils.getCacheString(redisTemplate, key);
- if (StringUtils.isBlank(code1)) {
- return new ResultData(ErrorCode.SYS_PARAMETER_ERROR.getCode(), "验证码已过期");
- }
- if (!code1.equals(code)) {
- return new ResultData(ErrorCode.SYS_PARAMETER_ERROR.getCode(), "验证码不正确");
- }
-
- String email = map.get("email");
- String password = map.get("password");
- if (StringUtils.isBlank(email) || StringUtils.isBlank(password)) {
- return new ResultData(ErrorCode.SYS_PARAMETER_ERROR.getCode(), "邮箱或密码为空");
- }
-
- WxCUserBasicInfo basicInfo = wxCUserBasicInfoService.findInfoByEmail(getTenantInfo(), email);
- if (basicInfo == null) {
- return new ResultData(ErrorCode.USER_IS_EMPTY);
- }
- if (EnumCUserBasicInfoStatus.NOT_ACTIVE.getCode().equals(basicInfo.getStatus())) {
- return new ResultData(ErrorCode.MEMBER_IS_NOT_ACTIVE);
- }
-
- String encryptPassword = new PasswordHelper().encryptPassword(password);
-
- if (!encryptPassword.equals(basicInfo.getPassword())) {
- return new ResultData(ErrorCode.USER_PASSWD_ERR.getCode(), "邮箱或密码错误");
- }
- wxCUserBasicInfoService.handleLoginUser(basicInfo);
- Map resultMap = new HashMap();
- // resultMap.put("phone", basicInfo.getPhone());
- resultMap.put("token", basicInfo.getToken());
- return new ResultData(resultMap);
- }
-
- /**
- * 用户登录
- * 手机+验证码登陆
- *
- * @param map
- * @return
- */
- @AuthIgnore
- @ApiOperation(value = "手机验证码登录", notes = "{\"phone\",\"string\",\"code\",\"string\"}")
- @PostMapping("/doLoginByPhone")
- public ResultData doLoginByPhone(@RequestBody Map<String, String> map, HttpServletResponse response) {
- String ipaddress = getIpAddr();
- logger.debug("[" + ipaddress + "] WxUserGrantController::doLoginByPhone");
- // String phone,String code,String pwd
- String phone = map.get("phone");
- String code = map.get("code");
-
- if (StringUtils.isBlank(phone)) {
- return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "手机号不能为空");
- }
- if (StringUtils.isBlank(code)) {
- return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "验证码不能为空");
- }
-
- // check 验证码正确
- boolean isValidCode = false;
- try {
- isValidCode = wxMsgValidationcodeService.checkCodeValid(phone, code);
- } catch (Exception e) {
- return new ResultData(Result.ERROR, e.getMessage());
- }
- if (isValidCode) {
- WxCUserBasicInfo basicInfo = wxCUserBasicInfoService.findInfoByPhone(getTenantInfo(), phone);
- if (basicInfo == null) {
- basicInfo = wxCUserBasicInfoService.register(getTenantInfo(), phone, null);
- }
- wxCUserBasicInfoService.handleLoginUser(basicInfo);
- Map resultMap = new HashMap();
- // resultMap.put("phone", basicInfo.getPhone());
- resultMap.put("token", basicInfo.getToken());
- return new ResultData(resultMap);
- } else {
- return new ResultData(ErrorCode.MSG_VERIFY_CODE_NOT_FOUND);
- }
- }
-
- /**
- * 获取用户信息
- * @return
- */
- @PostMapping("/getBasicInfo")
- @ApiOperation(value = "用户登录", notes = "")
- public ResultData getBasicInfo() {
- logger.debug("[" + getIpAddr() + "] WxUserGrantController::getBasicInfo");
- WxCUserBasicInfo basicInfo = getCUser();
- basicInfo.setPassword(null);
- basicInfo.setIdCard(null);
- return new ResultData(basicInfo);
- }
-
- @AuthIgnore
- @ApiOperation("发送手机验证码")
- @GetMapping("sendLoginPhoneCode")
- @ApiImplicitParams({
- @ApiImplicitParam(name = "phone", value = "手机号", dataType = "String", paramType = "query", required = true)})
- public ResultData sendLoginPhoneCode(String phone) {
- logger.debug("[" + getIpAddr() + "] WxUserGrantController::sendlogincode");
- if (StringUtils.isBlank(phone)) {
- return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "请输入手机号");
- }
-
- WxMsgValidationcode wxMsgValidationcode = new WxMsgValidationcode();
- wxMsgValidationcode.setPhone(phone);
- wxMsgValidationcode.setType(EnumMsgModel.VALIDATION_CODE.getCode());
- return wxMsgValidationcodeService.sendvalidationcode(wxMsgValidationcode);
- }
-
-
- /**
- * 需要效验用户及图片验证码
- *
- * @param phone
- * @return
- */
- @AuthIgnore
- @ApiOperation("发送修改密码验证码")
- @GetMapping("sendPhoneCode")
- @ApiImplicitParams({
- @ApiImplicitParam(name = "phone", value = "手机号", dataType = "String", paramType = "query", required = true)})
- public ResultData sendPhoneCode(String phone, String code) {
- String ipAddr = getIpAddr();
- logger.debug("[" + ipAddr + "] WxUserGrantController::sendPhoneCode");
- if (StringUtils.isBlank(phone)) {
- return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "请输入手机号");
- }
- if (StringUtils.isBlank(code)) {
- return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "请输入验证码");
- }
-
- String key = Constant.captchaPrev + ":" + ipAddr;
- String code1 = RedisCacheUtils.getCacheString(redisTemplate, key);
- if (StringUtils.isBlank(code1)) {
- return new ResultData(ErrorCode.SYS_PARAMETER_ERROR.getCode(), "验证码已过期");
- }
- if (!code1.equals(code)) {
- return new ResultData(ErrorCode.SYS_PARAMETER_ERROR.getCode(), "验证码不正确");
- }
- WxCUserBasicInfo basicInfo = wxCUserBasicInfoService.findInfoByPhone(getTenantInfo(), phone);
- if (basicInfo == null) {
- return new ResultData(ErrorCode.USER_IS_EMPTY.getCode(), "该手机号未注册");
- }
-
- WxMsgValidationcode wxMsgValidationcode = new WxMsgValidationcode();
- wxMsgValidationcode.setPhone(phone);
- wxMsgValidationcode.setType(EnumMsgModel.VALIDATION_CODE.getCode());
- return wxMsgValidationcodeService.sendvalidationcode(wxMsgValidationcode);
- }
-
-
- @AuthIgnore
- @ApiOperation(value = "手机号注册", notes = "{\"phone\",\"string\",\"code\",\"string\"}")
- @PostMapping("/doRegisterByPhone")
- public ResultData doRegisterByPhone(@RequestBody Map<String, String> params, HttpServletResponse response) {
- String ipaddress = getIpAddr();
- logger.debug("[" + ipaddress + "] WxUserGrantController::doRegisterByPhone");
- // String phone,String code,String pwd
- String phone = params.get("phone");
- String password = params.get("password");
- String code = params.get("code");
-
- if (StringUtils.isBlank(phone)) {
- return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "手机号不能为空");
- }
- if (StringUtils.isBlank(password)) {
- return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "密码不能为空");
- }
- // if (StringUtils.isBlank(code)) {
- // return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "验证码不能为空");
- // }
- WxCUserBasicInfo basicInfo = wxCUserBasicInfoService.findInfoByPhone(getTenantInfo(), phone);
- if (basicInfo != null) {
- return new ResultData(ErrorCode.MEMBER_IS_FOUND);
- }
-
-
- // check 验证码正确
- // boolean isValidCode = false;
- // try {
- // isValidCode = wxMsgValidationcodeService.checkCodeValid(phone,code);
- // } catch (Exception e) {
- // return new ResultData(Result.ERROR, e.getMessage());
- // }
- // if(isValidCode) {
- basicInfo = wxCUserBasicInfoService.register(getTenantInfo(), phone, password);
-
- Boolean aBoolean = userCreateVideoNumService.initializationUserCreateVideoNum(basicInfo.getId());
- if (!aBoolean) {
- return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "初始化创建视频时间表失败");
- }
- return new ResultData();
- // } else {
- // return new ResultData(ErrorCode.MSG_VERIFY_CODE_NOT_FOUND);
- // }
- }
-
- @AuthIgnore
- @ApiOperation(value = "邮箱注册", notes = "{\"email\",\"string\",\"code\",\"string\"}")
- @PostMapping("/doRegisterByEmail")
- public ResultData doRegisterByEmail(@RequestBody Map<String, String> params, HttpServletResponse response) {
- String ipaddress = getIpAddr();
- logger.debug("[" + ipaddress + "] WxUserGrantController::doRegisterByEmail");
- // String name,String username,String password
- String name = params.get("name");
- String email = params.get("email");
- String password = params.get("password");
- String code = params.get("code");
-
- if (StringUtils.isBlank(email)) {
- return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "邮箱不能为空");
- }
- if (StringUtils.isBlank(password)) {
- return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "密码不能为空");
- }
-
- // if (StringUtils.isBlank(code)) {
- // return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "验证码不能为空");
- // }
-
- WxCUserBasicInfo basicInfo = wxCUserBasicInfoService.findInfoByEmail(getTenantInfo(), email);
- if (basicInfo != null) {
- return new ResultData(ErrorCode.MEMBER_IS_FOUND);
- }
-
-
- // check 验证码正确
- // boolean isValidCode = false;
- // try {
- // isValidCode = wxMsgValidationcodeService.checkCodeValid(phone,code);
- // } catch (Exception e) {
- // return new ResultData(Result.ERROR, e.getMessage());
- // }
- // if(isValidCode) {
- basicInfo = wxCUserBasicInfoService.registerEmail(getTenantInfo(), email, password);
-
- Boolean aBoolean = userCreateVideoNumService.initializationUserCreateVideoNum(basicInfo.getId());
- if (!aBoolean) {
- return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "初始化创建视频时间表失败");
- }
- return new ResultData();
- // } else {
- // return new ResultData(ErrorCode.MSG_VERIFY_CODE_NOT_FOUND);
- // }
- }
-
- @AuthIgnore
- @ApiOperation(value = "发送激活邮件", notes = "{\"email\",\"string\",\"code\",\"string\"}")
- @PostMapping("/sendRegisterEmail")
- public ResultData sendRegisterEmail(@RequestBody Map<String, String> params, HttpServletResponse response) {
- String ipaddress = getIpAddr();
- logger.debug("[" + ipaddress + "] WxUserGrantController::sendRegisterEmail");
- // String name,String username,String password
- String email = params.get("email");
- String code = params.get("code");
-
- if (StringUtils.isBlank(email)) {
- return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "邮箱不能为空");
- }
-
- // if (StringUtils.isBlank(code)) {
- // return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "验证码不能为空");
- // }
-
- WxCUserBasicInfo basicInfo = wxCUserBasicInfoService.findInfoByEmail(getTenantInfo(), email);
- if (basicInfo == null) {
- return new ResultData(ErrorCode.USER_IS_EMPTY);
- }
- if (!EnumCUserBasicInfoStatus.NOT_ACTIVE.getCode().equals(basicInfo.getStatus())) {
- return new ResultData(ErrorCode.MEMBER_IS_ACTIVE);
- }
-
-
- // check 验证码正确
- // boolean isValidCode = false;
- // try {
- // isValidCode = wxMsgValidationcodeService.checkCodeValid(phone,code);
- // } catch (Exception e) {
- // return new ResultData(Result.ERROR, e.getMessage());
- // }
- // if(isValidCode) {
- wxCUserBasicInfoService.sendTicketEmail(basicInfo, EnumMsgModel.EMAIL_ACTIVATION);
- return new ResultData();
- // } else {
- // return new ResultData(ErrorCode.MSG_VERIFY_CODE_NOT_FOUND);
- // }
- }
-
- @AuthIgnore
- @ApiOperation(value = "激活", notes = "")
- @PostMapping("/doActivation")
- public ResultData doActivation(@RequestBody Map<String, String> params, HttpServletResponse response) {
- String ipaddress = getIpAddr();
- logger.debug("[" + ipaddress + "] WxUserGrantController::doActivation");
- //
- String ticket = params.get("ticket");
- String key = Constant.ticketPrev + ticket;
- Long userId = RedisCacheUtils.getCacheLong(redisTemplate, key);
- if (userId == null) {
- return new ResultData(ErrorCode.NET_TICKET_INVALID.getCode(), "ticket已过期");
- }
- WxCUserBasicInfo basicInfo = wxCUserBasicInfoService.getById(userId);
- if (basicInfo == null) {
- return new ResultData(ErrorCode.USER_IS_EMPTY);
- }
- // if(!EnumCUserBasicInfoStatus.NOT_ACTIVE.getCode().equals(basicInfo.getStatus())){
- // return new ResultData(ErrorCode.MEMBER_IS_ACTIVE);
- // }
-
- wxCUserBasicInfoService.handleLoginUser(basicInfo);
- Map resultMap = new HashMap();
- // resultMap.put("username", basicInfo.getEmail());
- resultMap.put("token", basicInfo.getToken());
- return new ResultData(resultMap);
- }
-
- @AuthIgnore
- @ApiOperation(value = "手机验证码修改密码", notes = "{\"phone\",\"string\",\"code\",\"string\"}")
- @PostMapping("/updPass")
- public ResultData updPass(@RequestBody Map<String, String> params, HttpServletResponse response) {
- String ipaddress = getIpAddr();
- logger.debug("[" + ipaddress + "] WxUserGrantController::doLoginByPhone");
- // String phone,String code,String pwd
- String phone = params.get("phone");
- String code = params.get("code");
- String pwd = params.get("pwd");
-
- if (StringUtils.isBlank(phone)) {
- return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "手机号不能为空");
- }
- if (StringUtils.isBlank(code)) {
- return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "验证码不能为空");
- }
- if (StringUtils.isBlank(pwd)) {
- return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "密码不能为空");
- }
- WxCUserBasicInfo basicInfo = wxCUserBasicInfoService.findInfoByPhone(getTenantInfo(), phone);
- if (basicInfo == null) {
- return new ResultData(ErrorCode.USER_PHONE_IS_NOT_FOUND.getCode(), "手机号还未注册");
- }
-
- // check 验证码正确
- boolean isValidCode = false;
- try {
- isValidCode = wxMsgValidationcodeService.checkCodeValid(phone, code);
- } catch (Exception e) {
- return new ResultData(Result.ERROR, e.getMessage());
- }
- if (isValidCode) {
- String encryptPassword = new PasswordHelper().encryptPassword(pwd);
- WxCUserBasicInfo basicInfoUpd = new WxCUserBasicInfo();
- basicInfoUpd.setId(basicInfo.getId());
- basicInfoUpd.setPassword(encryptPassword);
- wxCUserBasicInfoService.update(basicInfoUpd);
- return new ResultData();
- } else {
- return new ResultData(ErrorCode.MSG_VERIFY_CODE_NOT_FOUND);
- }
- }
-
- @ApiOperation(value = "旧密码修改密码", notes = "{\"oldpwd\",\"string\",\"newpwd\",\"string\"}")
- @PostMapping("/oldUpdPass")
- public ResultData oldUpdPass(@RequestBody Map<String, String> params, HttpServletResponse response) {
- String ipaddress = getIpAddr();
- logger.debug("[" + ipaddress + "] WxUserGrantController::oldUpdPass");
-
- WxCUserBasicInfo basicInfo = getCUser();
- //
- String oldpwd = params.get("oldpwd");
- // String code = params.get("code");
- String newpwd = params.get("newpwd");
-
- if (StringUtils.isBlank(oldpwd)) {
- return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "旧密码不能为空");
- }
- // if (StringUtils.isBlank(code)) {
- // return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "验证码不能为空");
- // }
- if (StringUtils.isBlank(newpwd)) {
- return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "新密码不能为空");
- }
-
- String encryptPassword = new PasswordHelper().encryptPassword(oldpwd);
-
- if (!encryptPassword.equals(basicInfo.getPassword())) {
- return new ResultData(ErrorCode.PASSWORD_ERROR.getCode(), "旧密码错误");
- }
-
-
- // check 验证码正确
- // boolean isValidCode = false;
- // try {
- // isValidCode = wxMsgValidationcodeService.checkCodeValid(phone,code);
- // } catch (Exception e) {
- // return new ResultData(Result.ERROR, e.getMessage());
- // }
- // if(isValidCode) {
- String newEncryptPassword = new PasswordHelper().encryptPassword(newpwd);
- WxCUserBasicInfo basicInfoUpd = new WxCUserBasicInfo();
- basicInfoUpd.setId(basicInfo.getId());
- basicInfoUpd.setPassword(newEncryptPassword);
- wxCUserBasicInfoService.update(basicInfoUpd);
- return new ResultData();
- // } else {
- // return new ResultData(ErrorCode.MSG_VERIFY_CODE_NOT_FOUND);
- // }
- }
-
- @AuthIgnore
- @ApiOperation(value = "发送修改密码邮件", notes = "{\"email\",\"string\",\"code\",\"string\"}")
- @PostMapping("/sendUpdPwdEmail")
- public ResultData sendUpdPwdEmail(@RequestBody Map<String, String> params, HttpServletResponse response) {
- String ipaddress = getIpAddr();
- logger.debug("[" + ipaddress + "] WxUserGrantController::sendUpdPwdEmail");
- // String name,String username,String password
- String email = params.get("email");
- String code = params.get("code");
-
- if (StringUtils.isBlank(email)) {
- return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "邮箱不能为空");
- }
-
- // if (StringUtils.isBlank(code)) {
- // return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "验证码不能为空");
- // }
-
- WxCUserBasicInfo basicInfo = wxCUserBasicInfoService.findInfoByEmail(getTenantInfo(), email);
- if (basicInfo == null) {
- return new ResultData(ErrorCode.USER_IS_EMPTY);
- }
- if (EnumCUserBasicInfoStatus.NOT_ACTIVE.getCode().equals(basicInfo.getStatus())) {
- return new ResultData(ErrorCode.MEMBER_IS_NOT_ACTIVE);
- }
-
-
- // check 验证码正确
- // boolean isValidCode = false;
- // try {
- // isValidCode = wxMsgValidationcodeService.checkCodeValid(phone,code);
- // } catch (Exception e) {
- // return new ResultData(Result.ERROR, e.getMessage());
- // }
- // if(isValidCode) {
- wxCUserBasicInfoService.sendTicketEmail(basicInfo, EnumMsgModel.EMAIL_UPD_PWD);
- return new ResultData();
- // } else {
- // return new ResultData(ErrorCode.MSG_VERIFY_CODE_NOT_FOUND);
- // }
- }
-
- @AuthIgnore
- @ApiOperation(value = "修改密码", notes = "{\"username\",\"string\",\"code\",\"string\"}")
- @PostMapping("/doUpdPass")
- public ResultData doUpdPass(@RequestBody Map<String, String> params, HttpServletResponse response) {
- String ipaddress = getIpAddr();
- logger.debug("[" + ipaddress + "] WxUserGrantController::doUpdPass");
- //
- String ticket = params.get("ticket");
- String key = Constant.ticketPrev + ticket;
- Long userId = RedisCacheUtils.getCacheLong(redisTemplate, key);
- if (userId == null) {
- return new ResultData(ErrorCode.NET_TICKET_INVALID.getCode(), "已过期");
- }
- WxCUserBasicInfo basicInfo = wxCUserBasicInfoService.getById(userId);
- if (basicInfo == null) {
- return new ResultData(ErrorCode.USER_IS_EMPTY);
- }
- String pwd = params.get("pwd");
- if (StringUtils.isBlank(pwd)) {
- return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "密码不能为空");
- }
-
- String encryptPassword = new PasswordHelper().encryptPassword(pwd);
- WxCUserBasicInfo basicInfoUpd = new WxCUserBasicInfo();
- basicInfoUpd.setId(basicInfo.getId());
- basicInfoUpd.setPassword(encryptPassword);
- wxCUserBasicInfoService.update(basicInfoUpd);
- return new ResultData();
- }
-
- @ApiOperation("登出")
- @GetMapping("/logout")
- public ResultData logout() {
- logger.debug("[" + getIpAddr() + "] WxUserGrantController::logout");
- wxCUserBasicInfoService.logout(getCUser());
- return new ResultData();
- }
-
- @ApiOperation("生成邀请码")
- @GetMapping("/inviteCode")
- public ResultData inviteCode() {
- logger.debug("[" + getIpAddr() + "] WxUserGrantController::inviteCode");
- String code = inviteCodeService.inviteCode(getMemberId());
- return new ResultData(code);
- }
-
- @ApiOperation("使用邀请码")
- @GetMapping("/useCode")
- @ApiImplicitParam(name = "code", value = "code", dataType = "String", paramType = "query", required = true)
- public ResultData useCode(String code) {
- logger.debug("[" + getIpAddr() + "] WxUserGrantController::useCode");
- return inviteCodeInfoService.useCode(getCUser(), code);
- }
-
- @ApiOperation("是否使用邀请码判断")
- @GetMapping("/isUse")
- public ResultData isUse() {
- logger.debug("[" + getIpAddr() + "] WxUserGrantController::isUse");
- Boolean use = inviteCodeInfoService.isUse(getCUser());
- return new ResultData(use);
- }
-
- @ApiOperation("查询哪些用户使用了当前账户的邀请码")
- @GetMapping("/getUseCodeUser")
- public ResultData getUseCodeUser() {
- logger.debug("[" + getIpAddr() + "] WxUserGrantController::getUseCodeUser");
- List<InviteCodeInfo> useCodeUser = inviteCodeInfoService.getUseCodeUser(getCUser());
- return new ResultData(useCodeUser);
- }
-
- @ApiOperation("编辑用户头像和名称")
- @PostMapping("/updUserInfo")
- public ResultData updUserInfo(@RequestBody WxCUserBasicInfo wxCUserBasicInfo) {
- logger.debug("[" + getIpAddr() + "] WxUserGrantController::updUserInfo");
- wxCUserBasicInfoService.updUserInfo(wxCUserBasicInfo, getMemberId());
- return new ResultData();
- }
-
- @ApiOperation("获取用户头像和名称")
- @GetMapping("/getUserInfo")
- public ResultData getUserInfo() {
- logger.debug("[" + getIpAddr() + "] WxUserGrantController::getUserInfo");
- WxCUserBasicInfo userBasicInfo = wxCUserBasicInfoService.getById(getMemberId());
- return new ResultData(userBasicInfo);
- }
-
- @AuthIgnore
- @ApiOperation("套餐档次查询")
- @GetMapping("/getPackageInfo")
- public ResultData getPackageInfo() {
- logger.debug("[" + getIpAddr() + "] WxUserGrantController::getPackageInfo");
- return new ResultData(userConsumptionPackageService.getPackageInfo());
- }
-
- }
|