public IActionResult Login(LoginForm loginForm) { if (!(loginForm is null) && ModelState.IsValid) { loginForm.Passwd = Convert.ToBase64String(_cryptoService.Crypter(loginForm.Passwd)); try { User user = _authRepository.Login(loginForm); if (!(user is null)) { SessionManager.User = user; return(RedirectToAction("Index", "Event")); } ViewBag.Message = "Incorrect Email or password !"; } catch (Exception ex) { return(View("Error")); } } return(View(loginForm.ToWeb())); }
public ActionResult EditPassword(G.Password form) { if (!(form is null) && ModelState.IsValid && (form.Passwd != form.NewPasswd)) { form.Passwd = Convert.ToBase64String(_cryptoService.Crypter(form.Passwd)); form.NewPasswd = Convert.ToBase64String(_cryptoService.Crypter(form.NewPasswd)); try { if (_apiTokenRequester.UpdateWithToken(form, "user/pwd/" + SessionManager.User.Id, SessionManager.User.Token)) { ViewBag.Message = "Password successfully changed"; return(RedirectToAction(nameof(Index))); } ViewBag.Message = "Wrong password"; return(View()); } catch { return(View("Error")); } } ViewBag.Message = "Old and new password can't be the same"; return(View()); }
public IActionResult Login(LoginForm form) { try { if (ModelState.IsValid) { // check if email or natreg as login User u = _iUserService.Login(form.Email, Convert.ToBase64String(_cryptoRSA.Crypter(form.Passwd))); // User u = _iUserService.Login(form.Email, Base64.Base64Encode(form.Passwd)); //else // User u = _iUserService.Login2("", Base64.Base64Encode(form.Passwd)); if (u is not null) { _sessionManager.User = new SessionUser() { Id = u.Id, LastName = u.LastName, FirstName = u.FirstName, Email = u.Email, NatRegNbr = u.NatRegNbr, UserStatus = u.UserStatus, Passwd = "", Token = u.Token }; return(RedirectToAction("Index", "TimeLine")); } ModelState.AddModelError("", "Email ou mot de passe invalide..."); } } catch (Exception ex) { _logger.LogError(ex.Message); ModelState.AddModelError("", "Une erreur est survenue"); //ViewBag.Error = ex.Message; } return(View()); }
public IActionResult Register(RegisterForm registerForm) { registerForm.Passwd = Convert.ToBase64String(_cryptoRSA.Crypter(registerForm.Passwd)); try { if (ModelState.IsValid) { _authRepository.Register(registerForm); return(RedirectToAction("Index", "Home")); } return(View(registerForm)); } catch (Exception ex) { return(View("Error")); } }