public ActionResult Login(LoginViewModel model) { if (ModelState.IsValid) { var arg = new LoginArgument() { LoginId = model.LoginId, Password = model.Password }; var result = _userService.LoginByPassword(arg); if (result != null && result.UserId != 0) { IdentitySignin(new ApplicationState() { UserId = result.UserId, LoginId = result.LoginId, Email = result.Email, UserName = result.UserName }); return(RedirectToAction("Index", "Home")); } else { ModelState.AddModelError("invalid", message.LoginFaileMessage); return(View()); } } ModelState.AddModelError("invalid", message.FormInvalidMessage); return(View()); }
public UserDto LoginByPassword(LoginArgument arg) { return(new UserDto() { UserId = 1, LoginId = "admin", Email = "*****@*****.**", UserName = "******" }); }
public async Task <ActionResult <string> > Login([FromBody] LoginArgument argument) { User user = await UserRepo.GetByEmail(argument.email); if (user == null || !user.VerifyPassword(argument.password)) { return(Unauthorized()); } await UserRepo.SetNewSessionCookie(user); return(Ok(user.SessionCookie)); }