diff --git a/.idea/php.xml b/.idea/php.xml deleted file mode 100644 index d29ced6..0000000 --- a/.idea/php.xml +++ /dev/null @@ -1,34 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/workspace.xml b/.idea/workspace.xml deleted file mode 100644 index b76164b..0000000 --- a/.idea/workspace.xml +++ /dev/null @@ -1,65 +0,0 @@ - - - - - - - $PROJECT_DIR$/webman/composer.json - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 1741661680676 - - - - - - \ No newline at end of file diff --git a/app/controller/UserController.php b/app/controller/UserController.php index 89b8943..8a472f3 100644 --- a/app/controller/UserController.php +++ b/app/controller/UserController.php @@ -169,6 +169,81 @@ class UserController } } + /** + * 修改 + * @param Request $request + * @return \support\Response + * @throws \Random\RandomException + */ + public function save(Request $request) + { + $name = Util::getParam($request, 'name'); + $sex = Util::getParam($request, 'sex'); + $position = Util::getParam($request, 'position'); + $country_id = Util::getParam($request, 'country_id'); + $sign = Util::getParam($request, 'sign'); + $id = $request->user['id']; + + $data = [ + 'name' => $name, + 'sex' => $sex, + 'position' => $position, + 'country_id' => $country_id, + 'sign' => $sign, + ]; + + $res = User::where('id', $id) + ->update($data); + + if ($res) { + return Util::success($res, trans('save_success')); + } else { + return Util::fail($res, trans('save_fail')); + } + } + + /** + * 修改 + * @param Request $request + * @return \support\Response + * @throws \Random\RandomException + */ + public function savePassword(Request $request) + { + $password = Util::getParam($request, 'password'); + $email = Util::getParam($request, 'email'); + $code = Util::getParam($request, 'code'); + $verification_code = Redis::get("verification_code:{$email}"); + $id = $request->user['id']; + + if ($code != $verification_code) { + return Util::fail([], trans('code_error')); + } + + $res = User::where('id', $id) + ->first(); + if($res['email'] != $email) { + return Util::fail([], trans('email_consistent')); + } + + //加密 +// $hashedPassword = password_hash($password, PASSWORD_DEFAULT); + $hashedPassword = password_hash($password, PASSWORD_DEFAULT); + + $data = [ + 'password' => $hashedPassword + ]; + + $res = User::where('id', $id) + ->update($data); + + if ($res) { + return Util::success($res, trans('save_success')); + } else { + return Util::fail($res, trans('save_fail')); + } + } + /** * 注册 * @param Request $request @@ -182,7 +257,7 @@ class UserController if (Util::isEmpty($language)) { return Util::fail([], 'language' . trans('not_null')); } - if (!in_array($language,['en','zh_CN'])) { + if (!in_array($language, ['en', 'zh_CN'])) { return Util::fail([], trans('param_error')); } $data = [ diff --git a/resource/translations/en/messages.php b/resource/translations/en/messages.php index f989337..a618b4d 100644 --- a/resource/translations/en/messages.php +++ b/resource/translations/en/messages.php @@ -22,4 +22,5 @@ return [ 'contacts_not_null' => ' Contact person, email, and phone cannot be empty at the same time', 'car_type_not_null' => ' preference_not_null', 'channel_not_null' => ' channel not null', + 'email_consistent' => ' Inconsistent email addresses', ]; \ No newline at end of file diff --git a/resource/translations/zh_CN/messages.php b/resource/translations/zh_CN/messages.php index f3d14b5..12f04cf 100644 --- a/resource/translations/zh_CN/messages.php +++ b/resource/translations/zh_CN/messages.php @@ -22,4 +22,5 @@ return [ 'contacts_not_null' => ' 联系人,邮箱,电话不能同时为空', 'car_type_not_null' => ' 偏好不能为空', 'channel_not_null' => ' 渠道不能为空', + 'email_consistent' => ' 邮箱不一致', ]; \ No newline at end of file