Login OK!
This commit is contained in:
@@ -60,6 +60,7 @@
|
||||
import * as types from '../../../store/mutation-types'
|
||||
|
||||
import {Errori_MongoDb} from '../../../store/modules/user'
|
||||
import {serv_constants} from "../../../store/modules/serv_constants";
|
||||
import axios from 'axios';
|
||||
|
||||
|
||||
@@ -116,7 +117,7 @@
|
||||
//console.log("RIS = " + riscode);
|
||||
if (riscode === Errori_MongoDb.OK) {
|
||||
this.$router.push('/');
|
||||
}else if (riscode === Errori_MongoDb.ERR_LOGIN_ERRATO) {
|
||||
}else if (riscode === serv_constants.RIS_CODE_LOGIN_ERR) {
|
||||
this.$q.notify(this.$t('login.errato'));
|
||||
this.$router.push('/signin');
|
||||
} else {
|
||||
@@ -136,11 +137,6 @@
|
||||
this.signin(this.form)
|
||||
.then((riscode) => {
|
||||
this.checkErrors(riscode);
|
||||
if (riscode === Errori_MongoDb.OK){
|
||||
this.$router.push('/');
|
||||
}else{
|
||||
this.$router.push('/signin');
|
||||
}
|
||||
}).catch(error => {
|
||||
console.log("ERROR = " + error);
|
||||
});
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
export const serv_constants = {
|
||||
RIS_CODE_EMAIL_ALREADY_VERIFIED: -20,
|
||||
RIS_CODE_EMAIL_ALREADY_VERIFIED: -5,
|
||||
RIS_CODE_EMAIL_VERIFIED: 1,
|
||||
|
||||
RIS_CODE_LOGIN_ERR_GENERIC: -20,
|
||||
RIS_CODE_LOGIN_ERR: -10,
|
||||
RIS_CODE_LOGIN_OK: 1,
|
||||
};
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
import Vue from 'vue'
|
||||
import Vuex from 'vuex'
|
||||
|
||||
import md5 from 'js-md5';
|
||||
|
||||
const bcrypt = require('bcryptjs');
|
||||
var bcrypt = require('bcryptjs');
|
||||
|
||||
Vue.use(Vuex);
|
||||
|
||||
@@ -23,7 +22,6 @@ export const Errori_MongoDb = {
|
||||
CALLING: 10,
|
||||
OK: 20,
|
||||
ERR_GENERICO: -1,
|
||||
ERR_LOGIN_ERRATO: -10,
|
||||
DUPLICATE_EMAIL_ID: 11000,
|
||||
DUPLICATE_USERNAME_ID: 11100
|
||||
};
|
||||
@@ -50,6 +48,7 @@ export const state = {
|
||||
servercode: 0,
|
||||
idToken: 0,
|
||||
userId: 0,
|
||||
username: '',
|
||||
};
|
||||
|
||||
function sendRequest(url, method, mydata) {
|
||||
@@ -71,12 +70,13 @@ function sendRequest(url, method, mydata) {
|
||||
|
||||
export const getters = {
|
||||
getUser: state => state.user,
|
||||
getUsername: state => state.user.username,
|
||||
getPassword: state => state.user.password,
|
||||
getDateOfBirth: state => state.user.dateofbirth,
|
||||
getUserServer: state => state.user.userServer,
|
||||
getServerCode: state => state.servercode,
|
||||
getLang: state => state.user.lang,
|
||||
|
||||
getUsername: state => state.username,
|
||||
};
|
||||
|
||||
|
||||
@@ -84,9 +84,6 @@ export const mutations = {
|
||||
[types.USER_REC]: (state, payload) => {
|
||||
state.user = payload;
|
||||
},
|
||||
[types.USER_USERNAME]: (state, payload) => {
|
||||
state.user.username = payload;
|
||||
},
|
||||
[types.USER_PASSWORD]: (state, payload) => {
|
||||
state.user.password = payload;
|
||||
},
|
||||
@@ -100,10 +97,15 @@ export const mutations = {
|
||||
state.user.dateOfBirth = payload;
|
||||
},
|
||||
|
||||
authUser(state, email, userid, mytoken) {
|
||||
state.user.tokens.push({access: "auth", token: mytoken});
|
||||
state.idToken = mytoken;
|
||||
[types.USER_USERNAME]: (state, payload) => {
|
||||
state.username = payload;
|
||||
},
|
||||
|
||||
authUser(state, username, userid, mytoken) {
|
||||
state.username = username;
|
||||
state.userId = userid;
|
||||
state.idToken = mytoken;
|
||||
state.user.tokens.push({access: "auth", token: mytoken});
|
||||
},
|
||||
setUser(state, user) {
|
||||
state.userServer = user
|
||||
@@ -183,12 +185,12 @@ export const actions = {
|
||||
var call = process.env.MONGODB_HOST + '/users';
|
||||
console.log("CALL " + call);
|
||||
|
||||
console.log("MYLANG = " + getlang());
|
||||
console.log("PASSW: " + authData.password);
|
||||
|
||||
bcrypt.genSalt(10, (err, salt) => {
|
||||
return bcrypt
|
||||
.hash(authData.password, salt)
|
||||
bcrypt
|
||||
.hash(authData.password, bcrypt.genSaltSync(12))
|
||||
.then(hashedPassword => {
|
||||
console.log("NEW hashedPassword = " + hashedPassword);
|
||||
let usertosend = {
|
||||
keyappid: process.env.PAO_APP_ID,
|
||||
lang: getlang(),
|
||||
@@ -204,19 +206,15 @@ export const actions = {
|
||||
|
||||
commit('setServerCode', Errori_MongoDb.CALLING);
|
||||
|
||||
var x_auth_token = null;
|
||||
|
||||
return sendRequest(call, "POST", usertosend)
|
||||
.then((res) => {
|
||||
console.log("HEADERS:");
|
||||
|
||||
for (let header of res.headers) {
|
||||
console.log(header);
|
||||
}
|
||||
|
||||
x_auth_token = res.headers.get('x-auth');
|
||||
myres = res;
|
||||
var x_auth_token = res.headers.get('x-auth');
|
||||
if (x_auth_token) {
|
||||
return res.json();
|
||||
} else {
|
||||
return {status: 400, code: Errori_MongoDb.ERR_GENERICO}
|
||||
}
|
||||
})
|
||||
.then((body) => {
|
||||
if (process.env.DEV) {
|
||||
@@ -231,17 +229,17 @@ export const actions = {
|
||||
|
||||
if (myres.status === 200) {
|
||||
var iduser = body._id;
|
||||
var email = body.email;
|
||||
var username = authData.username;
|
||||
if (process.env.DEV) {
|
||||
console.log("EMAIL = " + body.email);
|
||||
console.log("USERNAME = " + username);
|
||||
console.log("IDUSER= " + iduser);
|
||||
commit('authUser', email, iduser, x_auth_token);
|
||||
commit('authUser', username, iduser, x_auth_token);
|
||||
}
|
||||
|
||||
const now = new Date();
|
||||
//const expirationDate = new Date(now.getTime() + myres.data.expiresIn * 1000);
|
||||
const expirationDate = new Date(now.getTime() + 1000);
|
||||
localStorage.setItem('username', authData.username);
|
||||
localStorage.setItem('username', username);
|
||||
localStorage.setItem('token', x_auth_token);
|
||||
localStorage.setItem('userId', iduser);
|
||||
localStorage.setItem('expirationDate', expirationDate);
|
||||
@@ -270,7 +268,6 @@ export const actions = {
|
||||
return Errori_MongoDb.ERR_GENERICO;
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
},
|
||||
[types.USER_SIGNIN]: ({commit}, authData) => {
|
||||
@@ -279,14 +276,11 @@ export const actions = {
|
||||
|
||||
console.log("MYLANG = " + getlang());
|
||||
|
||||
bcrypt.genSalt(10, (err, salt) => {
|
||||
return bcrypt
|
||||
.hash(authData.password, salt)
|
||||
.then(hashedPassword => {
|
||||
console.log("PASSW: " + authData.password);
|
||||
|
||||
const usertosend = {
|
||||
username: authData.username,
|
||||
password: hashedPassword,
|
||||
password: authData.password,
|
||||
idapp: process.env.APP_ID,
|
||||
keyappid: process.env.PAO_APP_ID,
|
||||
lang: getlang(),
|
||||
@@ -303,7 +297,14 @@ export const actions = {
|
||||
return sendRequest(call, "POST", usertosend)
|
||||
.then((res) => {
|
||||
myres = res;
|
||||
return res.json();
|
||||
x_auth_token = res.headers.get('x-auth');
|
||||
var injson = res.json();
|
||||
|
||||
if (x_auth_token || injson) {
|
||||
return injson;
|
||||
} else {
|
||||
return {status: 400, code: Errori_MongoDb.ERR_GENERICO}
|
||||
}
|
||||
})
|
||||
.then((body) => {
|
||||
if (process.env.DEV) {
|
||||
@@ -314,27 +315,25 @@ export const actions = {
|
||||
}
|
||||
|
||||
if (body.code === serv_constants.RIS_CODE_LOGIN_ERR) {
|
||||
commit('setServerCode', Errori_MongoDb.ERR_LOGIN_ERRATO);
|
||||
return Errori_MongoDb.ERR_LOGIN_ERRATO;
|
||||
commit('setServerCode', body.code);
|
||||
return body.code;
|
||||
}
|
||||
|
||||
x_auth_token = body.token;
|
||||
|
||||
commit('setServerCode', myres);
|
||||
|
||||
if (myres.status === 200) {
|
||||
var iduser = body._id;
|
||||
var email = body.email;
|
||||
var username = authData.username;
|
||||
if (process.env.DEV) {
|
||||
console.log("EMAIL = " + email);
|
||||
console.log("USERNAME = " + username);
|
||||
console.log("IDUSER= " + iduser);
|
||||
commit('authUser', '', iduser, x_auth_token);
|
||||
commit('authUser', username, iduser, x_auth_token);
|
||||
}
|
||||
|
||||
const now = new Date();
|
||||
//const expirationDate = new Date(now.getTime() + myres.data.expiresIn * 1000);
|
||||
const expirationDate = new Date(now.getTime() + 1000);
|
||||
localStorage.setItem('username', authData.username);
|
||||
localStorage.setItem('username', username);
|
||||
localStorage.setItem('token', x_auth_token);
|
||||
localStorage.setItem('userId', iduser);
|
||||
localStorage.setItem('expirationDate', expirationDate);
|
||||
@@ -363,8 +362,6 @@ export const actions = {
|
||||
commit('setServerCode', Errori_MongoDb.ERR_GENERICO);
|
||||
return Errori_MongoDb.ERR_GENERICO;
|
||||
});
|
||||
});
|
||||
});
|
||||
},
|
||||
[types.USER_AUTOLOGIN]: ({commit}) => {
|
||||
const token = localStorage.getItem('token');
|
||||
@@ -380,8 +377,8 @@ export const actions = {
|
||||
const username = localStorage.getItem('username');
|
||||
commit('authUser', {
|
||||
username: username,
|
||||
userId: userId,
|
||||
token: token,
|
||||
userId: userId
|
||||
})
|
||||
},
|
||||
[types.USER_LOGOUT]: ({commit}) => {
|
||||
|
||||
Reference in New Issue
Block a user