Exemplo n.º 1
0
        public async Task <JwtView> Login(LoginAccountView view)
        {
            User    user  = _mapper.Map <LoginAccountView, User>(view);
            JwtView token = _jwtProvider.CreateToken(user);

            return(token);
        }
Exemplo n.º 2
0
        public async Task <JwtView> LogIn(LogInRequest logInRequest)
        {
            User user = await UserValidation(logInRequest);

            if (user != null)
            {
                JwtView view = _jwtHelper.CreateToken(user);
                return(view);
            }
            throw new UserNotFoundException("Не правильные данные");
        }
Exemplo n.º 3
0
        public JwtView CreateToken(User user)
        {
            ClaimsIdentity   claims      = GetClaimsIdentity(user);
            JwtSecurityToken jwt         = GetToken(claims);
            string           stringToken = new JwtSecurityTokenHandler().WriteToken(jwt);
            JwtView          result      = new JwtView()
            {
                AccessToken = stringToken
            };

            return(result);
        }
Exemplo n.º 4
0
        public async Task <JwtView> Login(LoginViewModel model)
        {
            SignInResult result = await _signInManager.PasswordSignInAsync(model.Email, model.Password, false, false);

            if (result.Succeeded)
            {
                User    appUser  = _userManager.Users.SingleOrDefault(r => r.Email == model.Email);
                JwtView jwtModel = await GenerateJwtToken(model.Email, appUser);

                return(jwtModel);
            }
            throw new ApplicationException("Incorrect login or password. User : " + model.Email);
        }
Exemplo n.º 5
0
        public async Task <IActionResult> Login([FromBody] LoginAccountView view)
        {
            JwtView token = await _accountService.Login(view);

            return(Ok(token));
        }