Commit 045dfe30 by 杨树贤

优化接口

parent 0dc9b2db
......@@ -4,7 +4,8 @@
<list default="true" id="fb90add0-1393-48c2-9f26-72365d42cd03" name="变更" comment="">
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/app/Http/Controllers/Api/AuthApiController.php" beforeDir="false" afterPath="$PROJECT_DIR$/app/Http/Controllers/Api/AuthApiController.php" afterDir="false" />
<change beforePath="$PROJECT_DIR$/routes/api.php" beforeDir="false" afterPath="$PROJECT_DIR$/routes/api.php" afterDir="false" />
<change beforePath="$PROJECT_DIR$/app/Models/User.php" beforeDir="false" afterPath="$PROJECT_DIR$/app/Models/User.php" afterDir="false" />
<change beforePath="$PROJECT_DIR$/config/database.php" beforeDir="false" afterPath="$PROJECT_DIR$/config/database.php" afterDir="false" />
<change beforePath="$PROJECT_DIR$/storage/app/.gitignore" beforeDir="false" afterPath="$PROJECT_DIR$/storage/app/.gitignore" afterDir="false" />
<change beforePath="$PROJECT_DIR$/storage/app/public/.gitignore" beforeDir="false" afterPath="$PROJECT_DIR$/storage/app/public/.gitignore" afterDir="false" />
<change beforePath="$PROJECT_DIR$/storage/framework/.gitignore" beforeDir="false" afterPath="$PROJECT_DIR$/storage/framework/.gitignore" afterDir="false" />
......@@ -183,7 +184,7 @@
<updated>1666170258203</updated>
<workItem from="1666170260162" duration="17108000" />
<workItem from="1666835076791" duration="693000" />
<workItem from="1667266026118" duration="10293000" />
<workItem from="1667266026118" duration="12368000" />
</task>
<servers />
</component>
......
......@@ -20,9 +20,13 @@ class AuthApiController extends Controller
public function register(Request $request)
{
$validator = Validator::make($request->all(), [
'name' => ['required', 'string', 'max:255'],
'email' => ['required', 'string', 'email', 'max:255', 'unique:users'],
'password' => ['required', 'string', 'min:8', 'confirmed'],
'email' => 'required|string|email|max:255|unique:users',
'password' => 'required|string|min:8|confirmed',
'first_name' => 'required|max:100',
'last_name' => 'required|max:100',
'email_code' => 'required|max:100',
'phone' => 'required|max:100',
'company_name' => 'required|max:100',
], [
'password.confirmed' => 'Passwords do not match!',
]);
......@@ -30,6 +34,12 @@ class AuthApiController extends Controller
return $this->setError($validator->errors()->first());
}
//判断邮箱验证码
$redisKey = 'sem_email_code_register_' . $request->input('email');
$cachedEmailCode = Redis::get($redisKey);
if ($cachedEmailCode != $request->input('email_code')) {
return $this->setError('Email code invalid');
}
$user = User::createUser($request->all());
\Auth::login($user);
......
......@@ -46,8 +46,11 @@ class User extends Authenticatable implements MustVerifyEmail
public static function createUser($data)
{
return User::create([
'name' => $data['name'],
'email' => $data['email'],
'first_name' => $data['first_name'],
'last_name' => $data['last_name'],
'phone' => $data['phone'],
'email_verified_at' => now(),
'company_name' => $data['company_name'],
'password' => Hash::make($data['password']),
]);
}
......
......@@ -123,7 +123,7 @@ return [
'options' => [
'cluster' => env('REDIS_CLUSTER', 'redis'),
'prefix' => env('REDIS_PREFIX', Str::slug(env('APP_NAME', 'laravel'), '_').'_database_'),
'prefix' => env('REDIS_PREFIX', ''),
],
'default' => [
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment