注册接口

This commit is contained in:
2025-05-05 20:23:01 +08:00
parent 91a1d06b53
commit c61357eca1
4 changed files with 153 additions and 130 deletions

View File

@@ -4,6 +4,7 @@ namespace App\Http\Controllers;
use App\BaseApp\BaseController;
use App\Service\LoginService;
use Illuminate\Http\JsonResponse;
class LoginController extends BaseController
{
@@ -18,7 +19,7 @@ class LoginController extends BaseController
/**
* 登录
* @Method POST
* @return \Illuminate\Http\JsonResponse
* @return JsonResponse
* @throws \Exception
*/
public function login()
@@ -34,4 +35,23 @@ class LoginController extends BaseController
);
}
/**
* 注册
* @Method POST
* @return JsonResponse
* @throws \Exception
*/
public function register()
{
$this->insertField = [
'account', 'password', 'email', 'code'
];
$param = $this->checkRequiredFields(request()->post());
return jok(
$this->service->register($param['account'], $param['password'], $param['email'], $param['code']),
'登录成功'
);
}
}

View File

@@ -37,7 +37,7 @@ class LoginService
* @return array
* @throws Exception
*/
public function login($account, $password)
public function login($account, $password): array
{
$userModel = UserModel::with(['roles:id,name,value'])->where('account', $account)->first();
if (empty($userModel)) {
@@ -86,10 +86,12 @@ class LoginService
* 注册
* @param $account
* @param $password
* @param $email
* @param $code
* @return array
* @throws Exception
*/
public function register($account, $password): array
public function register($account, $password, $email, $code): array
{
$userModel = UserModel::where('account', $account)->first();
if ($userModel) {
@@ -98,6 +100,7 @@ class LoginService
$createModel = UserModel::create([
'account' => $account,
'email' => $email,
'password' => password_hash($password, PASSWORD_DEFAULT),
'nick_name' => '新用户'. Str::random(),
'avatar' => 'https://pic.rmb.bdstatic.com/bjh/80852bfe7c321988191838517ba64e309354.jpeg@h_1280',