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
23e6620a
authored
Jan 17, 2024
by
杨树贤
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
优化
parent
53a50fbf
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
60 additions
and
1 deletions
app/Http/Controllers/Api/UserController.php
app/Http/Requests/UserRegister.php
app/Http/Services/UserService.php
app/Http/Controllers/Api/UserController.php
View file @
23e6620a
...
...
@@ -3,8 +3,39 @@
namespace
App\Http\Controllers\Api
;
use
App\Http\Controllers\Controller
;
use
App\Http\Services\UserService
;
class
UserController
extends
Controller
{
//绑定邮箱
public
function
bindEmail
(
\Request
$request
)
{
$ucId
=
$request
->
input
(
'uc_id'
);
if
(
empty
(
$ucId
))
{
return
$this
->
setError
(
'uc_id不能为空'
);
}
$email
=
$request
->
input
(
'email'
);
if
(
empty
(
$email
))
{
return
$this
->
setError
(
'email不能为空'
);
}
UserService
::
bindEmail
(
$ucId
,
$email
);
return
$this
->
setSuccess
(
'绑定成功'
);
}
//绑定手机号
public
function
bindMobile
(
\Request
$request
)
{
$ucId
=
$request
->
input
(
'uc_id'
);
if
(
empty
(
$ucId
))
{
return
$this
->
setError
(
'uc_id不能为空'
);
}
$mobile
=
$request
->
input
(
'mobile'
);
if
(
empty
(
$mobile
))
{
return
$this
->
setError
(
'mobile不能为空'
);
}
UserService
::
bindEmail
(
$ucId
,
$mobile
);
return
$this
->
setSuccess
(
'绑定成功'
);
}
}
app/Http/Requests/UserRegister.php
View file @
23e6620a
...
...
@@ -28,7 +28,7 @@ class UserRegister extends FormRequest
{
return
[
'password'
=>
'required'
,
'salt'
=>
'required'
,
//
'salt' => 'required',
'mobile'
=>
'required_without:email'
,
'email'
=>
'required_without:mobile'
,
'init_org_id'
=>
'required'
...
...
app/Http/Services/UserService.php
View file @
23e6620a
...
...
@@ -61,7 +61,35 @@ class UserService
UserModel
::
where
(
'uc_id'
,
$user
[
'uc_id'
])
->
update
([
'last_login_time'
=>
time
()]);
return
$user
?:
[];
}
//绑定邮箱
public
static
function
bindEmail
(
$ucId
,
$email
)
{
//先去判断这个email是否已经被其它账号使用了
$exists
=
UserModel
::
where
(
'uc_id'
,
'!='
,
$ucId
)
->
where
(
'email'
,
$email
)
->
exists
();
if
(
$exists
)
{
throw
new
InvalidRequestException
(
'该邮箱已经被其它账户绑定了,请确认后重新提交'
);
}
return
UserModel
::
where
(
'uc_id'
,
$ucId
)
->
update
([
'email'
=>
$email
,
'update_time'
=>
time
(),
]);
}
//绑定手机
public
static
function
bindMobile
(
$ucId
,
$mobile
)
{
//先去判断这个email是否已经被其它账号使用了
$exists
=
UserModel
::
where
(
'uc_id'
,
'!='
,
$ucId
)
->
where
(
'mobile'
,
$mobile
)
->
exists
();
if
(
$exists
)
{
throw
new
InvalidRequestException
(
'该手机号已经被其它账户绑定了,请确认后重新提交'
);
}
return
UserModel
::
where
(
'uc_id'
,
$ucId
)
->
update
([
'mobile'
=>
$mobile
,
'update_time'
=>
time
(),
]);
}
}
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