public async Task <IActionResult> OnPostLogIn() { try { // Verification. if (ModelState.IsValid) { // Initialization. bool loginInfo = await LoginManagement.LoginAsync(tempUser.Name, tempUser.Password); if (loginInfo) { HttpContext.Session.SetString("username", tempUser.Name); return(RedirectToPage("../Index")); } else { ModelState.AddModelError(string.Empty, "Invalid username or password."); } } } catch (Exception ex) { ModelState.AddModelError(string.Empty, ex.Message); } // Info. return(this.Page()); }
public async Task <IActionResult> OnPostAsync() { if (!ModelState.IsValid) { return(Page()); } _context.Users.Add(ModelUser); try { await _context.SaveChangesAsync(); if (!LoginManagement.TempUser.IsAdmin) { await LoginManagement.LoginAsync(ModelUser.Name, ModelUser.Password); } } catch (Exception ex) { ModelState.TryAddModelError("", ex.Message); return(Page()); } //todo: Redirect to previous Page return(RedirectToPage("/index")); }