Пример #1
0
        public async Task <AuthenticationResult> LoginAsync(string email, string password)
        {
            var identityUser = await _userAccess.GetByEmailAsync(email);

            if (identityUser == null)
            {
                return(AuthenticationErrorResult(new[] { "User does not exist" }));
            }

            var hasValidPassword = await _userAccess.VerifyPasswordAsync(identityUser, password);

            if (!hasValidPassword)
            {
                return(AuthenticationErrorResult(new[] { "User / Password combination is incorrect." }));
            }

            var user = new Domain.User
            {
                Id       = Guid.NewGuid(),
                Email    = email,
                Password = password
            };
            var token = _jwtAccess.GenerateJwtToken(user);

            return(AuthenticationSuccessResult(token));
        }
Пример #2
0
        public async Task <AuthenticationResult> RegisterAsync(string email, string password)
        {
            var existingUser = await _userAccess.GetByEmailAsync(email);

            if (existingUser != null)
            {
                return(UserExistsResult());
            }

            var createdUser = await _userAccess.CreateAsync(email, password);

            if (createdUser == null)
            {
                return(null);
            }

            var user = new Domain.User
            {
                Id       = Guid.NewGuid(),
                Email    = email,
                Password = password
            };
            var token = _jwtAccess.GenerateJwtToken(user);

            return(AuthenticationSuccessResult(token));
        }