Change email handling and logout function
This commit is contained in:
parent
ca0c35bf82
commit
fce394f6bd
6 changed files with 18 additions and 42 deletions
|
@ -40,7 +40,7 @@ class AccountController extends ClientApiController
|
||||||
/**
|
/**
|
||||||
* Update the authenticated user's email address if their password matches.
|
* Update the authenticated user's email address if their password matches.
|
||||||
*
|
*
|
||||||
* @param UpdateEmailRequest $request
|
* @param \Pterodactyl\Http\Requests\Api\Client\Account\UpdateEmailRequest $request
|
||||||
* @return array
|
* @return array
|
||||||
*
|
*
|
||||||
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
|
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
|
||||||
|
@ -48,9 +48,7 @@ class AccountController extends ClientApiController
|
||||||
*/
|
*/
|
||||||
public function updateEmail(UpdateEmailRequest $request): array
|
public function updateEmail(UpdateEmailRequest $request): array
|
||||||
{
|
{
|
||||||
$updated = $this->updateService->handle($request->user(), [
|
$updated = $this->updateService->handle($request->user(), $request->validated());
|
||||||
'email' => $request->input('email'),
|
|
||||||
]);
|
|
||||||
|
|
||||||
return $this->fractal->item($updated->get('model'))
|
return $this->fractal->item($updated->get('model'))
|
||||||
->transformWith($this->getTransformer(AccountTransformer::class))
|
->transformWith($this->getTransformer(AccountTransformer::class))
|
||||||
|
|
|
@ -34,9 +34,6 @@ class UpdateEmailRequest extends ClientApiRequest
|
||||||
{
|
{
|
||||||
$rules = User::getUpdateRulesForId($this->user()->id);
|
$rules = User::getUpdateRulesForId($this->user()->id);
|
||||||
|
|
||||||
return [
|
return ['email' => $rules['email']];
|
||||||
'email' => $rules['email'],
|
|
||||||
'password' => array_merge($rules['password'], ['confirmed']),
|
|
||||||
];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,7 +23,7 @@
|
||||||
</a>
|
</a>
|
||||||
</li>
|
</li>
|
||||||
<li>
|
<li>
|
||||||
<a :href="this.route('auth.logout')">
|
<a :href="this.route('auth.logout')" v-on:click.prevent="doLogout">
|
||||||
<log-out-icon aria-label="Sign out"/>
|
<log-out-icon aria-label="Sign out"/>
|
||||||
</a>
|
</a>
|
||||||
</li>
|
</li>
|
||||||
|
@ -37,6 +37,12 @@
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'navigation',
|
name: 'navigation',
|
||||||
components: { LogOutIcon, ServerIcon, SettingsIcon, UserIcon }
|
components: { LogOutIcon, ServerIcon, SettingsIcon, UserIcon },
|
||||||
|
methods: {
|
||||||
|
doLogout: function () {
|
||||||
|
this.$store.commit('auth/logout');
|
||||||
|
return window.location = this.route('auth.logout');
|
||||||
|
},
|
||||||
|
}
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
|
@ -16,12 +16,6 @@
|
||||||
v-model="password"
|
v-model="password"
|
||||||
>
|
>
|
||||||
</div>
|
</div>
|
||||||
<div class="mt-6">
|
|
||||||
<label for="grid-password-confirm" class="input-label">Confirm password</label>
|
|
||||||
<input id="grid-password-confirm" name="password_confirmation" type="password" class="input" required
|
|
||||||
v-model="confirm"
|
|
||||||
>
|
|
||||||
</div>
|
|
||||||
<div class="mt-6 text-right">
|
<div class="mt-6 text-right">
|
||||||
<button class="btn btn-blue btn-sm text-right" type="submit">Save</button>
|
<button class="btn btn-blue btn-sm text-right" type="submit">Save</button>
|
||||||
</div>
|
</div>
|
||||||
|
@ -31,6 +25,7 @@
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
import _ from 'lodash';
|
||||||
import { mapState, mapActions } from 'vuex';
|
import { mapState, mapActions } from 'vuex';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
|
@ -39,7 +34,6 @@
|
||||||
return {
|
return {
|
||||||
email: '',
|
email: '',
|
||||||
password: '',
|
password: '',
|
||||||
confirm: '',
|
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
|
@ -56,11 +50,11 @@
|
||||||
this.clearFlashes();
|
this.clearFlashes();
|
||||||
this.updateEmail({
|
this.updateEmail({
|
||||||
email: this.$data.email,
|
email: this.$data.email,
|
||||||
password: this.$data.password,
|
password: this.$data.password
|
||||||
confirm: this.$data.confirm,
|
|
||||||
})
|
})
|
||||||
.then(() => {
|
.then(() => {
|
||||||
this.success('Your email address has been updated.');
|
this.success('Your email address has been updated.');
|
||||||
|
this.$data.password = '';
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
if (!error.response) {
|
if (!error.response) {
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import User from './../../models/user';
|
import User from './../../models/user';
|
||||||
|
|
||||||
const route = require('./../../../../../vendor/tightenco/ziggy/src/js/route').default;
|
const route = require('./../../../../../vendor/tightenco/ziggy/src/js/route').default;
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
|
@ -56,37 +57,17 @@ export default {
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
|
||||||
* Log a user out of the Panel.
|
|
||||||
*
|
|
||||||
* @param commit
|
|
||||||
* @returns {Promise<any>}
|
|
||||||
*/
|
|
||||||
logout: function ({commit}) {
|
|
||||||
return new Promise((resolve, reject) => {
|
|
||||||
window.axios.get(route('auth.logout'))
|
|
||||||
.then(() => {
|
|
||||||
commit('logout');
|
|
||||||
return resolve();
|
|
||||||
})
|
|
||||||
.catch(reject);
|
|
||||||
})
|
|
||||||
},
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Update a user's email address on the Panel and store the updated result in Vuex.
|
* Update a user's email address on the Panel and store the updated result in Vuex.
|
||||||
*
|
*
|
||||||
* @param commit
|
* @param commit
|
||||||
* @param {String} email
|
* @param {String} email
|
||||||
* @param {String} password
|
* @param {String} password
|
||||||
* @param {String} confirm
|
|
||||||
* @return {Promise<any>}
|
* @return {Promise<any>}
|
||||||
*/
|
*/
|
||||||
updateEmail: function ({commit}, {email, password, confirm}) {
|
updateEmail: function ({commit}, {email, password}) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
window.axios.put(route('api.client.account.update-email'), {
|
window.axios.put(route('api.client.account.update-email'), {email, password})
|
||||||
email, password, password_confirmation: confirm
|
|
||||||
})
|
|
||||||
.then(response => {
|
.then(response => {
|
||||||
// If there is a 302 redirect or some other odd behavior (basically, response that isnt
|
// If there is a 302 redirect or some other odd behavior (basically, response that isnt
|
||||||
// in JSON format) throw an error and don't try to continue with the login.
|
// in JSON format) throw an error and don't try to continue with the login.
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
| Endpoint: /auth
|
| Endpoint: /auth
|
||||||
|
|
|
|
||||||
*/
|
*/
|
||||||
Route::group([], function () {
|
Route::group(['middleware' => 'guest'], function () {
|
||||||
// These routes are defined so that we can continue to reference them programatically.
|
// These routes are defined so that we can continue to reference them programatically.
|
||||||
// They all route to the same controller function which passes off to Vuejs.
|
// They all route to the same controller function which passes off to Vuejs.
|
||||||
Route::get('/login', 'LoginController@index')->name('auth.login');
|
Route::get('/login', 'LoginController@index')->name('auth.login');
|
||||||
|
|
Loading…
Reference in a new issue