/// <summary> /// Verifies user credentials (Email and Password) and returns user's initial data. /// </summary> /// <param name="pEmail">Email</param> /// <param name="pPassword">Password</param> /// <param name="pDeviceInfo">Devices manufacturer, operative system, and version.</param> /// <param name="pDeviceIP">Client's IP address</param> /// <param name="pDeviceID">Device identification</param> /// <param name="pEncrypted">Determinates if password proveded is encrypted or not</param> /// <returns>Autehnticated person's initial data</returns> public PersonEN AuthenticatePerson(string pEmail, string pPassword, string pDeviceInfo, string pDeviceIP, string pDeviceID, bool pEncrypted) { PersonEN person = new PersonEN(); try { if (pEncrypted) { pPassword = Encrypt.DecryptStringAESVector2(pPassword); } var nepass = Encrypt.EncryptStringAES(pPassword); pPassword = nepass; var available = false; person = personDAL.AuthenticatePerson(pEmail, pPassword); if (person.RollID == 1 && person.CategoryID == 0) { available = true; } else if (person.RollID == 1 && person.CategoryID == 1) { available = true; } else if (person.RollID == 2 && person.CategoryID == 1) { available = true; } else if (person.RollID == 2 && person.CategoryID == 0) { available = true; } else { available = true; } if (person != null) { if ((available == false && !person.Active)) { EventViewerLoggerBL.LogInformation("Signin Person: HDM desactivado"); return(null); } else { person.TokenExpiration = DateTime.Now.AddHours(Constants.TokenLifetime); person.CurrentToken = jwt.encode(person); person.VendorM = (person.MasterID != 0) ? true : false; person.DeviceIp = pDeviceIP; person.DeviceInfo = pDeviceInfo; person.DeviceID = pDeviceID; int sessionID = sessionDAL.InsertAuthenticationLog(person.PersonID, person.DeviceIp, person.DeviceInfo, person.DeviceID, true, CentralAmericaDateTime(DateTime.Now)); person.SessionID = sessionID; ManageUserSessions(sessionID, person); //UserBag person.OperatorsBalance = bagDAL.GetUserOperatorBag(person.PersonID); if (person.ReferredStatus == 0) { personDAL.UpdatePersonReferredStatus(1, person.Email); } } } } catch (Exception ex) { person = null; //Console.WriteLine(ex.InnerException); EventViewerLoggerBL.LogError("AuthenticatePerson, Error: " + ex.StackTrace); } return(person); }