Ejemplo n.º 1
0
 public void Staff_NoSecurityAnswer()
 {
     var user = new User();
     user.AddRole(ProfileRole);
     user.AddRole(StaffRole);
     Assert.IsFalse(user.RequiresSecurityQuestionToRetrieveCredentials);
 }
Ejemplo n.º 2
0
 public void Staff_WithSecurityAnswser()
 {
     var user = new User();
     user.AddRole(ProfileRole);
     user.AddRole(StaffRole);
     user.SecurityAnswer = "Test";
     Assert.IsTrue(user.RequiresSecurityQuestionToRetrieveCredentials);
 }
Ejemplo n.º 3
0
 private User CreateUser()
 {
     var user = new User();
     user.FirstName = "John";
     user.LastName = "Doe";
     user.Email = "*****@*****.**";
     return user;
 }
Ejemplo n.º 4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ForgotUserNameEmail"/> class.
 /// </summary>
 /// <param name="user">The user.</param>
 public ForgotUserNameEmail(User user)
 {
     ToAddress = user.Email;
     TokenData = new
     {
         FirstName = user.FirstName,
         lastName = user.LastName,
         UserName = user.UserName
     };
 }
Ejemplo n.º 5
0
        /// <summary>
        /// Creates and persists a new user.
        /// </summary>
        /// <param name="request">The request.</param>
        /// <returns>The new user.</returns>
        public User CreateUser(CreateUserRequest request)
        {
            lock (_threadLocker)
            {
                using (var entityContext = _entityContextFactory.CreateEntityContext())
                {
                    if (!_passwordValidator.IsPasswordValid(request.Password))
                        throw new InvalidUserException(MembershipCreateStatus.InvalidPassword);

                    MembershipCreateStatus createStatus;
                    if (request.AllowDuplicateEmails)
                        createStatus = _statusChecker.CheckCreateStatus(request.UserName);
                    else
                        createStatus = _statusChecker.CheckCreateStatus(request.UserName, request.Email);

                    if (createStatus != MembershipCreateStatus.Success)
                        throw new InvalidUserException(createStatus);

                    var user = new User(request.UserName, request.Email, request.Password)
                    {
                        ApplicationName = Utils.Common.Constants.MembershipProviderApplicationName,
                        IsApproved = request.IsApproved,
                        NamePrefix = request.NamePrefix,
                        FirstName = request.FirstName,
                        MiddleName = request.MiddleName,
                        LastName = request.LastName,
                        NameSuffix = request.NameSuffix,
                        IsVerified = request.IsVerified,
                        IsSocialMediaAccount = request.IsSocialMediaAccount
                    };

                    int questionId;
                    if (Int32.TryParse(request.PasswordQuestion, out questionId))
                    {
                        user.SecurityQuestionId = questionId;
                        user.SecurityAnswer = SymmetricUtility.Encrypt(request.PasswordAnswer, _symmetricKeyStore.ReadKey(), _symmetricKeyStore.ReadIV());
                    }

                    if (request.RoleIds != null && request.RoleIds.Any())
                    {
                        var roles = entityContext.EntitySet<Role>();
                        foreach (var roleId in request.RoleIds)
                        {
                            var role = roles.SingleOrDefault(r => r.Id == roleId);
                            if (role != null)
                                user.AddRole(role);
                        }
                    }
                    entityContext.EntitySet<User>().Add(user);
                    entityContext.SaveChanges();

                    return user;
                }
            }
        }
Ejemplo n.º 6
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ForgotUserNameEmail"/> class.
 /// </summary>
 /// <param name="user">The user.</param>
 /// <param name="token">The token.</param>
 /// <param name="resetPasswordLink">The reset password link.</param>
 public ForgotPasswordEmail(User user, Guid token, System.Uri resetPasswordLink)
 {
     ToAddress = user.Email;
     TokenData = new
     {
         FirstName = user.FirstName,
         lastName = user.LastName,
         UserName = user.UserName,
         PasswordResetLink = BuildResetPasswordLink(resetPasswordLink, token),
     };
 }
Ejemplo n.º 7
0
 public UserRole(User user, Role role)
 {
     if (user == null)
     {
         throw new ArgumentNullException("user");
     }
     if (role == null)
     {
         throw new ArgumentNullException("role");
     }
     User = user;
     Role = role;
 }
Ejemplo n.º 8
0
        private void FixupUser(User previousValue)
        {
            if (previousValue != null && previousValue.UsersInRoles.Contains(this))
            {
                previousValue.UsersInRoles.Remove(this);
            }

            if (User != null)
            {
                if (!User.UsersInRoles.Contains(this))
                {
                    User.UsersInRoles.Add(this);
                }
                if (UserId != User.Id)
                {
                    UserId = User.Id;
                }
            }
        }
Ejemplo n.º 9
0
 public void NoRoles()
 {
     var user = new User();
     Assert.IsTrue(user.RequiresSecurityQuestionToRetrieveCredentials);
 }
Ejemplo n.º 10
0
 public void NonStaff()
 {
     var user = new User();
     user.AddRole(ProfileRole);
     Assert.IsTrue(user.RequiresSecurityQuestionToRetrieveCredentials);
 }
Ejemplo n.º 11
0
 public void TestMapUserToDto()
 {
     var user = new User("username", "*****@*****.**", "password");
     Mapper.Map<User, UserDto>(user);
 }
Ejemplo n.º 12
0
        private static void UpdateUser(User user, UpdateStaffProfileRequest request)
        {
            user.UserName = request.UserName;
            user.Email = request.EmailAddress;
            user.NamePrefix = request.NamePrefix;
            user.FirstName = request.FirstName;
            user.MiddleName = request.MiddleName;
            user.LastName = request.LastName;
            user.NameSuffix = request.NameSuffix;

            if (request.LastLoginDate.HasValue)
                user.LastLoginDate = request.LastLoginDate;
        }