示例#1
0
 internal void Map(UserDetailsModel userDetailsModel, User user)
 {
     user.UserRoleId = userDetailsModel.UserRoleId;
     user.UserName = userDetailsModel.UserName;
     user.First = userDetailsModel.First;
     user.Last = userDetailsModel.Last;
     user.Email = userDetailsModel.Email;
 }
示例#2
0
 internal void Map(User user, UserDetailsModel userDetailsModel)
 {
     userDetailsModel.UserId = user.Id;
     userDetailsModel.UserRoleId = user.UserRoleId;
     userDetailsModel.UserRoleName = UserRoleModel.GetName(user.UserRoleId);
     userDetailsModel.UserName = user.UserName;
     userDetailsModel.First = user.First;
     userDetailsModel.Last = user.Last;
     userDetailsModel.Email = user.Email;
 }
示例#3
0
        public int CreateUser(UserDetailsModel userDetails)
        {
            ThrowBadDataIf(CheckUserNameExists(userDetails.UserName), "UserName exists");

            var user = Map<User>(userDetails);

            user.PasswordSalt = Cryptography.CreateSalt();
            user.PasswordHash = Cryptography.HashPassword(userDetails.Password, user.PasswordSalt);
            user.PasswordLength = userDetails.Password.Length;

            return userDetails.UserId = InsertAndSave(Map<User>(userDetails)).Id;
        }
示例#4
0
        public void UpdateUser(UserDetailsModel userDetails)
        {
            var user = EnsureFindSingle<User>(userDetails.UserId);

            ThrowBadDataIf(userDetails.UserName != user.UserName &&
                CheckUserNameExists(userDetails.UserName), "UserName exists");

            Map(userDetails, user);

            if (userDetails.Password != string.Concat(Enumerable.Repeat("*", user.PasswordLength)))
            {
                user.PasswordHash = Cryptography.HashPassword(
                    userDetails.Password, user.PasswordSalt);
                user.PasswordLength = userDetails.Password.Length;
            }

            UpdateAndSave(user);
        }