Ejemplo n.º 1
0
        public async Task <UserResultModel> CreateAsync(AppUser u, string password)
        {
            var res = new UserResultModel();

            if (!UserDataValidator.ValidateEmail(u.Email))
            {
                res.Errors.Add("Invalid email address.");
            }
            if (!UserDataValidator.ValidateUserName(u.UserName))
            {
                res.Errors.Add("Invalid user name.");
            }
            if (!UserDataValidator.ValidateTarget(u.DailyTarget))
            {
                res.Errors.Add("Target has to be at least 0.");
            }
            if (!UserDataValidator.ValidatePassword(password))
            {
                res.Errors.Add("Password does not meet minimum requirments.");
            }

            if (!res.Succeeded)
            {
                return(res);                // stop and return all errors.
            }
            u.PasswordHash = HashUserPassword(u, password);
            _dbContext.Users.Add(u);
            await _dbContext.SaveChangesAsync();

            return(res);
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Returns whether the given email address is valid,
 /// and shows an error dialog if not.
 /// </summary>
 public static bool ValidateUserName(string email, Context context)
 {
     if (UserDataValidator.ValidateUserName(email))
     {
         return(true);
     }
     else
     {
         ShowErrorDialog("Invalid user name", context);
         return(false);
     }
 }