feat: add remember me style login #1339

Merged
konrad merged 3 commits from feature/long-tokens into main 2022-02-06 13:17:56 +00:00
3 changed files with 12 additions and 11 deletions

View File

@ -56,7 +56,8 @@
"showPassword": "Show the password", "showPassword": "Show the password",
"hidePassword": "Hide the password", "hidePassword": "Hide the password",
"noAccountYet": "Don't have an account yet?", "noAccountYet": "Don't have an account yet?",
"alreadyHaveAnAccount": "Already have an account?" "alreadyHaveAnAccount": "Already have an account?",
"remember": "Stay logged in"
}, },
"settings": { "settings": {
"title": "Settings", "title": "Settings",

View File

@ -1,5 +1,6 @@
import {HTTPFactory} from '@/http-common' import {HTTPFactory} from '@/http-common'
import {i18n, getCurrentLanguage, saveLanguage} from '@/i18n' import {i18n, getCurrentLanguage, saveLanguage} from '@/i18n'
import {objectToSnakeCase} from '@/helpers/case'
konrad marked this conversation as resolved Outdated

Use @

Use `@`

Done!

Done!
import {LOADING} from '../mutation-types' import {LOADING} from '../mutation-types'
import UserModel from '@/models/user' import UserModel from '@/models/user'
import UserSettingsService from '@/services/userSettings' import UserSettingsService from '@/services/userSettings'
@ -90,17 +91,8 @@ export default {
// Delete an eventually preexisting old token // Delete an eventually preexisting old token
removeToken() removeToken()
const data = {
username: credentials.username,
password: credentials.password,
}
if (credentials.totpPasscode) {
data.totp_passcode = credentials.totpPasscode
}
try { try {
const response = await HTTP.post('login', data) const response = await HTTP.post('login', objectToSnakeCase(credentials))
// Save the token to local storage for later use // Save the token to local storage for later use
konrad marked this conversation as resolved Outdated

Why dont we simply convert credentials to snakecase for this object?

		async login(ctx, credentials) {
			const HTTP = HTTPFactory()
			ctx.commit(LOADING, true, {root: true})

			// Delete an eventually preexisting old token
			removeToken()

			try {
				const response = await HTTP.post('login', objectToSnakeCase(credentials))
Why dont we simply convert credentials to snakecase for this object? ```js async login(ctx, credentials) { const HTTP = HTTPFactory() ctx.commit(LOADING, true, {root: true}) // Delete an eventually preexisting old token removeToken() try { const response = await HTTP.post('login', objectToSnakeCase(credentials)) ```

Very good point! I've changed it accordingly.

Very good point! I've changed it accordingly.
saveToken(response.data.token, true) saveToken(response.data.token, true)

View File

@ -58,6 +58,12 @@
/> />
</div> </div>
</div> </div>
<div class="field">
<label class="label">
<input type="checkbox" v-model="rememberMe" class="mr-1"/>
{{ $t('user.auth.remember') }}
</label>
</div>
<x-button <x-button
@click="submit" @click="submit"
@ -118,6 +124,7 @@ export default {
usernameValid: true, usernameValid: true,
password: '', password: '',
validatePasswordInitially: false, validatePasswordInitially: false,
rememberMe: false,
} }
}, },
beforeMount() { beforeMount() {
@ -197,6 +204,7 @@ export default {
const credentials = { const credentials = {
username: this.$refs.username.value, username: this.$refs.username.value,
password: this.password, password: this.password,
longToken: this.rememberMe,
} }
if (credentials.username === '' || credentials.password === '') { if (credentials.username === '' || credentials.password === '') {