public int Handle(AuthorizatInfo authorizatInfo)
        {
            authorizatInfo.Email = authorizatInfo.Email.ToLower();
            var user = _userService.GetUserFromTableUser(authorizatInfo.Email);

            if (user == null)
            {
                throw new IncorrectRequestException("Пользователя не существует");
            }
            var verifiedUserHash = Password.GetHashPass(user.Salt, authorizatInfo.Password);
            var coincidence      = string.Equals(verifiedUserHash, user.HashPass);

            if (!coincidence)
            {
                throw new IncorrectRequestException("Плохой пароль");
            }

            return(user.Id);
        }
Ejemplo n.º 2
0
        public IActionResult AuthorisateUser(AuthorizatInfo authorizatInfo)
        {
            var authorisateRequestHandler = new AuthorisateRequestHandler(new UserService());
            var id = authorisateRequestHandler.Handle(authorizatInfo);

            var now = DateTime.UtcNow;

            var jwt = new JwtSecurityToken(
                issuer: AuthOptions.ISSUER,
                audience: AuthOptions.AUDIENCE,
                claims: new []
            {
                new Claim("id", id.ToString()),
            },
                expires: now.Add(TimeSpan.FromMinutes(AuthOptions.LIFETIME)),
                signingCredentials: new SigningCredentials(AuthOptions.GetSymmetricSecurityKey(), SecurityAlgorithms.HmacSha256));
            var JwtString = new JwtSecurityTokenHandler().WriteToken(jwt);

            return(Json(JwtString));
        }