//login sucsesfull, the login principal , error message public async Task <(bool, ClaimsPrincipal, string)> TryLogin(string email, string pass) { (bool, ClaimsPrincipal, string)temp = (false, null, "none"); //TODO: ENCRYPT PASSWORD HERE var data = await collection.FindAsync(new BsonDocument(new List <BsonElement>() { new BsonElement("Email", email), new BsonElement("PasswordHash", PasswordHandeler.EncryptPassword(pass)), } )); if (data == null) { temp.Item3 = "Could not find your account, Please make sure you entered the right details."; return(temp); } var result = data.First(); if (!result.Validated) { //account not validated temp.Item3 = "Account not validated, please validate your account via the email sent."; return(temp); } try { var princ = GetPrinciple(result); temp.Item1 = true; temp.Item2 = princ; } catch { temp.Item3 = "Fatal error logging in. Please provide valid details"; } return(temp); }
public override async Task <bool> InsertRecord(PersonModel record) { //check if email exists..... bool emailExist = await CheckIfEmailExists(record.Email); if (!emailExist) { record.PasswordHash = PasswordHandeler.EncryptPassword(record.PasswordHash); //steps //create user await base.InsertRecord(record); //get user id var data = await GetUserByEmail(record.Email); //send email EmailSystem.SendEmail(GenerateMassage(record.Name, data._id.ToString()), record.Email); return(true); } return(false); }