Exemple #1
0
        public async Task <IActionResult> Login([FromBody] LoginViewModel login)
        {
            var dbUser = await _userManager.FindByEmailAsync(login.Email);

            if (dbUser == null)
            {
                return(NotFound("Неверный адрес электронной почты"));
            }

            var isValid = await _userManager.CheckPasswordAsync(dbUser, login.Password);

            if (!isValid)
            {
                return(NotFound("Неверный пароль"));
            }

            var token = _tokenService.BuildToken(dbUser, _config["Jwt:Key"], _config["Jwt:Issuer"]);

            return(Ok(token));
        }
Exemple #2
0
        public async Task <ActionResult <TokenDto> > LoginAsync([FromBody] UserInfo data)
        {
            string userName = null;
            string password = null;

            if (data != null)
            {
                userName = data.UserName;
                password = data.Password;
            }
            var user = await userService.GetUser(userName, password);

            if (user == null)
            {
                return(new JsonResult(new RespResult(Configs.BizStatusCode.NoUser)));
            }
            var objToken = tokenService.BuildToken(user);

            return(new JsonResult(new RespResult <TokenDto>(objToken)));
        }