Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
projecttwo
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
wangtao
projecttwo
Commits
44347432
Commit
44347432
authored
May 19, 2025
by
wangzhengwen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
restpassword
parent
43bb42d2
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
51 additions
and
3 deletions
+51
-3
Sms.php
app/api/controller/Sms.php
+5
-0
User.php
app/api/controller/User.php
+29
-3
UtilService.php
app/api/service/UtilService.php
+16
-0
UserValidate.php
app/api/validate/UserValidate.php
+1
-0
No files found.
app/api/controller/Sms.php
View file @
44347432
...
...
@@ -5,10 +5,13 @@ namespace app\api\controller;
use
app\api\validate\UserValidate
;
use
app\BaseController
;
use
app\Request
;
use
think\facade\Cache
;
use
tool\SendSms
;
class
Sms
extends
BaseController
{
const
TOKEN_PREFIX
=
'sms_token:'
;
public
function
sendSms
(
Request
$request
)
{
...
...
@@ -18,9 +21,11 @@ class Sms extends BaseController
return
$vo
;
}
$data
=
$request
->
param
();
$code
=
str_pad
(
random_int
(
0
,
9999
),
4
,
'0'
,
STR_PAD_LEFT
);
// halt($code);
$SMS
=
new
SendSms
();
...
...
app/api/controller/User.php
View file @
44347432
...
...
@@ -4,6 +4,7 @@ namespace app\api\controller;
use
app\api\service\TokenService
;
use
app\api\service\UserService
;
use
app\api\service\UtilService
;
use
app\api\validate\UserValidate
;
use
app\BaseController
;
use
app\Request
;
...
...
@@ -52,7 +53,7 @@ class User extends BaseController
public
function
register
(
Request
$request
)
{
$vo
=
(
new
UserValidate
())
->
goCheck
();
$vo
=
(
new
UserValidate
())
->
goCheck
(
[
'name'
,
'mobile'
,
'password'
,
'code'
]
);
if
(
$vo
!==
true
)
{
return
$vo
;
}
...
...
@@ -64,6 +65,12 @@ class User extends BaseController
return
$this
->
returnMsg
(
'用户已存在'
,
0
);
}
$checkSmsCode
=
UtilService
::
checkSmsCode
(
$data
[
'mobile'
],
$data
[
'code'
]);
if
(
!
$checkSmsCode
)
{
return
$this
->
returnMsg
(
'验证码错误'
);
}
$user
[
'username'
]
=
$data
[
'name'
];
$user
[
'mobile'
]
=
$data
[
'mobile'
];
$user
[
'salt'
]
=
random
(
4
);
...
...
@@ -87,21 +94,32 @@ class User extends BaseController
}
$data
=
$request
->
param
();
$checkSmsCode
=
UtilService
::
checkSmsCode
(
$data
[
'str'
],
$data
[
'code'
]);
if
(
!
$checkSmsCode
)
{
return
$this
->
returnMsg
(
'验证码错误'
);
}
$user
=
userModel
::
where
([
'mobile'
=>
$data
[
'str'
]])
->
whereOr
([
'username'
=>
$data
[
'str'
]])
->
find
();
if
(
!
$user
)
{
return
$this
->
returnMsg
(
'用户不存在'
,
0
);
}
// 生成重置令牌并设置过期时间(如10分钟)
$resetToken
=
md5
(
uniqid
()
.
$user
[
'id'
]
.
time
());
cache
(
'reset_token_'
.
$user
[
'id'
],
$resetToken
,
600
);
// 10分钟有效期
//sms
return
$this
->
returnMsg
(
'success'
,
1
);
return
$this
->
returnMsg
(
'success'
,
1
,
[
'reset_token'
=>
$resetToken
]
);
}
public
function
restUserPasswordStep2
(
Request
$request
)
{
$vo
=
(
new
UserValidate
())
->
goCheck
([
'str'
,
'confirm_password'
,
'password'
]);
$vo
=
(
new
UserValidate
())
->
goCheck
([
'str'
,
'confirm_password'
,
'password'
,
'reset_token'
]);
if
(
$vo
!==
true
)
{
return
$vo
;
}
...
...
@@ -113,10 +131,18 @@ class User extends BaseController
{
return
$this
->
returnMsg
(
'用户不存在'
,
0
);
}
// 验证重置令牌
$storedToken
=
cache
(
'reset_token_'
.
$user
[
'id'
]);
if
(
!
$storedToken
||
$storedToken
!==
$data
[
'reset_token'
])
{
return
$this
->
returnMsg
(
'无效的重置令牌或已过期'
,
0
);
}
$update
[
'password'
]
=
md5
(
$data
[
'password'
]
.
$user
[
'salt'
]);
userModel
::
where
([
'id'
=>
$user
[
'id'
]])
->
update
(
$update
);
// 清除重置令牌
cache
(
'reset_token_'
.
$user
[
'id'
],
null
);
//销毁token
TokenService
::
deleteToken
(
$user
[
'token'
]);
...
...
app/api/service/UtilService.php
View file @
44347432
...
...
@@ -2,8 +2,14 @@
namespace
app\api\service
;
use
think\facade\Cache
;
class
UtilService
{
const
TOKEN_PREFIX
=
'sms_token:'
;
// public static function generateOrderNo($userId = 0,$str=null)
// {
// $microtime = microtime(true);
...
...
@@ -65,4 +71,14 @@ class UtilService
return
$result
;
}
public
static
function
checkSmsCode
(
$mobile
,
$code
)
{
$cacheCode
=
Cache
::
get
(
self
::
TOKEN_PREFIX
.
$mobile
);
if
(
$code
!=
$cacheCode
)
{
return
false
;
}
return
true
;
}
}
\ No newline at end of file
app/api/validate/UserValidate.php
View file @
44347432
...
...
@@ -23,6 +23,7 @@ class UserValidate extends BaseValidate
'idcard_h'
=>
'require'
,
'amount'
=>
'require|chenckAmount'
,
'txType'
=>
'require'
,
'reset_token'
=>
'require'
,
];
protected
$message
=
[
...
...
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