public ActionResult ResetPassword(string token, string password) { if (!PPOKPrincipal.passwordComplexity(password)) { ViewBag.Error = "Password is not complex enough. Be sure to follow all the rules"; return(View()); } bool resetAdminPass = false, resetPharmacistPass = false; var sysAdmin = AuthService.VerifySystemAdminToken(token); var pharmacist = AuthService.VerifyPharmacistToken(token); if (sysAdmin != null) { resetAdminPass = AuthService.ResetSystemAdminPassword(token, sysAdmin, PPOKPrincipal.HashPassword(sysAdmin, password)); } if (pharmacist != null) { resetPharmacistPass = AuthService.ResetPharmacistPassword(token, pharmacist, PPOKPrincipal.HashPassword(pharmacist, password)); } if (resetAdminPass || resetPharmacistPass) { return(View("Index")); } ViewBag.Error = "That token was not correct. Try again"; return(View("ForgotPassword")); }
protected void Application_PostAuthenticateRequest(Object sender, EventArgs e) { if (FormsAuthentication.CookiesSupported == true) { if (Request.Cookies[FormsAuthentication.FormsCookieName] != null) { try { //get the username FormsAuthenticationTicket authTicket = FormsAuthentication.Decrypt(Request.Cookies[FormsAuthentication.FormsCookieName].Value); JavaScriptSerializer serializer = new JavaScriptSerializer(); PPOKPrincipalSerializeModel serializeModel = serializer.Deserialize <PPOKPrincipalSerializeModel>(authTicket.UserData); PPOKPrincipal newUser = new PPOKPrincipal(serializeModel.Email); switch (serializeModel.Type) { case AccountTypes.Pharmacist: case AccountTypes.Admin: using (var service = new PharmacistService()) { newUser = new PPOKPrincipal(service.Get(serializeModel.Code), serializeModel.Pharmacy.Code); } break; case AccountTypes.Patient: using (var service = new PatientService()) { newUser = new PPOKPrincipal(service.Get(serializeModel.Code)); } break; case AccountTypes.System: using (var service = new SystemAdminService()) { newUser = new PPOKPrincipal(service.Get(serializeModel.Code)); } break; } HttpContext.Current.User = newUser; } catch (Exception ex) { Console.WriteLine(ex.Message); //somehting went wrong } } } }
public ActionResult SendCode(int area, int prefix, int number) { string phone = "1" + area.ToString() + prefix.ToString() + number.ToString(); var patient = AuthService.SendPatientToken(phone, PPOKPrincipal.generateRandomCode(TOKEN_LENGTH)); if (patient != null) { makeAuthTicket(new PPOKPrincipalSerializeModel(patient)); return(View("VerifyCode")); } else { ViewBag.Error = "That number was not found in our system."; return(View("Patient")); } }
public ActionResult ForgotPassword(string email) { var pharmcist = AuthService.SendPharmacistToken(email, PPOKPrincipal.generateRandomCode(TOKEN_LENGTH)); if (pharmcist != null) { return(View("ResetPassword")); } var sysAdmin = AuthService.SendSystemAdminToken(email, PPOKPrincipal.generateRandomCode(TOKEN_LENGTH)); if (sysAdmin != null) { return(View("ResetPassword")); } ViewBag.Error = "That email was not found"; return(View()); }
public ActionResult Login(string email, string password) { if (PPOKPrincipal.IsValid(email, password)) { using (var PharmService = new PharmacistService()) using (var SysService = new SystemAdminService()) { Pharmacist pharmacist = PharmService.GetWhere(PharmacistService.EmailCol == email).FirstOrDefault(); SystemAdmin admin = SysService.GetWhere(SystemAdminService.EmailCol == email).FirstOrDefault(); var logins = new LoginModel(email); if (logins.pharmacyList.Count > 1) { if (admin != null) { makeAuthTicket(new PPOKPrincipalSerializeModel(admin)); } else { makeAuthTicket(new PPOKPrincipalSerializeModel(pharmacist)); } return(View("PharmacySelect", logins)); } else if (admin != null) { var serializedAdmin = new PPOKPrincipalSerializeModel(admin); makeAuthTicket(serializedAdmin); return(RedirectToAction("Index", "SystemAdmin")); } else if (pharmacist != null) { var serializedPharmacist = new PPOKPrincipalSerializeModel(pharmacist); makeAuthTicket(serializedPharmacist); return(RedirectToAction("Index", "LandingPage")); } } } ViewBag.Error = "Invalid username/password combination"; return(View("Index")); }