Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
D
dm_project
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
姚本章
dm_project
Commits
b3b082b7
Commit
b3b082b7
authored
Dec 04, 2020
by
ysongq
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
注册/手机号码重复校验
parent
e44ed819
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
148 additions
and
47 deletions
+148
-47
LoginController.java
...z/dm/mall/moduls/controller/customer/LoginController.java
+78
-5
MallCustomerController.java
...ll/moduls/controller/customer/MallCustomerController.java
+23
-38
MallCustomerDao.java
...in/java/com/jz/dm/mall/moduls/mapper/MallCustomerDao.java
+13
-1
MallCustomerService.java
...va/com/jz/dm/mall/moduls/service/MallCustomerService.java
+8
-0
MallCustomerServiceImpl.java
.../dm/mall/moduls/service/impl/MallCustomerServiceImpl.java
+19
-3
MallCustomerDao.xml
jz-dm-mall/src/main/resources/mapperconf/MallCustomerDao.xml
+7
-0
No files found.
jz-dm-mall/src/main/java/com/jz/dm/mall/moduls/controller/customer/LoginController.java
View file @
b3b082b7
...
@@ -2,19 +2,22 @@ package com.jz.dm.mall.moduls.controller.customer;
...
@@ -2,19 +2,22 @@ package com.jz.dm.mall.moduls.controller.customer;
import
com.jz.common.base.CurrentUser
;
import
com.jz.common.base.CurrentUser
;
import
com.jz.common.constant.RedisMessageConstant
;
import
com.jz.dm.mall.moduls.entity.MallCustomer
;
import
com.jz.dm.mall.moduls.entity.MallCustomer
;
import
com.jz.common.utils.Result
;
import
com.jz.common.utils.Result
;
import
com.jz.common.utils.StatusCode
;
import
com.jz.common.utils.StatusCode
;
import
com.jz.dm.mall.moduls.service.MallCustomerService
;
import
com.jz.dm.mall.moduls.service.MallCustomerService
;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.ApiOperation
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.data.redis.core.RedisTemplate
;
import
org.springframework.data.redis.core.RedisTemplate
;
import
org.springframework.web.bind.annotation.PostMapping
;
import
org.springframework.util.StringUtils
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.*
;
import
org.springframework.web.bind.annotation.RestController
;
import
org.apache.catalina.servlet4preview.http.HttpServletRequest
;
import
org.apache.catalina.servlet4preview.http.HttpServletRequest
;
import
java.util.Map
;
/**
/**
* @ClassName:
* @ClassName:
...
@@ -57,8 +60,6 @@ public class LoginController {
...
@@ -57,8 +60,6 @@ public class LoginController {
MallCustomer
mallCustomer
=
mallCustomerService
.
selectByAccount
(
username
,
request
);
MallCustomer
mallCustomer
=
mallCustomerService
.
selectByAccount
(
username
,
request
);
if
(
mallCustomer
!=
null
)
{
if
(
mallCustomer
!=
null
)
{
if
(
mallCustomer
.
getCustomerAccount
().
equals
(
username
)
&&
mallCustomer
.
getPassword
().
equals
(
password
)){
if
(
mallCustomer
.
getCustomerAccount
().
equals
(
username
)
&&
mallCustomer
.
getPassword
().
equals
(
password
)){
System
.
out
.
println
(
CurrentUser
.
getCurrentUser
(
request
));
return
new
Result
<>(
true
,
"登录成功!"
,
StatusCode
.
OK
);
return
new
Result
<>(
true
,
"登录成功!"
,
StatusCode
.
OK
);
}
}
}
}
...
@@ -66,4 +67,76 @@ public class LoginController {
...
@@ -66,4 +67,76 @@ public class LoginController {
return
new
Result
<>(
false
,
"用户名或密码错误!"
,
StatusCode
.
ERROR
);
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
,
"用户名不同!"
);
}
}
}
jz-dm-mall/src/main/java/com/jz/dm/mall/moduls/controller/customer/MallCustomerController.java
View file @
b3b082b7
package
com
.
jz
.
dm
.
mall
.
moduls
.
controller
.
customer
;
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.base.BaseController
;
import
com.jz.common.constant.RedisMessageConstant
;
import
com.jz.common.constant.RedisMessageConstant
;
import
com.jz.common.constant.ResultCode
;
import
com.jz.common.constant.ResultCode
;
...
@@ -8,11 +9,14 @@ import com.jz.dm.mall.moduls.entity.MallCustomer;
...
@@ -8,11 +9,14 @@ import com.jz.dm.mall.moduls.entity.MallCustomer;
import
com.jz.common.utils.Result
;
import
com.jz.common.utils.Result
;
import
com.jz.common.utils.StatusCode
;
import
com.jz.common.utils.StatusCode
;
import
com.jz.dm.mall.moduls.service.MallCustomerService
;
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.beans.factory.annotation.Autowired
;
import
org.springframework.data.redis.core.RedisTemplate
;
import
org.springframework.data.redis.core.RedisTemplate
;
import
org.springframework.util.StringUtils
;
import
org.springframework.util.StringUtils
;
import
org.springframework.web.bind.annotation.*
;
import
org.springframework.web.bind.annotation.*
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
import
javax.servlet.http.HttpServletResponse
;
import
java.util.Map
;
import
java.util.Map
;
...
@@ -24,6 +28,7 @@ import java.util.Map;
...
@@ -24,6 +28,7 @@ import java.util.Map;
*/
*/
@RestController
@RestController
@RequestMapping
(
"/mallCustomer"
)
@RequestMapping
(
"/mallCustomer"
)
@Api
(
tags
=
"商城用户api"
)
public
class
MallCustomerController
extends
BaseController
{
public
class
MallCustomerController
extends
BaseController
{
/**
/**
* 服务对象
* 服务对象
...
@@ -40,51 +45,31 @@ public class MallCustomerController extends BaseController {
...
@@ -40,51 +45,31 @@ public class MallCustomerController extends BaseController {
* @return
* @return
*/
*/
@PostMapping
(
"/saveCustomer"
)
@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
)
{
if
(
paramMap
!=
null
)
{
String
username
=
paramMap
.
get
(
"username"
);
String
username
=
paramMap
.
get
(
"username"
);
String
telephone
=
paramMap
.
get
(
"telephone"
);
String
telephone
=
paramMap
.
get
(
"telephone"
);
if
(
username
==
null
)
{
String
ph
=
"^[1][34578]\\d{9}$"
;
return
new
Result
(
false
,
"请输入用户名!"
);
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
,
"用户名相同"
);
}
}
}
// // 根据用户名查询用户信息
//// 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
);
mallCustomerService
.
saveCustomer
(
paramMap
);
return
new
Result
(
true
,
"注册成功!"
,
StatusCode
.
OK
);
return
new
Result
(
true
,
"注册成功!"
,
StatusCode
.
OK
);
}
}
return
new
Result
(
false
,
"注册失败!"
,
StatusCode
.
ERROR
);
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
);
}
// 判断验证码是否一致
if
(!
codeInRedis
.
equals
(
paramMap
.
get
(
"validateCode"
)))
{
return
new
Result
(
false
,
"验证码不正确!"
,
StatusCode
.
ERROR
);
}
// 删除redis的验证码
redisTemplate
.
delete
(
key
);
return
new
Result
(
true
,
"验证码正确!"
,
StatusCode
.
OK
);
}
}
}
\ No newline at end of file
jz-dm-mall/src/main/java/com/jz/dm/mall/moduls/mapper/MallCustomerDao.java
View file @
b3b082b7
...
@@ -30,10 +30,22 @@ public interface MallCustomerDao extends BaseMapper<MallCustomer> {
...
@@ -30,10 +30,22 @@ public interface MallCustomerDao extends BaseMapper<MallCustomer> {
*/
*/
MallCustomer
selectByPhone
(
String
username
);
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})"
)
@Insert
(
"INSERT into t_mall_customer(customer_account, customer_phone, password) VALUES (#{customerAccount},#{customerPhone}, #{password})"
)
@ResultType
(
MallCustomer
.
class
)
void
saveCustomer
(
MallCustomer
mallCustomer
);
void
saveCustomer
(
MallCustomer
mallCustomer
);
/**
/**
* 根据ID查询用户信息
* 根据ID查询用户信息
* @param customerId
* @param customerId
...
...
jz-dm-mall/src/main/java/com/jz/dm/mall/moduls/service/MallCustomerService.java
View file @
b3b082b7
...
@@ -32,4 +32,12 @@ public interface MallCustomerService {
...
@@ -32,4 +32,12 @@ public interface MallCustomerService {
* @param paramMap
* @param paramMap
*/
*/
void
saveCustomer
(
Map
<
String
,
String
>
paramMap
);
void
saveCustomer
(
Map
<
String
,
String
>
paramMap
);
/**
* 通过手机号查询是否已注册
* @param telephone
* @return
*/
MallCustomer
selectByPhone
(
String
telephone
);
}
}
\ No newline at end of file
jz-dm-mall/src/main/java/com/jz/dm/mall/moduls/service/impl/MallCustomerServiceImpl.java
View file @
b3b082b7
...
@@ -3,6 +3,7 @@ package com.jz.dm.mall.moduls.service.impl;
...
@@ -3,6 +3,7 @@ package com.jz.dm.mall.moduls.service.impl;
import
com.jz.common.constant.RedisMessageConstant
;
import
com.jz.common.constant.RedisMessageConstant
;
import
com.jz.common.enums.UserTypeEnum
;
import
com.jz.common.enums.UserTypeEnum
;
import
com.jz.common.utils.Result
;
import
com.jz.common.utils.SessionUtils
;
import
com.jz.common.utils.SessionUtils
;
import
com.jz.common.bean.MallCustomerApiDto
;
import
com.jz.common.bean.MallCustomerApiDto
;
import
com.jz.dm.mall.moduls.entity.MallCustomer
;
import
com.jz.dm.mall.moduls.entity.MallCustomer
;
...
@@ -59,8 +60,6 @@ public class MallCustomerServiceImpl implements MallCustomerService {
...
@@ -59,8 +60,6 @@ public class MallCustomerServiceImpl implements MallCustomerService {
return
mallCustomer
;
return
mallCustomer
;
}
}
/**
/**
* 通过手机号进行查询
* 通过手机号进行查询
*
*
...
@@ -96,18 +95,35 @@ public class MallCustomerServiceImpl implements MallCustomerService {
...
@@ -96,18 +95,35 @@ public class MallCustomerServiceImpl implements MallCustomerService {
MallCustomer
mallCustomer
=
new
MallCustomer
();
MallCustomer
mallCustomer
=
new
MallCustomer
();
// 获取验证码
// 获取验证码
String
vailCode
=
paramMap
.
get
(
"vailCode"
);
String
vailCode
=
paramMap
.
get
(
"vailCode"
);
String
username
=
paramMap
.
get
(
"username"
);
String
telephone
=
paramMap
.
get
(
"telephone"
);
String
telephone
=
paramMap
.
get
(
"telephone"
);
// 从redis获取验证码
// 从redis获取验证码
// String key = RedisMessageConstant.SENDTYPE_LOGIN + "_" + telephone;
// String key = RedisMessageConstant.SENDTYPE_LOGIN + "_" + telephone;
String
key
=
"18179617425"
;
String
key
=
"18179617425"
;
// String codeInRedis = (String) redisTemplate.opsForValue().get(key);
// String codeInRedis = (String) redisTemplate.opsForValue().get(key);
String
codeInRedis
=
"147826"
;
String
codeInRedis
=
"147826"
;
if
(
codeInRedis
.
equals
(
vailCode
))
{
if
(
codeInRedis
.
equals
(
vailCode
))
{
mallCustomer
.
setCustomerAccount
(
paramMap
.
get
(
"username"
)
);
mallCustomer
.
setCustomerAccount
(
username
);
mallCustomer
.
setPassword
(
paramMap
.
get
(
"password"
));
mallCustomer
.
setPassword
(
paramMap
.
get
(
"password"
));
mallCustomer
.
setCustomerPhone
(
telephone
);
mallCustomer
.
setCustomerPhone
(
telephone
);
tMallCustomerDao
.
saveCustomer
(
mallCustomer
);
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
jz-dm-mall/src/main/resources/mapperconf/MallCustomerDao.xml
View file @
b3b082b7
...
@@ -178,4 +178,11 @@
...
@@ -178,4 +178,11 @@
from t_mall_customer
from t_mall_customer
where customer_phone = #{username};
where customer_phone = #{username};
</select>
</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>
</mapper>
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment