Browse Source

update login method

pull/342/head
Guillaume Vincent 8 years ago
parent
commit
1a8bfd5c29
4 changed files with 19 additions and 17 deletions
  1. +7
    -5
      src/components/Login.vue
  2. +2
    -2
      src/components/Menu.vue
  3. +1
    -0
      src/main.js
  4. +9
    -10
      src/store.js

+ 7
- 5
src/components/Login.vue View File

@@ -108,20 +108,22 @@
}, 3000); }, 3000);
}, },
login(){ login(){
if (!this.user.email || !this.user.password || !this.baseURL) {
var baseURL = this.baseURL;
var email = this.user.email;
if (!email || !this.user.password || !baseURL) {
this.showErrorMessage('email, password and url '); this.showErrorMessage('email, password and url ');
return; return;
} }
this.auth.login(this.user, this.baseURL)
this.auth.login(this.user, baseURL)
.then(()=> { .then(()=> {
this.storage.save({baseURL: this.baseURL});
this.$store.dispatch('userAuthenticated', {email: this.user.email});
this.storage.save({baseURL: baseURL, email: email});
this.$store.dispatch('userAuthenticated', {email: email});
this.$store.dispatch('go', 'index'); this.$store.dispatch('go', 'index');
this.$store.dispatch('loadPasswords'); this.$store.dispatch('loadPasswords');
}) })
.catch(err => { .catch(err => {
if (err.response === undefined) { if (err.response === undefined) {
if (this.baseURL === "https://lesspass.com") {
if (baseURL === "https://lesspass.com") {
this.showErrorMessage('LessPass Database is not running. Sorry for the inconvenience.'); this.showErrorMessage('LessPass Database is not running. Sorry for the inconvenience.');
} else { } else {
this.showErrorMessage('Your LessPass Database is not running'); this.showErrorMessage('Your LessPass Database is not running');


+ 2
- 2
src/components/Menu.vue View File

@@ -20,7 +20,7 @@
<div class="btn-group"> <div class="btn-group">
<button type="button" class="btn dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" <button type="button" class="btn dropdown-toggle" data-toggle="dropdown" aria-haspopup="true"
aria-expanded="false" style="background-color:transparent; padding:0;"> aria-expanded="false" style="background-color:transparent; padding:0;">
{{user.email}}
{{email}}
</button> </button>
<div class="dropdown-menu dropdown-menu-right"> <div class="dropdown-menu dropdown-menu-right">
<button class="dropdown-item" type="button" v-on:click="go('passwords')">Passwords</button> <button class="dropdown-item" type="button" v-on:click="go('passwords')">Passwords</button>
@@ -71,7 +71,7 @@
'page', 'page',
'isAuthenticated', 'isAuthenticated',
'isGuest', 'isGuest',
'user'
'email'
]) ])
} }
</script> </script>

+ 1
- 0
src/main.js View File

@@ -9,6 +9,7 @@ import Store from './store'
import Storage from './api/storage'; import Storage from './api/storage';


const storage = new Storage(); const storage = new Storage();
console.log(storage.json())
const store = Store(storage.json()); const store = Store(storage.json());


new Vue({ new Vue({


+ 9
- 10
src/store.js View File

@@ -12,9 +12,8 @@ const passwords = new HTTP('passwords', storage);


const state = { const state = {
page: 'index', page: 'index',
user: {
authenticated: auth.isAuthenticated()
},
authenticated: auth.isAuthenticated(),
email: '',
passwords: [], passwords: [],
currentPassword: {} currentPassword: {}
}; };
@@ -27,7 +26,7 @@ const mutations = {
state.page = page state.page = page
}, },
logout(state){ logout(state){
state.user = {authenticated: false};
state.authenticated = false;
state.page = 'login'; state.page = 'login';
state.currentPassword = { state.currentPassword = {
site: '', site: '',
@@ -44,8 +43,8 @@ const mutations = {
state.passwords = []; state.passwords = [];
}, },
userAuthenticated(state, user){ userAuthenticated(state, user){
state.user.authenticated = true;
state.user.email = user.email;
state.authenticated = true;
state.email = user.email;
}, },
loadPasswords(state, passwords){ loadPasswords(state, passwords){
state.passwords = passwords state.passwords = passwords
@@ -69,17 +68,17 @@ const actions = {


const getters = { const getters = {
page: state => state.page, page: state => state.page,
isAuthenticated: state => state.user.authenticated,
isGuest: state => !state.user.authenticated,
isAuthenticated: state => state.authenticated,
isGuest: state => !state.authenticated,
passwords: state => state.passwords, passwords: state => state.passwords,
currentPassword: state => state.currentPassword, currentPassword: state => state.currentPassword,
user: state => state.user,
email: state => state.email,
baseURL: state => state.baseURL baseURL: state => state.baseURL
}; };


export default function (config) { export default function (config) {
return new Vuex.Store({ return new Vuex.Store({
state: Object.assign(config, state),
state: Object.assign(state, config),
getters, getters,
actions, actions,
mutations mutations


Loading…
Cancel
Save