2018-09-06 17:46:38 +00:00
|
|
|
<template>
|
2018-11-01 21:34:29 +00:00
|
|
|
<div>
|
2019-10-19 14:27:56 +00:00
|
|
|
<h2 class="title has-text-centered">Login</h2>
|
2018-11-01 21:34:29 +00:00
|
|
|
<div class="box">
|
2018-11-01 22:58:59 +00:00
|
|
|
<div v-if="confirmedEmailSuccess" class="notification is-success has-text-centered">
|
|
|
|
You successfully confirmed your email! You can log in now.
|
|
|
|
</div>
|
2018-11-01 21:34:29 +00:00
|
|
|
<form id="loginform" @submit.prevent="submit">
|
|
|
|
<div class="field">
|
2019-10-19 14:27:56 +00:00
|
|
|
<label class="label" for="username">Username</label>
|
2018-11-01 21:34:29 +00:00
|
|
|
<div class="control">
|
2020-04-02 19:53:18 +00:00
|
|
|
<input v-focus type="text" id="username" class="input" name="username" placeholder="e.g. frederick" ref="username" required/>
|
2018-09-06 18:15:49 +00:00
|
|
|
</div>
|
2018-11-01 21:34:29 +00:00
|
|
|
</div>
|
|
|
|
<div class="field">
|
2019-10-19 14:27:56 +00:00
|
|
|
<label class="label" for="password">Password</label>
|
2018-11-01 21:34:29 +00:00
|
|
|
<div class="control">
|
2020-04-02 19:53:18 +00:00
|
|
|
<input type="password" class="input" id="password" name="password" placeholder="e.g. ••••••••••••" ref="password" required/>
|
2018-09-06 18:15:49 +00:00
|
|
|
</div>
|
2018-11-01 21:34:29 +00:00
|
|
|
</div>
|
2020-04-17 23:46:07 +00:00
|
|
|
<div class="field" v-if="needsTotpPasscode">
|
|
|
|
<label class="label" for="totpPasscode">Two Factor Authentication Code</label>
|
|
|
|
<div class="control">
|
|
|
|
<input type="text" class="input" id="totpPasscode" placeholder="e.g. 123456" ref="totpPasscode" required v-focus/>
|
|
|
|
</div>
|
|
|
|
</div>
|
2018-09-06 18:15:49 +00:00
|
|
|
|
2018-11-01 21:34:29 +00:00
|
|
|
<div class="field is-grouped">
|
|
|
|
<div class="control">
|
|
|
|
<button type="submit" class="button is-primary" v-bind:class="{ 'is-loading': loading}">Login</button>
|
|
|
|
<router-link :to="{ name: 'register' }" class="button">Register</router-link>
|
|
|
|
<router-link :to="{ name: 'getPasswordReset' }" class="reset-password-link">Reset your password</router-link>
|
2018-09-06 18:15:49 +00:00
|
|
|
</div>
|
2018-11-01 21:34:29 +00:00
|
|
|
</div>
|
2020-01-31 15:33:14 +00:00
|
|
|
<div class="notification is-danger" v-if="errorMsg">
|
|
|
|
{{ errorMsg }}
|
2018-11-01 21:34:29 +00:00
|
|
|
</div>
|
|
|
|
</form>
|
2018-09-06 18:15:49 +00:00
|
|
|
</div>
|
2018-09-06 17:46:38 +00:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
2019-03-02 10:25:10 +00:00
|
|
|
import auth from '../../auth'
|
|
|
|
import router from '../../router'
|
|
|
|
import {HTTP} from '../../http-common'
|
2018-11-27 10:23:50 +00:00
|
|
|
import message from '../../message'
|
2018-09-06 17:46:38 +00:00
|
|
|
|
2019-03-02 10:25:10 +00:00
|
|
|
export default {
|
|
|
|
data() {
|
|
|
|
return {
|
2020-01-31 15:33:14 +00:00
|
|
|
errorMsg: '',
|
2019-03-02 10:25:10 +00:00
|
|
|
confirmedEmailSuccess: false,
|
2020-04-17 23:46:07 +00:00
|
|
|
loading: false,
|
|
|
|
needsTotpPasscode: false,
|
2019-03-02 10:25:10 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
beforeMount() {
|
|
|
|
// Try to verify the email
|
|
|
|
// FIXME: Why is this here? Can we find a better place for this?
|
2018-11-01 22:58:59 +00:00
|
|
|
let emailVerifyToken = localStorage.getItem('emailConfirmToken')
|
2018-11-06 09:39:54 +00:00
|
|
|
if (emailVerifyToken) {
|
2018-11-27 10:23:50 +00:00
|
|
|
const cancel = message.setLoading(this)
|
2018-11-01 22:58:59 +00:00
|
|
|
HTTP.post(`user/confirm`, {token: emailVerifyToken})
|
|
|
|
.then(() => {
|
2019-03-02 10:25:10 +00:00
|
|
|
localStorage.removeItem('emailConfirmToken')
|
|
|
|
this.confirmedEmailSuccess = true
|
|
|
|
cancel()
|
|
|
|
})
|
|
|
|
.catch(e => {
|
2018-11-27 10:23:50 +00:00
|
|
|
cancel()
|
2020-01-31 15:33:14 +00:00
|
|
|
this.errorMsg = e.response.data.message
|
2019-03-02 10:25:10 +00:00
|
|
|
})
|
2018-11-01 22:58:59 +00:00
|
|
|
}
|
|
|
|
|
2019-03-02 10:25:10 +00:00
|
|
|
// Check if the user is already logged in, if so, redirect him to the homepage
|
|
|
|
if (auth.user.authenticated) {
|
|
|
|
router.push({name: 'home'})
|
|
|
|
}
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
submit() {
|
|
|
|
this.loading = true
|
2020-01-31 15:33:14 +00:00
|
|
|
this.errorMsg = ''
|
2020-04-02 19:53:18 +00:00
|
|
|
// Some browsers prevent Vue bindings from working with autofilled values.
|
|
|
|
// To work around this, we're manually getting the values here instead of relying on vue bindings.
|
|
|
|
// For more info, see https://kolaente.dev/vikunja/frontend/issues/78
|
|
|
|
const credentials = {
|
|
|
|
username: this.$refs.username.value,
|
|
|
|
password: this.$refs.password.value,
|
2019-03-02 10:25:10 +00:00
|
|
|
}
|
2018-09-06 17:46:38 +00:00
|
|
|
|
2020-04-17 23:46:07 +00:00
|
|
|
if(this.needsTotpPasscode) {
|
|
|
|
credentials.totpPasscode = this.$refs.totpPasscode.value
|
|
|
|
}
|
|
|
|
|
2019-03-02 10:25:10 +00:00
|
|
|
auth.login(this, credentials, 'home')
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-09-06 17:46:38 +00:00
|
|
|
</script>
|
|
|
|
|
|
|
|
<style scoped>
|
2018-09-08 20:27:13 +00:00
|
|
|
.button {
|
|
|
|
margin: 0 0.4em 0 0;
|
|
|
|
}
|
2018-11-01 21:34:29 +00:00
|
|
|
|
|
|
|
.reset-password-link{
|
|
|
|
display: inline-block;
|
|
|
|
padding-top: 5px;
|
|
|
|
}
|
2018-09-06 17:46:38 +00:00
|
|
|
</style>
|