From 0cc895f2d53f05425ff81804222e3caa72e97618 Mon Sep 17 00:00:00 2001 From: Dane Everitt Date: Sun, 17 Jun 2018 16:53:24 -0700 Subject: [PATCH] Finalize email/password changing in UI --- .../Api/Client/AccountController.php | 30 ++++++-- .../Client/Account/UpdatePasswordRequest.php | 39 ++++++++++ package.json | 6 +- resources/assets/scripts/app.js | 2 + .../scripts/components/dashboard/Account.vue | 2 +- .../dashboard/account/ChangePassword.vue | 72 +++++++++++++++++-- .../dashboard/account/UpdateEmail.vue | 15 ++-- resources/assets/styles/components/forms.css | 10 ++- routes/api-client.php | 1 + yarn.lock | 4 ++ 10 files changed, 158 insertions(+), 23 deletions(-) create mode 100644 app/Http/Requests/Api/Client/Account/UpdatePasswordRequest.php diff --git a/app/Http/Controllers/Api/Client/AccountController.php b/app/Http/Controllers/Api/Client/AccountController.php index 84ec07e3a..965d01264 100644 --- a/app/Http/Controllers/Api/Client/AccountController.php +++ b/app/Http/Controllers/Api/Client/AccountController.php @@ -3,9 +3,11 @@ namespace Pterodactyl\Http\Controllers\Api\Client; use Illuminate\Http\Request; +use Illuminate\Http\Response; use Pterodactyl\Services\Users\UserUpdateService; use Pterodactyl\Transformers\Api\Client\AccountTransformer; use Pterodactyl\Http\Requests\Api\Client\Account\UpdateEmailRequest; +use Pterodactyl\Http\Requests\Api\Client\Account\UpdatePasswordRequest; class AccountController extends ClientApiController { @@ -38,20 +40,34 @@ class AccountController extends ClientApiController } /** - * Update the authenticated user's email address if their password matches. + * Update the authenticated user's email address. * * @param \Pterodactyl\Http\Requests\Api\Client\Account\UpdateEmailRequest $request - * @return array + * @return \Illuminate\Http\Response * * @throws \Pterodactyl\Exceptions\Model\DataValidationException * @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException */ - public function updateEmail(UpdateEmailRequest $request): array + public function updateEmail(UpdateEmailRequest $request): Response { - $updated = $this->updateService->handle($request->user(), $request->validated()); + $this->updateService->handle($request->user(), $request->validated()); - return $this->fractal->item($updated->get('model')) - ->transformWith($this->getTransformer(AccountTransformer::class)) - ->toArray(); + return response('', Response::HTTP_CREATED); + } + + /** + * Update the authenticated user's password. + * + * @param \Pterodactyl\Http\Requests\Api\Client\Account\UpdatePasswordRequest $request + * @return \Illuminate\Http\Response + * + * @throws \Pterodactyl\Exceptions\Model\DataValidationException + * @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException + */ + public function updatePassword(UpdatePasswordRequest $request): Response + { + $this->updateService->handle($request->user(), $request->validated()); + + return response('', Response::HTTP_CREATED); } } diff --git a/app/Http/Requests/Api/Client/Account/UpdatePasswordRequest.php b/app/Http/Requests/Api/Client/Account/UpdatePasswordRequest.php new file mode 100644 index 000000000..2fe368f8c --- /dev/null +++ b/app/Http/Requests/Api/Client/Account/UpdatePasswordRequest.php @@ -0,0 +1,39 @@ +input('current_password'), $this->user()->password)) { + throw new InvalidPasswordProvidedException(trans('base.account.invalid_password')); + } + + return true; + } + + /** + * @return array + */ + public function rules(): array + { + $rules = User::getUpdateRulesForId($this->user()->id); + + return ['password' => array_merge($rules['password'], ['confirmed'])]; + } +} diff --git a/package.json b/package.json index a727e3fa1..4e672967b 100644 --- a/package.json +++ b/package.json @@ -2,6 +2,7 @@ "name": "pterodactyl-panel", "dependencies": { "date-fns": "^1.29.0", + "vee-validate": "^2.1.0-beta.2", "vue": "^2.5.7", "vue-axios": "^2.1.1", "vue-router": "^3.0.1", @@ -57,7 +58,8 @@ "watch": "NODE_ENV=development ./node_modules/.bin/webpack --watch --progress", "build": "NODE_ENV=development ./node_modules/.bin/webpack --progress", "build:production": "NODE_ENV=production ./node_modules/.bin/webpack", - "serve": "NODE_ENV=development webpack-serve --hot --config ./webpack.config.js --no-clipboard", - "v:serve": "PUBLIC_PATH=http://192.168.50.2:8080 NODE_ENV=development webpack-serve --hot --config ./webpack.config.js --host 192.168.50.2 --no-clipboard" + "serve": "NODE_ENV=development webpack-serve --hot --config ./webpack.config.js --no-clipboard --progress", + "v:serve": "PUBLIC_PATH=http://192.168.50.2:8080 NODE_ENV=development webpack-serve --hot --config ./webpack.config.js --host 192.168.50.2 --no-clipboard", + "compile:assets": "php artisan vue-i18n:generate & php artisan ziggy:generate resources/assets/scripts/helpers/ziggy.js" } } diff --git a/resources/assets/scripts/app.js b/resources/assets/scripts/app.js index 6048cc5aa..044c392d2 100644 --- a/resources/assets/scripts/app.js +++ b/resources/assets/scripts/app.js @@ -2,6 +2,7 @@ import Vue from 'vue'; import Vuex from 'vuex'; import vuexI18n from 'vuex-i18n'; import VueRouter from 'vue-router'; +import VeeValidate from 'vee-validate'; Vue.config.productionTip = false; require('./bootstrap'); @@ -19,6 +20,7 @@ window.Ziggy = Ziggy; Vue.use(Vuex); Vue.use(VueRouter); Vue.use(vuexI18n.plugin, store); +Vue.use(VeeValidate); const route = require('./../../../vendor/tightenco/ziggy/src/js/route').default; diff --git a/resources/assets/scripts/components/dashboard/Account.vue b/resources/assets/scripts/components/dashboard/Account.vue index 8d8aa1dbb..c40a63b4f 100644 --- a/resources/assets/scripts/components/dashboard/Account.vue +++ b/resources/assets/scripts/components/dashboard/Account.vue @@ -5,7 +5,7 @@ - +
diff --git a/resources/assets/scripts/components/dashboard/account/ChangePassword.vue b/resources/assets/scripts/components/dashboard/account/ChangePassword.vue index c9f8944a7..d5793a07a 100644 --- a/resources/assets/scripts/components/dashboard/account/ChangePassword.vue +++ b/resources/assets/scripts/components/dashboard/account/ChangePassword.vue @@ -1,20 +1,34 @@ diff --git a/resources/assets/scripts/components/dashboard/account/UpdateEmail.vue b/resources/assets/scripts/components/dashboard/account/UpdateEmail.vue index 8ff9543a4..27a61b8de 100644 --- a/resources/assets/scripts/components/dashboard/account/UpdateEmail.vue +++ b/resources/assets/scripts/components/dashboard/account/UpdateEmail.vue @@ -6,9 +6,11 @@
-

If your email is no longer {{ user.email }} enter a new email in the field above.

+

{{ errors.first('email') }}

@@ -25,14 +27,14 @@