Merge pull request #149 from SquidFerry/hotfix/password

fix:change password
This commit is contained in:
tokumeikoi 2020-04-05 15:18:28 +08:00 committed by GitHub
commit b2c33cd31b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 32 additions and 7 deletions

View File

@ -4,6 +4,7 @@ namespace App\Http\Controllers\User;
use App\Http\Controllers\Controller; use App\Http\Controllers\Controller;
use App\Http\Requests\User\UserUpdate; use App\Http\Requests\User\UserUpdate;
use App\Http\Requests\User\UserChangePassword;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use App\Models\User; use App\Models\User;
use App\Models\Plan; use App\Models\Plan;
@ -23,14 +24,8 @@ class UserController extends Controller
]); ]);
} }
public function changePassword(Request $request) public function changePassword(UserChangePassword $request)
{ {
if (empty($request->input('old_password'))) {
abort(500, '旧密码不能为空');
}
if (empty($request->input('new_password'))) {
abort(500, '新密码不能为空');
}
$user = User::find($request->session()->get('id')); $user = User::find($request->session()->get('id'));
if (!Helper::multiPasswordVerify( if (!Helper::multiPasswordVerify(
$user->password_algo, $user->password_algo,

View File

@ -0,0 +1,30 @@
<?php
namespace App\Http\Requests\User;
use Illuminate\Foundation\Http\FormRequest;
class UserChangePassword extends FormRequest
{
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
'old_password' => 'required',
'new_password' => 'required|min:8'
];
}
public function messages()
{
return [
'old_password.required' => '旧密码不能为空',
'new_password.required' => '新密码不能为空',
'new_password.min' => '密码必须大于8位数'
];
}
}