Commit b3b082b7 authored by ysongq's avatar ysongq

注册/手机号码重复校验

parent e44ed819
......@@ -2,19 +2,22 @@ package com.jz.dm.mall.moduls.controller.customer;
import com.jz.common.base.CurrentUser;
import com.jz.common.constant.RedisMessageConstant;
import com.jz.dm.mall.moduls.entity.MallCustomer;
import com.jz.common.utils.Result;
import com.jz.common.utils.StatusCode;
import com.jz.dm.mall.moduls.service.MallCustomerService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;
import org.apache.catalina.servlet4preview.http.HttpServletRequest;
import java.util.Map;
/**
* @ClassName:
......@@ -57,8 +60,6 @@ public class LoginController {
MallCustomer mallCustomer = mallCustomerService.selectByAccount(username, request);
if (mallCustomer != null) {
if (mallCustomer.getCustomerAccount().equals(username) && mallCustomer.getPassword().equals(password)){
System.out.println(CurrentUser.getCurrentUser(request));
return new Result<>(true, "登录成功!", StatusCode.OK);
}
}
......@@ -66,4 +67,76 @@ public class LoginController {
return new Result<>(false, "用户名或密码错误!", StatusCode.ERROR);
}
/**
* 手机获取验证码
* @param paramMap
* @return
*/
@PostMapping(value = "/getCode")
public Result loginCheck(@RequestParam(required = false) Map<String, String> paramMap) {
// 获取手机号码
String telephone = paramMap.get("telephone");
String key = RedisMessageConstant.SENDTYPE_LOGIN + "_" + telephone;
// 获取redis中key对应的值
String codeInRedis = (String) redisTemplate.opsForValue().get(key);
if (StringUtils.isEmpty(codeInRedis)) {
return new Result(false, "请重新获取验证码!", StatusCode.ERROR);
}
// 判断验证码是否一致
if (!codeInRedis.equals(paramMap.get("validateCode"))) {
return new Result(false, "验证码不正确!", StatusCode.ERROR);
}
// 删除redis的验证码
redisTemplate.delete(key);
return new Result(true, "验证码正确!", StatusCode.OK);
}
/**
* 手机号码校验
* @param telephone
* @return
*/
@GetMapping(value = "/phoneCheck")
@ApiOperation(value = "手机号码校验接口", notes = "手机号码是否已注册")
public Result phoneCheck(String telephone) {
if (telephone == null) {
return new Result(false, "请重新输入手机号!");
}
MallCustomer mallCustomer = mallCustomerService.selectByPhone(telephone);
if (mallCustomer != null) {
return new Result(false, "手机号码已注册!");
}
return new Result(true, "手机号码未注册!");
}
/**
* 手机号码及用户名重复校验
* @param username
* @param telephone
* @param request
* @return
*/
@GetMapping(value = "/phoneUserCheck")
@ApiOperation(value = "手机号用户名重复校验接口", notes = "手机号用户名是否重复")
public Result phoneCheck(String username, String telephone, HttpServletRequest request) {
String ph = "^[1][34578]\\d{9}$";
if (telephone.matches(ph)) {
MallCustomer mallCustomer = mallCustomerService.selectByPhone(telephone);
if (mallCustomer != null) {
if (mallCustomer.getCustomerPhone().equals(telephone)) {
return new Result(false, "手机号相同");
}
}
}
// 根据手机号查询用户信息
MallCustomer mallCustomer = mallCustomerService.selectByAccount(username, request);
if (mallCustomer != null) {
if (mallCustomer.getCustomerAccount().equals(username)) {
return new Result(false, "用户名相同!");
}
}
return new Result(true, "用户名不同!");
}
}
package com.jz.dm.mall.moduls.controller.customer;
import com.baomidou.mybatisplus.extension.api.R;
import com.jz.common.base.BaseController;
import com.jz.common.constant.RedisMessageConstant;
import com.jz.common.constant.ResultCode;
......@@ -8,11 +9,14 @@ import com.jz.dm.mall.moduls.entity.MallCustomer;
import com.jz.common.utils.Result;
import com.jz.common.utils.StatusCode;
import com.jz.dm.mall.moduls.service.MallCustomerService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Map;
......@@ -24,6 +28,7 @@ import java.util.Map;
*/
@RestController
@RequestMapping("/mallCustomer")
@Api(tags = "商城用户api")
public class MallCustomerController extends BaseController {
/**
* 服务对象
......@@ -40,51 +45,31 @@ public class MallCustomerController extends BaseController {
* @return
*/
@PostMapping("/saveCustomer")
public Result saveCustomer(@RequestParam(required = false) Map<String, String> paramMap) {
@ApiOperation(value = "注册用户", notes = "添加用户")
public Result saveCustomer(@RequestParam(required = false) Map<String, String> paramMap, HttpServletRequest request) {
if (paramMap != null) {
String username = paramMap.get("username");
String telephone = paramMap.get("telephone");
if (username == null) {
return new Result(false, "请输入用户名!");
String ph = "^[1][34578]\\d{9}$";
if (telephone.matches(ph)) {
MallCustomer mallCustomer = mallCustomerService.selectByPhone(telephone);
if (mallCustomer != null) {
if (mallCustomer.getCustomerPhone().equals(telephone)) {
return new Result(false, "手机号相同");
}
// // 根据用户名查询用户信息
//// MallCustomer mallCustomer = mallCustomerService.selectByAccount(username);
//// if (mallCustomer.getCustomerAccount().equals(username)) {
//// return new Result(false, "用户名相同!");
//// }
//// if (mallCustomer.getCustomerPhone().equals(telephone)) {
//// return new Result(false,"手机号相同!");
//// }
mallCustomerService.saveCustomer(paramMap);
return new Result(true, "注册成功!", StatusCode.OK);
}
return new Result(false, "注册失败!", StatusCode.ERROR);
}
/**
* 手机号码校验
* @param paramMap
* @return
*/
@PostMapping(value = "/check")
public Result loginCheck(@RequestBody Map<String, String> paramMap) {
// 获取手机号码
String telephone = paramMap.get("telephone");
String key = RedisMessageConstant.SENDTYPE_LOGIN + "_" + telephone;
// 获取redis中key对应的值
String codeInRedis = (String) redisTemplate.opsForValue().get(key);
if (StringUtils.isEmpty(codeInRedis)) {
return new Result(false, "请重新获取验证码!", StatusCode.ERROR);
// 根据手机号查询用户信息
MallCustomer mallCustomer = mallCustomerService.selectByAccount(username, request);
if (mallCustomer != null) {
if (mallCustomer.getCustomerAccount().equals(username)) {
return new Result(false, "用户名相同");
}
// 判断验证码是否一致
if (!codeInRedis.equals(paramMap.get("validateCode"))) {
return new Result(false, "验证码不正确!", StatusCode.ERROR);
}
// 删除redis的验证码
redisTemplate.delete(key);
return new Result(true, "验证码正确!", StatusCode.OK);
mallCustomerService.saveCustomer(paramMap);
return new Result(true, "注册成功!", StatusCode.OK);
}
return new Result(false, "注册失败!", StatusCode.ERROR);
}
}
\ No newline at end of file
......@@ -30,10 +30,22 @@ public interface MallCustomerDao extends BaseMapper<MallCustomer> {
*/
MallCustomer selectByPhone(String username);
/**
* 根据手机号查询是否已注册
* @param telephone
* @return
*/
MallCustomer selectByPhoneExist(String telephone);
/**
* 添加用户
* @param mallCustomer
*/
@Insert("INSERT into t_mall_customer(customer_account, customer_phone, password) VALUES (#{customerAccount},#{customerPhone}, #{password})")
@ResultType(MallCustomer.class)
void saveCustomer(MallCustomer mallCustomer);
/**
* 根据ID查询用户信息
* @param customerId
......
......@@ -32,4 +32,12 @@ public interface MallCustomerService {
* @param paramMap
*/
void saveCustomer(Map<String, String> paramMap);
/**
* 通过手机号查询是否已注册
* @param telephone
* @return
*/
MallCustomer selectByPhone(String telephone);
}
\ No newline at end of file
......@@ -3,6 +3,7 @@ package com.jz.dm.mall.moduls.service.impl;
import com.jz.common.constant.RedisMessageConstant;
import com.jz.common.enums.UserTypeEnum;
import com.jz.common.utils.Result;
import com.jz.common.utils.SessionUtils;
import com.jz.common.bean.MallCustomerApiDto;
import com.jz.dm.mall.moduls.entity.MallCustomer;
......@@ -59,8 +60,6 @@ public class MallCustomerServiceImpl implements MallCustomerService {
return mallCustomer;
}
/**
* 通过手机号进行查询
*
......@@ -96,18 +95,35 @@ public class MallCustomerServiceImpl implements MallCustomerService {
MallCustomer mallCustomer = new MallCustomer();
// 获取验证码
String vailCode = paramMap.get("vailCode");
String username = paramMap.get("username");
String telephone = paramMap.get("telephone");
// 从redis获取验证码
// String key = RedisMessageConstant.SENDTYPE_LOGIN + "_" + telephone;
String key = "18179617425";
// String codeInRedis = (String) redisTemplate.opsForValue().get(key);
String codeInRedis = "147826";
if (codeInRedis.equals(vailCode)) {
mallCustomer.setCustomerAccount(paramMap.get("username"));
mallCustomer.setCustomerAccount(username);
mallCustomer.setPassword(paramMap.get("password"));
mallCustomer.setCustomerPhone(telephone);
tMallCustomerDao.saveCustomer(mallCustomer);
}
}
/**
* 通过手机号查询是否已注册
*
* @param telephone@return
*/
@Override
public MallCustomer selectByPhone(String telephone) {
MallCustomer mallCustomer = tMallCustomerDao.selectByPhoneExist(telephone);
if (mallCustomer != null) {
return mallCustomer;
}
return null;
}
}
\ No newline at end of file
......@@ -178,4 +178,11 @@
from t_mall_customer
where customer_phone = #{username};
</select>
<select id="selectByPhoneExist" resultMap="TMallCustomerMap">
select
customer_id, department_id, password, customer_account, customer_name, customer_phone, customer_email, customer_address, customer_point, register_time, customer_level, identity_card, cre_time, upt_time, del_flag
from t_mall_customer
where customer_phone = #{telephone};
</select>
</mapper>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment