Add user email verification when registering (#3)

This commit is contained in:
konrad 2018-11-01 22:58:59 +00:00 committed by Gitea
parent 4a78a508df
commit 89023908b5
3 changed files with 29 additions and 2 deletions

View File

@ -105,6 +105,12 @@
localStorage.setItem('passwordResetToken', this.$route.query.userPasswordReset)
router.push({name: 'passwordReset'})
}
// Email verification
if(this.$route.query.userEmailConfirm !== undefined) {
localStorage.removeItem('emailConfirmToken') // Delete an eventually preexisting old token
localStorage.setItem('emailConfirmToken', this.$route.query.userEmailConfirm)
router.push({name: 'login'})
}
},
created() {
if (this.user.authenticated) {

View File

@ -2,6 +2,9 @@
<div>
<h2 class="title">Login</h2>
<div class="box">
<div v-if="confirmedEmailSuccess" class="notification is-success has-text-centered">
You successfully confirmed your email! You can log in now.
</div>
<form id="loginform" @submit.prevent="submit">
<div class="field">
<div class="control">
@ -32,6 +35,7 @@
<script>
import auth from '../../auth'
import router from '../../router'
import {HTTP} from '../../http-common'
export default {
data() {
@ -41,10 +45,27 @@
password: ''
},
error: '',
confirmedEmailSuccess: false,
loading: false
}
},
beforeMount() {
// Try to verify the email
let emailVerifyToken = localStorage.getItem('emailConfirmToken')
if (emailVerifyToken !== '') {
this.loading = true
HTTP.post(`user/confirm`, {token: emailVerifyToken})
.then(() => {
localStorage.removeItem('emailConfirmToken')
this.loading = false
this.confirmedEmailSuccess = true
})
.catch(e => {
this.loading = false
this.error = e.response.data.message
})
}
// Check if the user is already logged in, if so, redirect him to the homepage
if (auth.user.authenticated) {
router.push({name: 'home'})

View File

@ -59,6 +59,6 @@
* [ ] Google fonts raus (sollen von lokal geladen werden)
* [ ] Ladeanimationen erst nach 100ms anzeigen, sonst wird das überflüssigerweise angezeigt
* [ ] Userstuff
* [ ] Email-Verification
* [x] Userstuff
* [x] Email-Verification
* [x] Password forgot