Ejemplo n.º 1
0
        public async Task <User> VerifyLoginAsync(string email, string password)
        {
            var user = await _dataContext.Users.FirstOrDefaultAsync(x => x.Email.Equals(email));

            if (user != null && PasswordHashService.ValidatePassword(password, user.Password))
            {
                return(user);
            }

            return(null);
        }
Ejemplo n.º 2
0
 public string ValidateLoginRequest(LoginRequest request, User user)
 {
     if (user == null)
     {
         return("No user is registered with this email");
     }
     if (user.Password == null)
     {
         return("User has only registered with an external provider");
     }
     if (!PasswordHashService.ValidatePassword(request.Password, user.Password))
     {
         return("Incorrect password");
     }
     return(null);
 }
Ejemplo n.º 3
0
        public async Task <User> RegisterUser(RegisterRequest request)
        {
            string hashedPassword = request.Password == null
                ? null
                : PasswordHashService.HashPassword(request.Password);
            var user = new User
            {
                Email       = request.Email,
                Username    = request.Username,
                Password    = hashedPassword,
                ExternalId  = request.ExternalId,
                PhoneNumber = request.PhoneNumber,
                Created     = DateTime.Now
            };

            return(await _userRepository.AddUser(user));
        }