public IActionResult ForgotYourPassword(IFormCollection form) { if (User.Identity.IsAuthenticated) { return(RedirectToAction("Index", "Home")); } string strEmail = Convert.ToString(form["email"]); LoginState state = IsRegistered(strEmail, ""); if (state == LoginState.EMAIL_NOTFOUND || state == LoginState.CONNECTION_FAILED) { ViewData["FYP-Message-Error"] = state.GetMessage(); ViewData["FYP-Message"] = ""; ViewData["fyp-initial-display"] = "block"; ViewData["initial-email-fyp"] = strEmail; return(View("Login")); } else { SendFYPEmail(strEmail); ViewData["FYP-Message"] = "Password renovada. <br>Verifique a sua caixa de correio."; ViewData["FYP-Message-Error"] = ""; ViewData["fyp-initial-display"] = "block"; return(View("Login")); } }
public async Task <IActionResult> Login(LoginViewModel model) { string strEmail = model.Email; string strPassword = model.Password; if (ModelState.IsValid) { LoginState state = IsRegistered(strEmail, strPassword); if (state == LoginState.EMAIL_NOTFOUND || state == LoginState.CONNECTION_FAILED || state == LoginState.WRONG_PASSWORD) //Email não encontrado, ou password inválida { ViewData["Login-Message"] = state.GetMessage(); ViewData["Got-Error"] = "true"; } else { var claims = new List <Claim> { new Claim(ClaimTypes.Name, strEmail), new Claim(ClaimTypes.Role, "Mentor"), }; var claimsIdentity = new ClaimsIdentity(claims, CookieAuthenticationDefaults.AuthenticationScheme); var principal = new ClaimsPrincipal(claimsIdentity); await HttpContext.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme, principal); return(RedirectToAction("Index", "BackOffice")); } } return(RedirectToAction("Index", "Home")); }
public async Task <IActionResult> Login(LoginViewModel model) { string strEmail = model.Email; string strPassword = model.Password; if (ModelState.IsValid) { LoginState state = IsRegistered(strEmail, strPassword); if (state == LoginState.EMAIL_NOTFOUND || state == LoginState.CONNECTION_FAILED || state == LoginState.WRONG_PASSWORD) { ViewData["Login-Message"] = state.GetMessage(); ViewData["fyp-initial-display"] = "none"; ViewData["initial-email"] = strEmail; return(View("Login")); } else { string strAccountId = AccountID(strEmail); var identity = new ClaimsIdentity(CookieAuthenticationDefaults.AuthenticationScheme, ClaimTypes.Name, ClaimTypes.Role); identity.AddClaim(new Claim(ClaimTypes.NameIdentifier, strAccountId)); identity.AddClaim(new Claim(ClaimTypes.Name, AccountName(strAccountId))); if (state == LoginState.CONNECTED_STUDENT) { identity.AddClaim(new Claim(ClaimTypes.Role, "estudante")); } else { if (IsAdmin(strAccountId) == "True") { identity.AddClaim(new Claim(ClaimTypes.Role, "tecnico_admin")); } else { identity.AddClaim(new Claim(ClaimTypes.Role, "tecnico")); } } var principal = new ClaimsPrincipal(identity); await HttpContext.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme, principal, new AuthenticationProperties { IsPersistent = model.RememberMe }); return(RedirectToAction("Index", "Home")); } } ViewData["initial-email"] = strEmail; return(View(model)); }