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

            if (!ValidatePasswordResetToken(u, token))
            {
                res.Errors.Add("Invalid token.");
                return(res);
            }

            if (!UserDataValidator.ValidatePassword(newPassword))
            {
                res.Errors.Add("Password does not meet minimum requirments.");
                return(res);
            }

            var newPwdHash = HashUserPassword(u, newPassword);

            u.PasswordHash = newPwdHash;

            _dbContext.Update(u);
            await _dbContext.SaveChangesAsync();

            return(res);
        }
Ejemplo n.º 2
0
        public async Task <WriteUserResponseDTO> EditProfile(int userId, EditProfileDTO data)
        {
            IUserDataValidator validator = new UserDataValidator();
            var userData = new UserDataDTO
            {
                Email   = data.Email,
                Name    = data.Name,
                Surname = data.Surname
            };

            var editResponce = new WriteUserResponseDTO
            {
                IsSuccessful  = true,
                PropertyInfos = new List <WriteUserResponseDTO.PropertyInfo>()
            };
            var user = _unitOfWork.Users.Find(u => u.Email.Equals(data.Email) && u.UserId != userId).FirstOrDefault();

            validator.EditProfileValidation(user, userData, editResponce);
            if (editResponce.IsSuccessful)
            {
                EditUserData(userId, userData);
                await AddUserInfo(userId, data);
            }
            return(editResponce);
        }
Ejemplo n.º 3
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.º 4
0
            public async Task <UserData> Handle(UserData data, CancellationToken cancellationToken)
            {
                UserDataValidator validator = new UserDataValidator();
                var results = validator.Validate(data);

                // null or empty fields
                if (results.IsValid == false)
                {
                    throw new RestException(HttpStatusCode.BadRequest, results.Errors);
                }

                // duplicate user
                if (await _context.Users.Where(u => u.EmailAddress == data.EmailAddress).AnyAsync())
                {
                    throw new RestException(HttpStatusCode.BadRequest, "Used email address");
                }

                await _context.Users.AddAsync(
                    new User
                {
                    Username     = data.Username,
                    EmailAddress = data.EmailAddress,
                    Password     = data.Password,
                    DateCreated  = DateTime.Now.ToString(),
                    PasswordSalt = "salt"      // TODO : add salting algorithm
                });

                _context.SaveChanges();
                return(data);
            }
Ejemplo n.º 5
0
        public Task Should_Throw_ConflictExceprion_If_User_Exists()
        {
            var usersStub = new List <User>()
            {
                new User()
                {
                    Email = "*****@*****.**"
                }
            }.AsQueryable();

            var usersMock = usersStub.BuildMockDbSet <User>();

            var options = new DbContextOptionsBuilder <DataContext>()
                          .UseInMemoryDatabase(databaseName: "TaskAPI")
                          .Options;

            var dataContextMock = new Mock <DataContext>(options);

            dataContextMock.Setup(x => x.Users).Returns(usersMock.Object);

            var dataValidator = new UserDataValidator(dataContextMock.Object);
            var newUserMock   = new User()
            {
                Email = "*****@*****.**"
            };

            Func <Task> f = async() => await dataValidator.Validate(newUserMock);

            f.Should().Throw <ConflictException>();

            return(Task.CompletedTask);
        }
Ejemplo n.º 6
0
 /// <summary>
 /// Returns whether ALL the given values are not empty strings,
 /// and shows an error dialog otherwise
 /// </summary>
 /// <param name="values">The string values to check</param>
 public static bool ValidateFilled(Context context, params string[] values)
 {
     if (UserDataValidator.ValidateNotNullOrEmpty(values))
     {
         return(true);
     }
     else
     {
         ShowErrorDialog("All fields must be filled.", context);
         return(false);
     }
 }
Ejemplo n.º 7
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);
     }
 }
Ejemplo n.º 8
0
 /// <summary>
 /// Returns whether the given email address is valid,
 /// and shows an error dialog if not.
 /// </summary>
 public static bool ValidateEmail(string email, Context context)
 {
     if (UserDataValidator.ValidateEmail(email))
     {
         return(true);
     }
     else
     {
         ShowErrorDialog("Invalid email address.", context);
         return(false);
     }
 }
Ejemplo n.º 9
0
 /// <summary>
 /// Returns whether the given password is valid,
 /// And shows an error dialog if not.
 /// </summary>
 public static bool ValidatePassword(string password, Context context)
 {
     if (UserDataValidator.ValidatePassword(password))
     {
         return(true);
     }
     else
     {
         ShowErrorDialog("Password must include a lower case, an upper case," +
                         " a number and a special charachter, as well as at least 8 digits.", context);
         return(false);
     }
 }
Ejemplo n.º 10
0
        public async Task <UserResultModel> SetUserTarget(int target, string userName)
        {
            var res = new UserResultModel();

            if (!UserDataValidator.ValidateTarget(target))
            {
                res.Errors.Add("Target has to be at least 0.");
                return(res);
            }

            var u = await _dbContext.Users.FirstOrDefaultAsync(u => u.UserName == userName);

            u.DailyTarget = target;
            _dbContext.Update(u);
            await _dbContext.SaveChangesAsync();

            return(res);
        }
Ejemplo n.º 11
0
 public IssueViewModel(Issue issue)
 {
     this.Issue = issue;
     validator  = new UserDataValidator();
 }
Ejemplo n.º 12
0
 public IssueViewModel()
 {
     this.Issue = new Issue();
     validator  = new UserDataValidator();
 }
Ejemplo n.º 13
0
 public UserService(VacationCalendarContext context, UserDataValidator validator)
 {
     _context   = context;
     _validator = validator;
 }
 public void Arrange()
 {
     _validator = new UserDataValidator();
 }