diff options
author | Julius Härtl <jus@bitgrid.net> | 2019-07-25 18:04:33 +0300 |
---|---|---|
committer | Julius Härtl <jus@bitgrid.net> | 2019-07-31 10:19:07 +0300 |
commit | 3b0d13944a966930731d3cb9a0216236420796c5 (patch) | |
tree | 05b6e7a694b77568984fd7087a58935a68517942 /core/src | |
parent | 57f2ea22c784d7b2c3bbabc6b616b9afc6c5ff3c (diff) |
Move actual password reset to vue
Signed-off-by: Julius Härtl <jus@bitgrid.net>
Diffstat (limited to 'core/src')
-rw-r--r-- | core/src/components/login/UpdatePassword.vue | 139 | ||||
-rw-r--r-- | core/src/login.js | 2 | ||||
-rw-r--r-- | core/src/views/Login.vue | 18 |
3 files changed, 158 insertions, 1 deletions
diff --git a/core/src/components/login/UpdatePassword.vue b/core/src/components/login/UpdatePassword.vue new file mode 100644 index 00000000000..5ee01772df7 --- /dev/null +++ b/core/src/components/login/UpdatePassword.vue @@ -0,0 +1,139 @@ +<!-- + - @copyright Copyright (c) 2019 Julius Härtl <jus@bitgrid.net> + - + - @author Julius Härtl <jus@bitgrid.net> + - + - @license GNU AGPL version 3 or any later version + - + - This program is free software: you can redistribute it and/or modify + - it under the terms of the GNU Affero General Public License as + - published by the Free Software Foundation, either version 3 of the + - License, or (at your option) any later version. + - + - This program is distributed in the hope that it will be useful, + - but WITHOUT ANY WARRANTY; without even the implied warranty of + - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + - GNU Affero General Public License for more details. + - + - You should have received a copy of the GNU Affero General Public License + - along with this program. If not, see <http://www.gnu.org/licenses/>. + - + --> + +<template> + <form @submit.prevent="submit"> + <fieldset> + <p> + <label for="password" class="infield">{{ t('core', 'New password') }}</label> + <input type="password" name="password" + id="password" v-model="password" required + :placeholder="t('core', 'New password')" /> + </p> + + <div v-if="encrypted" class="update"> + <p> + {{ t('core', 'Your files are encrypted. There will be no way to get your data back after your password is reset. If you are not sure what to do, please contact your administrator before you continue. Do you really want to continue?') }} + </p> + <input type="checkbox" class="checkbox" + id="encrypted-continue" v-model="proceed" /> + <label for="encrypted-continue"> + {{ t('core', 'I know what I\'m doing') }} + </label> + </div> + + <div id="submit-wrapper"> + <input type="submit" + id="submit" + class="login primary" + title="" + :value="!loading ? t('core', 'Reset password') : t('core', 'Resetting password')" /> + <div class="submit-icon" :class="{ + 'icon-loading-small': loading && invertedColors, + 'icon-loading-small-dark': loading && !invertedColors + }"></div> + </div> + + <p v-if="error && message" :class="{warning: error}"> + {{ message }} + </p> + </fieldset> + </form> +</template> + +<script> + import Axios from 'nextcloud-axios' + + export default { + name: 'UpdatePassword', + props: { + username: { + type: String, + required: true, + }, + resetPasswordTarget: { + type: String, + required: true, + }, + invertedColors: { + type: Boolean, + default: false, + } + }, + data() { + return { + error: false, + loading: false, + message: undefined, + user: this.username, + password: '', + encrypted: false, + proceed: false + } + }, + watch: { + username (value) { + this.user = value + } + }, + methods: { + async submit () { + this.loading = true + this.error = false + this.message = '' + + try { + const { data } = await Axios.post(this.resetPasswordTarget, { + password: this.user, + proceed: this.proceed + }) + if (data && data.status === 'success') { + this.message = 'send-success' + this.$emit('update:username', this.user) + this.$emit('done') + } else if (data && data.encryption) { + this.encrypted = true + } else if (data && data.msg) { + throw new Error(data.msg) + } else { + throw new Error() + } + } catch (e) { + this.error = true + this.message = e.message ? e.message : t('core', 'Password can not be changed. Please contact your administrator.') + } finally { + this.loading = false + } + } + }, + } +</script> + +<style scoped> + fieldset { + text-align: center; + } + + input[type=submit] { + margin-top: 20px; + } +</style> diff --git a/core/src/login.js b/core/src/login.js index c537f6e7811..12f3a896308 100644 --- a/core/src/login.js +++ b/core/src/login.js @@ -59,5 +59,7 @@ new View({ canResetPassword: fromStateOr('loginCanResetPassword', false), resetPasswordLink: fromStateOr('loginResetPasswordLink', ''), autoCompleteAllowed: fromStateOr('loginAutocomplete', true), + resetPasswordTarget: fromStateOr('resetPasswordTarget', ''), + resetPasswordUser: fromStateOr('resetPasswordUser', ''), } }).$mount('#login'); diff --git a/core/src/views/Login.vue b/core/src/views/Login.vue index efe1d721776..d1127e05f95 100644 --- a/core/src/views/Login.vue +++ b/core/src/views/Login.vue @@ -22,7 +22,7 @@ <template> <div> <transition name="fade" mode="out-in"> - <div v-if="!resetPassword" + <div v-if="!resetPassword && resetPasswordTarget === ''" key="login"> <LoginForm :username.sync="user" @@ -56,6 +56,12 @@ @abort="resetPassword = false"/> </div> </div> + <div v-else-if="resetPasswordTarget !== ''"> + <UpdatePassword :username.sync="user" + :reset-password-target="resetPasswordTarget" + :inverted-colors="invertedColors" + @done="passwordResetFinished"/> + </div> </transition> </div> </template> @@ -63,6 +69,7 @@ <script> import LoginForm from '../components/login/LoginForm.vue' import ResetPassword from '../components/login/ResetPassword.vue' + import UpdatePassword from '../components/login/UpdatePassword.vue' export default { name: 'Login', @@ -92,6 +99,9 @@ resetPasswordLink: { type: String, }, + resetPasswordTarget: { + type: String, + }, invertedColors: { type: Boolean, default: false, @@ -104,6 +114,7 @@ components: { LoginForm, ResetPassword, + UpdatePassword, }, data () { return { @@ -111,6 +122,11 @@ user: this.username, resetPassword: false, } + }, + methods: { + passwordResetFinished() { + this.resetPasswordTarget = '' + } } } </script> |