Exemplo n.º 1
0
        public ApplicationUserDTO Create(ApplicationUserDTO user, string password)
        {
            if (_userRepository.GetAll().Any(u => u.Email == user.Email))
            {
                throw new HttpStatusCodeException(
                          HttpStatusCode.UnprocessableEntity, "Such user already exists");
            }

            user.SettingsId = _settingsRepository.GetSettingsByPhoneId(user.PhoneIdentifier).SettingsId;
            user.Id         = _userRepository.GetAll().First(u => u.PhoneIdentifier == user.PhoneIdentifier).AccountId;

            _userRepository.UpdateUser(new ApplicationUserModel
            {
                City             = user.City,
                Country          = user.Country,
                DateOfBirth      = Convert.ToDateTime(user.DateOfBirth).Date,
                Email            = user.Email,
                FirstName        = user.FirstName,
                Id               = user.Id,
                LastName         = user.LastName,
                PasswordHash     = PasswordGenerators.CreatePasswordHash(password),
                SettingsId       = user.SettingsId.Value,
                PhoneNumber      = user.PhoneNumber,
                PhoneIdentifier  = user.PhoneIdentifier,
                ValidationCode   = user.ValidationCode,
                CodeCreationTime = user.CodeCreationTime
            });

            _theaterScheduleUnitOfWork.Save();

            return(user);
        }
Exemplo n.º 2
0
        public async Task <ApplicationUserDTO> GetAsync(string email, string passwordHash)
        {
            var user = await _userRepository.GetAll().FirstOrDefaultAsync(item => item.Email == email);

            if (user == null)
            {
                throw new HttpStatusCodeException(
                          HttpStatusCode.NotFound, $"Such user doesn't exist");
            }


            if (!(PasswordGenerators.CreatePasswordHash(passwordHash) == user.PasswordHash))
            {
                throw new HttpStatusCodeException(
                          HttpStatusCode.NotFound, $"Such user doesn't exist");
            }


            return(new ApplicationUserDTO
            {
                Id = user.AccountId,
                FirstName = user.FirstName,
                LastName = user.LastName,
                Email = user.Email,
                City = user.City,
                PhoneNumber = user.PhoneNumber,
                Country = user.Country,
                DateOfBirth = user.Birthdate.ToString("yyyy-MM-dd"),
                ValidationCode = user.ValidationCode,
                CodeCreationTime = user.CodeCreationTime
            });
        }
Exemplo n.º 3
0
        public CreateUserViewModel(string fullName, string email, string phoneNumber, string role)
        {
            FullName    = fullName;
            Email       = email;
            PhoneNumber = phoneNumber;
            Role        = role;

            Password       = PasswordGenerators.GeneratePassword();
            privateKeyJson = JsonConvert.SerializeObject(privateKey);

            CreateUserCommand = new Command(CreateUser);
        }
Exemplo n.º 4
0
        public void ResetPasswordAsync(ResetPasswordDTO passwordDTO)
        {
            var user = _userRepository.GetById(passwordDTO.Id);

            if (user == null)
            {
                throw new HttpStatusCodeException(HttpStatusCode.NotFound);
            }
            _userRepository.UpdatePasswordAsync(new ChangePasswordModel
            {
                Id       = passwordDTO.Id,
                Password = PasswordGenerators.CreatePasswordHash(passwordDTO.Password)
            });

            _theaterScheduleUnitOfWork.Save();
        }
Exemplo n.º 5
0
        public async Task UpdatePasswordAsync(ChangePasswordDTO passwordDTO)
        {
            var user = await _userRepository.GetByIdAsync(passwordDTO.Id);

            if (user == null)
            {
                throw new HttpStatusCodeException(HttpStatusCode.NotFound, $"Wrong user Id");
            }

            var oldPasswordHash = PasswordGenerators.CreatePasswordHash(passwordDTO.OldPassword);

            if (user.PasswordHash != oldPasswordHash)
            {
                throw new HttpStatusCodeException(HttpStatusCode.BadRequest, $"Wrong user Password");
            }

            await _userRepository.UpdatePasswordAsync(new ChangePasswordModel
            {
                Id       = passwordDTO.Id,
                Password = PasswordGenerators.CreatePasswordHash(passwordDTO.NewPassword)
            });

            _theaterScheduleUnitOfWork.Save();
        }