Exemplo n.º 1
0
        /// <summary>
        /// The user Add flow works differently than other adds. After adding the record here, the calling code will also
        /// generate a token to send to user so they can complete registration.
        /// </summary>
        /// <param name="model"></param>
        /// <param name="userId"></param>
        /// <returns></returns>
        //add this layer so we can instantiate the new entity here.
        public override async Task <int?> Add(UserModel model, UserToken userToken)
        {
            //generate random password and then encrypt in here.
            var password = PasswordUtils.GenerateRandomPassword(_configUtil.PasswordConfigSettings.RandomPasswordLength);

            User entity = new User
            {
                ID        = null
                , Created = DateTime.UtcNow
                            //not actually used during registration but keep it here because db expects non null.
                            //if future, the user sets their own pw on register complete
                , Password = PasswordUtils.EncryptNewPassword(_configUtil.PasswordConfigSettings.EncryptionSettings, password)
            };

            this.MapToEntity(ref entity, model, userToken);
            //do this after mapping to enforce isactive is true on add
            entity.IsActive = true;

            //this will add and call saveChanges
            await _repo.AddAsync(entity);

            model.ID = entity.ID;
            // Return id for newly added user
            return(entity.ID);
        }
Exemplo n.º 2
0
 public string GetPassword()
 {
     if (Password == null)
     {
         var pwd = PasswordUtils.GenerateRandomPassword();
         Password = pwd;
         return pwd;
     }
     else
         return Password;
 }
Exemplo n.º 3
0
        /// <summary>
        /// Executes the command
        /// </summary>
        /// <returns>Returns the generated password for the user</returns>
        /// <exception cref="MJLEntityNotFoundException">Thrown when the specified user is not found</exception>
        public virtual string Execute()
        {
            // Retrieve the user
            var user = new UserByEmailQuery(_unitOfWork).WithEmail(_email).Execute();

            if (user == null)
            {
                throw new MJLUserNotFoundException(MJLUserNotFoundException.SearchPropertyType.Email, _email);
            }

            // Generate a new password for the user
            string newPassword = PasswordUtils.GenerateRandomPassword();

            user.Password = PasswordUtils.CreatePasswordHash(user.Email, newPassword);

            _unitOfWork.Commit();

            // Send out an email
            EmailProvider.Send(user.Email, "Password Recovery", "Your new MyJobLeads password is: " + newPassword);

            return(newPassword);
        }