示例#1
0
        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());
        }
示例#2
0
 public UserDto LoginByPassword(LoginArgument arg)
 {
     return(new UserDto()
     {
         UserId = 1,
         LoginId = "admin",
         Email = "*****@*****.**",
         UserName = "******"
     });
 }
示例#3
0
        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));
        }