|
@@ -154,7 +154,27 @@ class UserController extends Controller
|
|
{
|
|
{
|
|
$user = auth()->user();
|
|
$user = auth()->user();
|
|
if ($request->isMethod('POST')) {
|
|
if ($request->isMethod('POST')) {
|
|
|
|
+ // 检查用户是否开启了双重验证
|
|
|
|
+ if (!$user->google2fa_enable) {
|
|
|
|
+ // 如果用户未开启双重验证,重定向到双重验证设置页面
|
|
|
|
+ return redirect('/2fa')->withErrors('您必须先开启双重验证才能修改个人资料');
|
|
|
|
+ }
|
|
|
|
+
|
|
$oldPassword = $user->password;
|
|
$oldPassword = $user->password;
|
|
|
|
+
|
|
|
|
+ // 验证双重验证码
|
|
|
|
+ $data = $request->all();
|
|
|
|
+ if (!isset($data['code']) || empty($data['code'])) {
|
|
|
|
+ return Redirect::back()->withErrors('修改个人资料需要输入双重验证码');
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ $google2fa = new Google2FA();
|
|
|
|
+ $valid = $google2fa->verifyKey($user->google2fa_secret, $data['code']);
|
|
|
|
+
|
|
|
|
+ if (!$valid) {
|
|
|
|
+ return Redirect::back()->withErrors('双重验证码无效,请重试');
|
|
|
|
+ }
|
|
|
|
+
|
|
// 修改密码
|
|
// 修改密码
|
|
if ($request->has(['password', 'new_password'])) {
|
|
if ($request->has(['password', 'new_password'])) {
|
|
$data = $request->only(['password', 'new_password', 'code']);
|
|
$data = $request->only(['password', 'new_password', 'code']);
|
|
@@ -171,21 +191,6 @@ class UserController extends Controller
|
|
if ($user->id === 1 && config('app.demo')) {
|
|
if ($user->id === 1 && config('app.demo')) {
|
|
return Redirect::back()->withErrors(trans('auth.password.reset.error.demo'));
|
|
return Redirect::back()->withErrors(trans('auth.password.reset.error.demo'));
|
|
}
|
|
}
|
|
-
|
|
|
|
- // 检查用户是否开启了双重验证
|
|
|
|
- if ($user->google2fa_enable) {
|
|
|
|
- // 验证双重验证码
|
|
|
|
- if (!isset($data['code']) || empty($data['code'])) {
|
|
|
|
- return Redirect::back()->withErrors('修改密码需要输入双重验证码');
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- $google2fa = new Google2FA();
|
|
|
|
- $valid = $google2fa->verifyKey($user->google2fa_secret, $data['code']);
|
|
|
|
-
|
|
|
|
- if (!$valid) {
|
|
|
|
- return Redirect::back()->withErrors('双重验证码无效,请重试');
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
|
|
|
|
if (! $user->update(['password' => $data['new_password']])) {
|
|
if (! $user->update(['password' => $data['new_password']])) {
|
|
return Redirect::back()->withErrors(trans('common.update_action', ['action' => trans('common.failed')]));
|
|
return Redirect::back()->withErrors(trans('common.update_action', ['action' => trans('common.failed')]));
|
|
@@ -207,23 +212,7 @@ class UserController extends Controller
|
|
|
|
|
|
// 修改联系方式
|
|
// 修改联系方式
|
|
if ($request->has(['email','username', 'wechat', 'qq'])) {
|
|
if ($request->has(['email','username', 'wechat', 'qq'])) {
|
|
- //ol_emil
|
|
|
|
$data = $request->only(['newemail','email','username', 'wechat', 'qq', 'code']);
|
|
$data = $request->only(['newemail','email','username', 'wechat', 'qq', 'code']);
|
|
-
|
|
|
|
- // 检查用户是否开启了双重验证
|
|
|
|
- if ($user->google2fa_enable) {
|
|
|
|
- // 验证双重验证码
|
|
|
|
- if (!isset($data['code']) || empty($data['code'])) {
|
|
|
|
- return Redirect::back()->withErrors('修改邮箱需要输入双重验证码');
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- $google2fa = new Google2FA();
|
|
|
|
- $valid = $google2fa->verifyKey($user->google2fa_secret, $data['code']);
|
|
|
|
-
|
|
|
|
- if (!$valid) {
|
|
|
|
- return Redirect::back()->withErrors('双重验证码无效,请重试');
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
|
|
|
|
$email = $data['newemail'];
|
|
$email = $data['newemail'];
|
|
$pattern = "/^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/";
|
|
$pattern = "/^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/";
|
|
@@ -232,12 +221,10 @@ class UserController extends Controller
|
|
return Redirect::back()->withErrors(trans('common.update_action', ['action' => trans('common.error_email')]));
|
|
return Redirect::back()->withErrors(trans('common.update_action', ['action' => trans('common.error_email')]));
|
|
}
|
|
}
|
|
|
|
|
|
- if ( User::where('email', $data['newemail'])->count() >= 1) {
|
|
|
|
|
|
+ if (User::where('email', $data['newemail'])->count() >= 1) {
|
|
return Redirect::back()->withErrors(trans('common.update_action', ['action' => trans('common.failed_email')]));
|
|
return Redirect::back()->withErrors(trans('common.update_action', ['action' => trans('common.failed_email')]));
|
|
}
|
|
}
|
|
-// if (empty($data['qq'])) {
|
|
|
|
-// return Redirect::back()->withErrors(trans('validation.required', ['attribute' => trans('validation.attributes.qq')]));
|
|
|
|
-// }
|
|
|
|
|
|
+
|
|
if (empty($data['username'])) {
|
|
if (empty($data['username'])) {
|
|
return Redirect::back()->withErrors(trans('validation.required', ['attribute' => trans('validation.attributes.username')]));
|
|
return Redirect::back()->withErrors(trans('validation.required', ['attribute' => trans('validation.attributes.username')]));
|
|
}
|
|
}
|
|
@@ -248,22 +235,15 @@ class UserController extends Controller
|
|
'qq' => $data['qq'],
|
|
'qq' => $data['qq'],
|
|
'ol_emil' => $data['email'],
|
|
'ol_emil' => $data['email'],
|
|
];
|
|
];
|
|
-// var_dump($newData); die();
|
|
|
|
-// $data['old_email'] = $data['email'];
|
|
|
|
-// $data['email'] = $data['newemail'];
|
|
|
|
-// var_dump($data);
|
|
|
|
-// die();
|
|
|
|
|
|
+
|
|
if (! $user->update($newData)) {
|
|
if (! $user->update($newData)) {
|
|
return Redirect::back()->withErrors(trans('common.update_action', ['action' => trans('common.failed')]));
|
|
return Redirect::back()->withErrors(trans('common.update_action', ['action' => trans('common.failed')]));
|
|
}
|
|
}
|
|
|
|
|
|
Helpers::addEmailLog($user->id,$data['email'],$data['newemail']);
|
|
Helpers::addEmailLog($user->id,$data['email'],$data['newemail']);
|
|
|
|
|
|
|
|
+ return Redirect::back()->with('successMsg', trans('common.update_action', ['action' => trans('common.success')]));
|
|
}
|
|
}
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
- return Redirect::back()->with('successMsg', trans('common.update_action', ['action' => trans('common.success')]));
|
|
|
|
}
|
|
}
|
|
|
|
|
|
return view('user.profile');
|
|
return view('user.profile');
|