Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
xiaolang
/
expert
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
72f87dc7
authored
Mar 23, 2020
by
xiaolang850403
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
图形验证码
parent
6b477c9b
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
65 additions
and
7 deletions
+65
-7
src/main/java/com/asset/common/Common.java
+13
-0
src/main/java/com/asset/controller/CaptchaController.java
+12
-4
src/main/java/com/asset/controller/UserController.java
+34
-0
src/main/java/com/asset/domain/system/Captcha.java
+2
-2
src/main/java/com/asset/enums/CodeEnum.java
+4
-1
No files found.
src/main/java/com/asset/common/Common.java
View file @
72f87dc7
...
@@ -8,6 +8,7 @@ import java.text.SimpleDateFormat;
...
@@ -8,6 +8,7 @@ import java.text.SimpleDateFormat;
import
java.util.*
;
import
java.util.*
;
import
java.util.regex.Matcher
;
import
java.util.regex.Matcher
;
import
java.util.regex.Pattern
;
import
java.util.regex.Pattern
;
import
java.util.Date
;
/*
/*
* @author xiaol
* @author xiaol
...
@@ -57,6 +58,18 @@ public class Common {
...
@@ -57,6 +58,18 @@ public class Common {
return
Arrays
.
toString
(
arr
);
return
Arrays
.
toString
(
arr
);
}
}
//日期比较大小
public
static
boolean
getCompareDate
(
String
daf
)
throws
ParseException
{
SimpleDateFormat
df
=
new
SimpleDateFormat
(
"yyyy-MM-dd HH:mm:ss"
);
//设置日期格式
String
begin
=
df
.
format
(
new
Date
());
Integer
i
=
begin
.
compareTo
(
daf
);
//返回值大于0表示左侧大于右侧
if
(
i
>
0
){
return
true
;
}
else
{
return
false
;
}
}
/**
/**
* @param phone 字符串类型的手机号
* @param phone 字符串类型的手机号
* 传入手机号,判断后返回
* 传入手机号,判断后返回
...
...
src/main/java/com/asset/controller/CaptchaController.java
View file @
72f87dc7
...
@@ -10,6 +10,9 @@ import com.wf.captcha.SpecCaptcha;
...
@@ -10,6 +10,9 @@ import com.wf.captcha.SpecCaptcha;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RestController
;
import
org.springframework.web.bind.annotation.RestController
;
import
java.util.HashMap
;
import
java.util.Map
;
import
java.util.UUID
;
import
java.util.UUID
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
import
javax.servlet.http.HttpServletResponse
;
...
@@ -32,10 +35,15 @@ public class CaptchaController {
...
@@ -32,10 +35,15 @@ public class CaptchaController {
String
key
=
UUID
.
randomUUID
().
toString
();
String
key
=
UUID
.
randomUUID
().
toString
();
// 存入表并设置过期时间为2分钟
// 存入表并设置过期时间为2分钟
Captcha
cap
=
new
Captcha
();
Captcha
cap
=
new
Captcha
();
cap
.
setCaptcha
_k
ey
(
key
);
cap
.
setCaptcha
K
ey
(
key
);
cap
.
setCaptcha
_value
(
specCaptcha
.
toBase64
()
);
cap
.
setCaptcha
Value
(
verCode
);
String
ex
=
Common
.
getDateToString
(
Common
.
getTime
()
+
12
0
);
String
ex
=
Common
.
getDateToString
(
Common
.
getTime
()
+
2
*
60
*
100
0
);
cap
.
setExpire
(
ex
);
cap
.
setExpire
(
ex
);
return
ResultUtil
.
success
(
CodeEnum
.
SUCCESS
,
cap
);
//入库
captchaService
.
save
(
cap
);
Map
map
=
new
HashMap
();
map
.
put
(
"key"
,
key
);
map
.
put
(
"image"
,
specCaptcha
.
toBase64
());
return
ResultUtil
.
success
(
CodeEnum
.
SUCCESS
,
map
);
}
}
}
}
src/main/java/com/asset/controller/UserController.java
View file @
72f87dc7
...
@@ -4,10 +4,12 @@ import com.aliyun.oss.OSS;
...
@@ -4,10 +4,12 @@ import com.aliyun.oss.OSS;
import
com.asset.common.*
;
import
com.asset.common.*
;
import
com.asset.domain.Result
;
import
com.asset.domain.Result
;
import
com.asset.domain.User
;
import
com.asset.domain.User
;
import
com.asset.domain.system.Captcha
;
import
com.asset.domain.system.Certificate
;
import
com.asset.domain.system.Certificate
;
import
com.asset.domain.system.LoginLog
;
import
com.asset.domain.system.LoginLog
;
import
com.asset.enums.CodeEnum
;
import
com.asset.enums.CodeEnum
;
import
com.asset.service.UserService
;
import
com.asset.service.UserService
;
import
com.asset.service.system.CaptchaService
;
import
com.asset.service.system.CertificateService
;
import
com.asset.service.system.CertificateService
;
import
com.asset.service.system.LoginLogService
;
import
com.asset.service.system.LoginLogService
;
import
com.baomidou.mybatisplus.core.conditions.query.QueryWrapper
;
import
com.baomidou.mybatisplus.core.conditions.query.QueryWrapper
;
...
@@ -22,6 +24,7 @@ import javax.servlet.http.HttpSession;
...
@@ -22,6 +24,7 @@ import javax.servlet.http.HttpSession;
import
java.io.IOException
;
import
java.io.IOException
;
import
java.io.UnsupportedEncodingException
;
import
java.io.UnsupportedEncodingException
;
import
java.net.URL
;
import
java.net.URL
;
import
java.text.ParseException
;
import
java.util.*
;
import
java.util.*
;
...
@@ -42,6 +45,9 @@ public class UserController {
...
@@ -42,6 +45,9 @@ public class UserController {
@Autowired
@Autowired
LoginLogService
loginLogService
;
LoginLogService
loginLogService
;
@Autowired
CaptchaService
captchaService
;
@RequestMapping
(
"/register"
)
@RequestMapping
(
"/register"
)
public
Result
register
(
@Validated
(
value
={
Insert
.
class
})
@RequestBody
User
user
,
BindingResult
result
)
throws
UnsupportedEncodingException
{
public
Result
register
(
@Validated
(
value
={
Insert
.
class
})
@RequestBody
User
user
,
BindingResult
result
)
throws
UnsupportedEncodingException
{
if
(
result
.
hasErrors
())
{
if
(
result
.
hasErrors
())
{
...
@@ -263,4 +269,32 @@ public class UserController {
...
@@ -263,4 +269,32 @@ public class UserController {
map
.
put
(
"url"
,
url
);
map
.
put
(
"url"
,
url
);
return
ResultUtil
.
success
(
CodeEnum
.
SUCCESS
,
map
);
return
ResultUtil
.
success
(
CodeEnum
.
SUCCESS
,
map
);
}
}
@GetMapping
(
"/checkCaptcha"
)
public
Result
checkCaptcha
(
String
name
,
String
verKey
,
String
captcha
)
throws
ParseException
{
//先判断账号是否存在
QueryWrapper
<
User
>
queryWrapper
=
new
QueryWrapper
<>();
queryWrapper
.
eq
(
"mobile"
,
name
).
or
().
eq
(
"email"
,
name
);
User
user
=
userService
.
getOne
(
queryWrapper
);
if
(
user
==
null
){
return
ResultUtil
.
success
(
CodeEnum
.
ISEXITE_NOT_ERROR
);
}
else
{
QueryWrapper
<
Captcha
>
CapqueryWrapper
=
new
QueryWrapper
<>();
CapqueryWrapper
.
eq
(
"captcha_key"
,
verKey
);
Captcha
cap
=
captchaService
.
getOne
(
CapqueryWrapper
);
if
(
cap
==
null
){
return
ResultUtil
.
success
(
CodeEnum
.
ISEXITE_CODE
);
}
else
{
//比较看验证码是否过期
if
(
Common
.
getCompareDate
(
cap
.
getExpire
())){
return
ResultUtil
.
success
(
CodeEnum
.
CODE_EXpired
);
}
else
{
//没过期判断对错
if
(
captcha
==
null
||
!
cap
.
getCaptchaValue
().
equals
(
captcha
.
trim
().
toLowerCase
())){
return
ResultUtil
.
success
(
CodeEnum
.
CODE_ERROR
);
}
}
}
}
return
ResultUtil
.
success
(
CodeEnum
.
SUCCESS
);
}
}
}
src/main/java/com/asset/domain/system/Captcha.java
View file @
72f87dc7
...
@@ -15,9 +15,9 @@ public class Captcha {
...
@@ -15,9 +15,9 @@ public class Captcha {
private
Integer
id
;
private
Integer
id
;
private
String
captcha
_k
ey
;
private
String
captcha
K
ey
;
private
String
captcha
_v
alue
;
private
String
captcha
V
alue
;
private
String
expire
;
private
String
expire
;
...
...
src/main/java/com/asset/enums/CodeEnum.java
View file @
72f87dc7
...
@@ -18,7 +18,10 @@ public enum CodeEnum {
...
@@ -18,7 +18,10 @@ public enum CodeEnum {
ISEXITE_NOT_ERROR
(
20005
,
"账号不存在!"
),
ISEXITE_NOT_ERROR
(
20005
,
"账号不存在!"
),
LOGINOUT_SUCCESS
(
20004
,
"成功!"
),
LOGINOUT_SUCCESS
(
20004
,
"成功!"
),
ISEXITE_MOBILE
(
20006
,
"手机号已经存在!"
),
ISEXITE_MOBILE
(
20006
,
"手机号已经存在!"
),
FORMAT_MOBILE
(
20007
,
"手机号格式不正确!"
)
FORMAT_MOBILE
(
20007
,
"手机号格式不正确!"
),
CODE_ERROR
(
20008
,
"验证码错误!"
),
ISEXITE_CODE
(
20010
,
"验证码不存在!"
),
CODE_EXpired
(
20009
,
"验证码过期!"
)
;
;
...
...
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