[O] Move cookies detection to login class
This commit is contained in:
@@ -59,16 +59,6 @@ export default class App extends Vue
|
|||||||
{
|
{
|
||||||
// Show splash
|
// Show splash
|
||||||
console.log(Constants.SPLASH);
|
console.log(Constants.SPLASH);
|
||||||
|
|
||||||
// Check login cookies
|
|
||||||
if (this.$cookies.isKey('va.token'))
|
|
||||||
{
|
|
||||||
// Hide login
|
|
||||||
this.showLogin = false;
|
|
||||||
|
|
||||||
// Load data
|
|
||||||
this.loadAfterLogin();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -15,6 +15,19 @@ export default class Login extends Vue
|
|||||||
public loading: boolean = false;
|
public loading: boolean = false;
|
||||||
public error: String = '';
|
public error: String = '';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This is called when the instance is created.
|
||||||
|
*/
|
||||||
|
public created()
|
||||||
|
{
|
||||||
|
// Check login cookies
|
||||||
|
if (this.$cookies.isKey('va.token'))
|
||||||
|
{
|
||||||
|
// Already contains valid token / TODO: Validate
|
||||||
|
this.$emit('login:token', this.$cookies.get('va.token'));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* On click, sends username and password to the server.
|
* On click, sends username and password to the server.
|
||||||
*/
|
*/
|
||||||
@@ -37,7 +50,10 @@ export default class Login extends Vue
|
|||||||
// Check success
|
// Check success
|
||||||
if (response.success)
|
if (response.success)
|
||||||
{
|
{
|
||||||
// Call custom event with courses info
|
// Save token to cookies
|
||||||
|
this.$cookies.set('va.token', response.data, '7d');
|
||||||
|
|
||||||
|
// Call custom event with token
|
||||||
this.$emit('login:token', response.data);
|
this.$emit('login:token', response.data);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|||||||
Reference in New Issue
Block a user