Skip to content

Commit fce394f

Browse files
committed
Change email handling and logout function
1 parent ca0c35b commit fce394f

File tree

6 files changed

+18
-42
lines changed

6 files changed

+18
-42
lines changed

app/Http/Controllers/Api/Client/AccountController.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,17 +40,15 @@ public function index(Request $request): array
4040
/**
4141
* Update the authenticated user's email address if their password matches.
4242
*
43-
* @param UpdateEmailRequest $request
43+
* @param \Pterodactyl\Http\Requests\Api\Client\Account\UpdateEmailRequest $request
4444
* @return array
4545
*
4646
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
4747
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
4848
*/
4949
public function updateEmail(UpdateEmailRequest $request): array
5050
{
51-
$updated = $this->updateService->handle($request->user(), [
52-
'email' => $request->input('email'),
53-
]);
51+
$updated = $this->updateService->handle($request->user(), $request->validated());
5452

5553
return $this->fractal->item($updated->get('model'))
5654
->transformWith($this->getTransformer(AccountTransformer::class))

app/Http/Requests/Api/Client/Account/UpdateEmailRequest.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,6 @@ public function rules(): array
3434
{
3535
$rules = User::getUpdateRulesForId($this->user()->id);
3636

37-
return [
38-
'email' => $rules['email'],
39-
'password' => array_merge($rules['password'], ['confirmed']),
40-
];
37+
return ['email' => $rules['email']];
4138
}
4239
}

resources/assets/scripts/components/core/Navigation.vue

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
</a>
2424
</li>
2525
<li>
26-
<a :href="this.route('auth.logout')">
26+
<a :href="this.route('auth.logout')" v-on:click.prevent="doLogout">
2727
<log-out-icon aria-label="Sign out"/>
2828
</a>
2929
</li>
@@ -37,6 +37,12 @@
3737
3838
export default {
3939
name: 'navigation',
40-
components: { LogOutIcon, ServerIcon, SettingsIcon, UserIcon }
40+
components: { LogOutIcon, ServerIcon, SettingsIcon, UserIcon },
41+
methods: {
42+
doLogout: function () {
43+
this.$store.commit('auth/logout');
44+
return window.location = this.route('auth.logout');
45+
},
46+
}
4147
};
4248
</script>

resources/assets/scripts/components/dashboard/account/UpdateEmail.vue

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,6 @@
1616
v-model="password"
1717
>
1818
</div>
19-
<div class="mt-6">
20-
<label for="grid-password-confirm" class="input-label">Confirm password</label>
21-
<input id="grid-password-confirm" name="password_confirmation" type="password" class="input" required
22-
v-model="confirm"
23-
>
24-
</div>
2519
<div class="mt-6 text-right">
2620
<button class="btn btn-blue btn-sm text-right" type="submit">Save</button>
2721
</div>
@@ -31,6 +25,7 @@
3125
</template>
3226

3327
<script>
28+
import _ from 'lodash';
3429
import { mapState, mapActions } from 'vuex';
3530
3631
export default {
@@ -39,7 +34,6 @@
3934
return {
4035
email: '',
4136
password: '',
42-
confirm: '',
4337
};
4438
},
4539
computed: {
@@ -56,11 +50,11 @@
5650
this.clearFlashes();
5751
this.updateEmail({
5852
email: this.$data.email,
59-
password: this.$data.password,
60-
confirm: this.$data.confirm,
53+
password: this.$data.password
6154
})
6255
.then(() => {
6356
this.success('Your email address has been updated.');
57+
this.$data.password = '';
6458
})
6559
.catch(error => {
6660
if (!error.response) {

resources/assets/scripts/store/modules/auth.js

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import User from './../../models/user';
2+
23
const route = require('./../../../../../vendor/tightenco/ziggy/src/js/route').default;
34

45
export default {
@@ -56,37 +57,17 @@ export default {
5657
});
5758
},
5859

59-
/**
60-
* Log a user out of the Panel.
61-
*
62-
* @param commit
63-
* @returns {Promise<any>}
64-
*/
65-
logout: function ({commit}) {
66-
return new Promise((resolve, reject) => {
67-
window.axios.get(route('auth.logout'))
68-
.then(() => {
69-
commit('logout');
70-
return resolve();
71-
})
72-
.catch(reject);
73-
})
74-
},
75-
7660
/**
7761
* Update a user's email address on the Panel and store the updated result in Vuex.
7862
*
7963
* @param commit
8064
* @param {String} email
8165
* @param {String} password
82-
* @param {String} confirm
8366
* @return {Promise<any>}
8467
*/
85-
updateEmail: function ({commit}, {email, password, confirm}) {
68+
updateEmail: function ({commit}, {email, password}) {
8669
return new Promise((resolve, reject) => {
87-
window.axios.put(route('api.client.account.update-email'), {
88-
email, password, password_confirmation: confirm
89-
})
70+
window.axios.put(route('api.client.account.update-email'), {email, password})
9071
.then(response => {
9172
// If there is a 302 redirect or some other odd behavior (basically, response that isnt
9273
// in JSON format) throw an error and don't try to continue with the login.

routes/auth.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
| Endpoint: /auth
99
|
1010
*/
11-
Route::group([], function () {
11+
Route::group(['middleware' => 'guest'], function () {
1212
// These routes are defined so that we can continue to reference them programatically.
1313
// They all route to the same controller function which passes off to Vuejs.
1414
Route::get('/login', 'LoginController@index')->name('auth.login');

0 commit comments

Comments
 (0)