Skip to content
Snippets Groups Projects
Commit bd9461b0 authored by thomas craipeau's avatar thomas craipeau Committed by GitHub
Browse files

Merge pull request #107 from aboire/master

update login method
parents b6576245 ab4e3a77
No related branches found
No related tags found
No related merge requests found
......@@ -5,6 +5,7 @@ config.push.json
settings.json
settings-prod.json
electron-settings.json
electron-settings-prod.json
cordova.facebook.json
private/*
node_modules/
......@@ -71,6 +71,9 @@
"Invitations contacts":"Invitations contacts",
"Change location":"Change location",
"Search a city or postal code":"Search a city or postal code",
"accountPending":"You've been invited : please resume the registration process in order to log in.",
"betaTestNotOpen":"Our developpers are fighting to open soon ! Check your mail that will happen soon !",
"notValidatedEmail":"Your account is not validated : please check your mailbox to validate your email address.",
"Cities":"Villes",
"schemas":{
"followrest":{
......
......@@ -72,6 +72,9 @@
"Change location":"Changer de position",
"Search a city or postal code":"Rechercher une ville ou un code postal",
"Cities":"Villes",
"accountPending":"Vous avez été invité(e) : vous n'avez plus qu'à finir l'inscription pour vous connecter.",
"betaTestNotOpen":"Nos développeurs sont au taquet et ne dorment plus pour que la plateforme sorte bientôt ! Vérifiez votre boite aux lettres, ça arrive bientôt !",
"notValidatedEmail":"Votre compte n'est pas validé : un mail vous a été envoyé sur votre boite mail.",
"schemas":{
"followrest":{
"invitedUserName":{
......
......@@ -8,40 +8,58 @@ Accounts.registerLoginHandler(function(loginRequest) {
if(!loginRequest.email || !loginRequest.pwd) {
return null;
}
var pswdDigest = SHA256(loginRequest.email+loginRequest.pwd)
//var pswdDigest = CryptoJS.SHA256(loginRequest.email+loginRequest.pwd).toString();
var userId = null;
var userC = Citoyens.findOne({email: loginRequest.email,pwd:pswdDigest},{fields:{pwd:0}});
const response = HTTP.call( 'POST', Meteor.settings.endpoint+'/communecter/person/authenticate', {
params: {
"email": loginRequest.email,
"pwd": loginRequest.pwd,
}
});
//console.log(response);
if(response && response.data && response.data.result && response.data.id){
//var pswdDigest = SHA256(loginRequest.email+loginRequest.pwd)
//var pswdDigest = CryptoJS.SHA256(loginRequest.email+loginRequest.pwd).toString();
var userId = null;
//var userC = Citoyens.findOne({email: loginRequest.email,pwd:pswdDigest},{fields:{pwd:0}});
if(!userC) {
throw new Meteor.Error(Accounts.LoginCancelledError.numericError, 'Communecter Login Failed');;
} else {
//ok valide
var userM = Meteor.users.findOne({'_id':userC._id._str});
console.log(userM);
if(userM && userM.profile && userM.profile.pixelhumain){
//Meteor.user existe
userId= userM._id;
Meteor.users.update(userId,{$set: {'profile.pixelhumain': userC,emails:[userC.email]}});
var userC = Citoyens.findOne({ _id: new Mongo.ObjectID(response.data.id.$id) },{fields:{pwd:0}});
if(!userC) {
throw new Meteor.Error(Accounts.LoginCancelledError.numericError, 'Communecter Login Failed');
} else {
//ok valide
var userM = Meteor.users.findOne({'_id':userC._id._str});
console.log(userM);
if(userM && userM.profile && userM.profile.pixelhumain){
//Meteor.user existe
userId= userM._id;
Meteor.users.update(userId,{$set: {'profile.pixelhumain': userC,emails:[userC.email]}});
}else{
//Meteor.user n'existe pas
//username ou emails
userId = Meteor.users.insert({_id:userC._id._str,emails:[userC.email]});
Meteor.users.update(userId,{$set: {'profile.pixelhumain': userC}});
}
}
var stampedToken = Accounts._generateStampedLoginToken();
Meteor.users.update(userId,
{$push: {'services.resume.loginTokens': stampedToken}}
);
this.setUserId(userId);
console.log(userId);
return {
userId: userId,
token: stampedToken.token
}
}else{
//Meteor.user n'existe pas
//username ou emails
userId = Meteor.users.insert({_id:userC._id._str,emails:[userC.email]});
Meteor.users.update(userId,{$set: {'profile.pixelhumain': userC}});
}
}
if(response && response.data && response.data.result === false){
throw new Meteor.Error(Accounts.LoginCancelledError.numericError, 'Communecter Login Failed');
} else if(response && response.data && response.data.result === true && response.data.msg){
throw new Meteor.Error(response.data.msg);
}
var stampedToken = Accounts._generateStampedLoginToken();
Meteor.users.update(userId,
{$push: {'services.resume.loginTokens': stampedToken}}
);
this.setUserId(userId);
console.log(userId);
return {
userId: userId,
token: stampedToken.token
}
}
});
Push.debug = true;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment