Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
杨树贤
/
ucenter
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
17b8616e
authored
Jan 16, 2024
by
杨树贤
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
最后登录时间
parent
de81acba
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
25 additions
and
15 deletions
app/Http/Controllers/Api/AuthController.php
app/Http/Services/UserService.php
app/Http/Controllers/Api/AuthController.php
View file @
17b8616e
...
...
@@ -20,9 +20,8 @@ class AuthController extends Controller
'salt'
,
]);
$ucId
=
UserService
::
register
(
$data
);
return
$this
->
setSuccessData
([
'uc_id'
=>
$ucId
]);
$user
=
UserService
::
register
(
$data
);
return
$this
->
setSuccessData
([
'uc_id'
=>
$user
[
'uc_id'
],
'user'
=>
$user
]);
}
public
function
login
(
UserLogin
$request
)
...
...
@@ -33,14 +32,12 @@ class AuthController extends Controller
'password'
,
]);
$u
cId
=
UserService
::
login
(
$data
);
$u
ser
=
UserService
::
login
(
$data
);
if
(
empty
(
$u
cId
))
{
if
(
empty
(
$u
ser
))
{
$this
->
setError
(
'账号和密码校验失败'
);
}
return
$this
->
setSuccessData
([
'uc_id'
=>
$ucId
]);
return
$this
->
setSuccessData
([
'uc_id'
=>
$user
[
'uc_id'
],
'user'
=>
$user
]);
}
}
app/Http/Services/UserService.php
View file @
17b8616e
...
...
@@ -18,14 +18,22 @@ class UserService
$ucId
=
UserModel
::
where
(
'email'
,
$data
[
'email'
])
->
value
(
'uc_id'
);
}
if
(
$ucId
)
{
return
$ucId
;
}
else
{
if
(
!
$ucId
)
{
//去新增注册
$data
[
'create_time'
]
=
time
();
$ucId
=
UserModel
::
insertGetId
(
$data
);
}
return
$ucId
;
$user
=
UserModel
::
select
([
'uc_id'
,
'mobile'
,
'email'
,
'create_time'
,
])
->
where
(
'uc_id'
,
$ucId
)
->
first
();
UserModel
::
where
(
'uc_id'
,
$user
[
'uc_id'
])
->
update
([
'last_login_time'
],
time
());
return
$user
;
}
//登录接口
...
...
@@ -39,13 +47,18 @@ class UserService
$salt
=
UserModel
::
where
(
'email'
,
$data
[
'email'
])
->
value
(
'salt'
);
$loginQuery
->
where
(
'email'
,
$data
[
'email'
]);
}
if
(
empty
(
$salt
))
{
throw
new
InvalidRequestException
(
'该账号不存在'
);
}
$passwordHash
=
PasswordService
::
passwordHash
(
$data
[
'password'
],
$salt
);
$user
=
$loginQuery
->
where
(
'password'
,
$passwordHash
)
->
first
();
$user
=
$loginQuery
->
select
([
'uc_id'
,
'mobile'
,
'email'
,
'create_time'
,
])
->
where
(
'password'
,
$passwordHash
)
->
first
();
UserModel
::
where
(
'uc_id'
,
$user
[
'uc_id'
])
->
update
([
'last_login_time'
],
time
());
return
$user
?:
[];
...
...
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