1
0
Merge branch 'master' into feature/vuex

Cleanup

Move namespaces handling to store

Move fullpage setting to store

Move online/offline handling to store

Remove debug log

Fix loading namepaces

Rename errorMsg

Handle registering through the store

Use store to determine wether or not a user is authenticated on login page

Use store in edit team

Use store to get the current user's avatar

Use store to figure out if the current user belongs to a team

Use store to figure out if the current user is list admin

Use store to get user info when listing labels

Use store to get username on home

Use store to figure out if the user is namespace admin

Use the store for configuration

Use the store to check if a user is authenticated everywhere

Only renew token if the user is logged in

Fix renewing auth from jwt token

Move logout to store

Move renew token to store

Move log in to store

Only show enabled migrators

Only show registration button if registration is enabled

Put all config information from the backend in the store

Remove old config handler

Move config state to seperate module

Add vuex and get the motd through it

Co-authored-by: kolaente <k@knt.li>
Reviewed-on: https://kolaente.dev/vikunja/frontend/pulls/126
This commit is contained in:
konrad
2020-05-08 18:43:51 +00:00
parent 2ba6b7ef3a
commit 5724b98358
31 changed files with 501 additions and 393 deletions

View File

@ -9,31 +9,61 @@
<div class="field">
<label class="label" for="username">Username</label>
<div class="control">
<input v-focus type="text" id="username" class="input" name="username" placeholder="e.g. frederick" ref="username" required/>
<input
v-focus type="text"
id="username"
class="input"
name="username"
placeholder="e.g. frederick"
ref="username"
required
/>
</div>
</div>
<div class="field">
<label class="label" for="password">Password</label>
<div class="control">
<input type="password" class="input" id="password" name="password" placeholder="e.g. ••••••••••••" ref="password" required/>
<input
type="password"
class="input"
id="password"
name="password"
placeholder="e.g. ••••••••••••"
ref="password"
required
/>
</div>
</div>
<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/>
<input
type="text"
class="input"
id="totpPasscode"
placeholder="e.g. 123456"
ref="totpPasscode"
required
v-focus
/>
</div>
</div>
<div class="field is-grouped">
<div class="control is-expanded">
<button type="submit" class="button is-primary" v-bind:class="{ 'is-loading': loading}">Login
</button>
<router-link :to="{ name: 'register' }" class="button" v-if="registrationEnabled">Register
</router-link>
</div>
<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>
<router-link :to="{ name: 'getPasswordReset' }" class="reset-password-link">Reset your
password
</router-link>
</div>
</div>
<div class="notification is-danger" v-if="errorMsg">
{{ errorMsg }}
<div class="notification is-danger" v-if="errorMessage">
{{ errorMessage }}
</div>
</form>
</div>
@ -41,18 +71,17 @@
</template>
<script>
import auth from '../../auth'
import {mapState} from 'vuex'
import router from '../../router'
import {HTTP} from '../../http-common'
import message from '../../message'
import {ERROR_MESSAGE, LOADING} from '../../store/mutation-types'
export default {
data() {
return {
errorMsg: '',
confirmedEmailSuccess: false,
loading: false,
needsTotpPasscode: false,
}
},
beforeMount() {
@ -69,19 +98,25 @@
})
.catch(e => {
cancel()
this.errorMsg = e.response.data.message
this.$store.commit(ERROR_MESSAGE, e.response.data.message)
})
}
// Check if the user is already logged in, if so, redirect him to the homepage
if (auth.user.authenticated) {
if (this.authenticated) {
router.push({name: 'home'})
}
},
computed: mapState({
registrationEnabled: state => state.config.registrationEnabled,
loading: LOADING,
errorMessage: ERROR_MESSAGE,
needsTotpPasscode: state => state.auth.needsTotpPasscode,
authenticated: state => state.auth.authenticated,
}),
methods: {
submit() {
this.loading = true
this.errorMsg = ''
this.$store.commit(ERROR_MESSAGE, '')
// 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
@ -90,11 +125,15 @@
password: this.$refs.password.value,
}
if(this.needsTotpPasscode) {
if (this.needsTotpPasscode) {
credentials.totpPasscode = this.$refs.totpPasscode.value
}
auth.login(this, credentials, 'home')
this.$store.dispatch('auth/login', credentials)
.then(() => {
router.push({name: 'home'})
})
.catch(() => {})
}
}
}
@ -105,7 +144,7 @@
margin: 0 0.4em 0 0;
}
.reset-password-link{
.reset-password-link {
display: inline-block;
padding-top: 5px;
}

View File

@ -37,8 +37,8 @@
<div class="notification is-info" v-if="loading">
Loading...
</div>
<div class="notification is-danger" v-if="errorMsg !== ''">
{{ errorMsg }}
<div class="notification is-danger" v-if="errorMessage !== ''">
{{ errorMessage }}
</div>
</form>
</div>
@ -46,8 +46,9 @@
</template>
<script>
import auth from '../../auth'
import router from '../../router'
import {mapState} from 'vuex'
import {ERROR_MESSAGE, LOADING} from '../../store/mutation-types'
export default {
data() {
@ -58,35 +59,37 @@
password: '',
password2: '',
},
errorMsg: '',
loading: false
}
},
beforeMount() {
// Check if the user is already logged in, if so, redirect him to the homepage
if (auth.user.authenticated) {
if (this.authenticated) {
router.push({name: 'home'})
}
},
computed: mapState({
authenticated: state => state.auth.authenticated,
loading: LOADING,
errorMessage: ERROR_MESSAGE,
}),
methods: {
submit() {
this.loading = true
this.errorMsg = ''
this.$store.commit(LOADING, true)
this.$store.commit(ERROR_MESSAGE, '')
if (this.credentials.password2 !== this.credentials.password) {
this.loading = false
this.errorMsg = 'Passwords don\'t match.'
this.$store.commit(ERROR_MESSAGE, 'Passwords don\'t match.')
this.$store.commit(LOADING, false)
return
}
let credentials = {
const credentials = {
username: this.credentials.username,
email: this.credentials.email,
password: this.credentials.password
}
auth.register(this, credentials, 'home')
this.$store.dispatch('auth/register', credentials)
}
}
}