Commit 0dc9b2db by 杨树贤

邮箱

parent f432d22b
......@@ -2,14 +2,9 @@
<project version="4">
<component name="ChangeListManager">
<list default="true" id="fb90add0-1393-48c2-9f26-72365d42cd03" name="变更" comment="">
<change beforePath="$PROJECT_DIR$/.env" beforeDir="false" afterPath="$PROJECT_DIR$/.env" afterDir="false" />
<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$/app/Http/Controllers/Controller.php" beforeDir="false" afterPath="$PROJECT_DIR$/app/Http/Controllers/Controller.php" afterDir="false" />
<change beforePath="$PROJECT_DIR$/app/Http/Kernel.php" beforeDir="false" afterPath="$PROJECT_DIR$/app/Http/Kernel.php" afterDir="false" />
<change beforePath="$PROJECT_DIR$/config/database.php" beforeDir="false" afterPath="$PROJECT_DIR$/config/database.php" afterDir="false" />
<change beforePath="$PROJECT_DIR$/routes/api.php" beforeDir="false" afterPath="$PROJECT_DIR$/routes/api.php" afterDir="false" />
<change beforePath="$PROJECT_DIR$/routes/web.php" beforeDir="false" afterPath="$PROJECT_DIR$/routes/web.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" />
......@@ -188,7 +183,7 @@
<updated>1666170258203</updated>
<workItem from="1666170260162" duration="17108000" />
<workItem from="1666835076791" duration="693000" />
<workItem from="1667266026118" duration="8640000" />
<workItem from="1667266026118" duration="10293000" />
</task>
<servers />
</component>
......
......@@ -73,6 +73,7 @@ class AuthApiController extends Controller
public function resetPassword(Request $request)
{
$validator = Validator::make($request->all(), [
'old_password' => 'required|min:8',
'password' => ['required', 'string', 'min:8', 'confirmed'],
......@@ -85,15 +86,15 @@ class AuthApiController extends Controller
if ($validator->fails()) {
return $this->setError($validator->errors()->first());
}
$password = $request->get('password');
$match = User::where('password', Hash::make($request->get('old_password')))->exists();
if (!$match) {
$oldPassword = $request->get('old_password');
$userId = Auth::user()->id;
$hashedPassword = User::where('id', $userId)->value('password');
if (!Hash::check($oldPassword, $hashedPassword)) {
return $this->setError('Wrong Password!');
}
$user = new User();
$user = User::find($userId);
$user->password = Hash::make($password);
$user->update_time = time();
$result = $user->save();
......@@ -113,14 +114,14 @@ class AuthApiController extends Controller
return $this->setError('Email address required');
}
$info = User::where('email', $email)->first();
if ($info) {
if ($info && $type == 'register') {
return $this->setError('This email had been registered');
}
//发送验证码
$code = mt_rand(1000, 9999);
$redisKey = 'sem_email_code_' . $type;
Redis::hset($redisKey, $code);
$redisKey = 'sem_email_code_' . $type . '_' . $email;
Redis::set($redisKey, $code);
Redis::expire($redisKey, 60);
$subject = config('mail.from.name');
$msg = 'Email Code:' . $code . '.';
......
......@@ -22,8 +22,9 @@ Route::middleware(['api'])->namespace('Api')->group(function () {
Route::middleware(['api','api.check'])->namespace('Api')->group(function () {
Route::GET('/user/logout', 'AuthApiController@logout');
Route::Any('user/reset_password', 'AuthApiController@resetPassword');
Route::Any('user/send_email_code', 'AuthApiController@sendEmailCode');
});
Route::middleware(['api','api.check'])->namespace('Auth')->group(function () {
Route::Any('user/reset_password', 'ResetPasswordController@reset');
});
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