Ejemplo n.º 1
0
 public static void PasswordFailuresIncreased(this ILog log, User user)
 {
     if (log.IsDebugEnabled)
     {
         log.DebugFormat("Password failures attemps for user \"{0}\" was set to {1}", user.Username, user.PasswordFailuresSinceLastSuccess);
     }
 }
Ejemplo n.º 2
0
 public static void UserLockedBecousePasswordVerificationAttemptsIsOver(this ILog log, User user)
 {
     if (log.IsDebugEnabled)
     {
         log.DebugFormat("Password failures attemps is over, user with name \"{0}\" is locked", user.Username);
     }
 }
Ejemplo n.º 3
0
        public void DeleteUser(User user)
        {
            using (var session = OpenSesion())
            {
                var userEntity = session.Query<UserEntity>().SingleOrDefault(u => u.UserId == user.UserId);
                if (userEntity == null)
                    throw new InvalidOperationException("User is not exists");

                session.Delete(userEntity);
                session.SubmitChanges();
            }
        }
Ejemplo n.º 4
0
        public static void LogUserStateForValidationOperation(this ILog log, string username, User user)
        {
            if (!log.IsDebugEnabled)
                return;

            if (user == null)
            {
                log.DebugFormat("User with name \"{0}\" is not exists", username);
            }
            else
            {
                log.DebugFormat("User with name \"{0}\" sucessfully founded", username);
                if (!user.IsApproved)
                {
                    log.DebugFormat("User with name \"{0}\" is not approved", username);
                }
                if (user.IsLockedOut)
                {
                    log.DebugFormat("User with name \"{0}\" is locked", username);
                }
            }
        }
Ejemplo n.º 5
0
        public void AddUser(User newUser)
        {
            _log.Trace(m => m("Adding user started"));
            using (var session = OpenSesion())
            {
                session.UseOptimisticConcurrency();

                var userEntity = newUser.ToEntityWithoutRoles();
                var roles = newUser.HasRoles
                                ? session.Query<RoleEntity>().ContainsIn(r => r.RoleName, newUser.Roles).ToList()
                                : Enumerable.Empty<RoleEntity>();
                _log.FoundedRolesByParameters(roles, newUser.Roles);

                foreach (var role in roles)
                {
                    userEntity.AddRole(role.RoleName);
                }
                session.Save(userEntity);
                session.SubmitChanges();
            }
            _log.Trace(m => m("User successfully added"));
        }
 public static User ToUser(this UserEntity entity)
 {
     var user = new User(entity.UserId, entity.Username, entity.Email, entity.ApplicationName)
         {
             Password = entity.Password,
             Roles    = entity.Roles.ToList(),
             Comment = entity.Comment,
             ConfirmationToken = entity.ConfirmationToken,
             CreateDate = entity.CreateDate,
             IsApproved = entity.IsApproved,
             IsLockedOut = entity.IsLockedOut,
             LastActivityDate = entity.LastActivityDate,
             LastLockoutDate = entity.LastLockoutDate,
             LastLoginDate = entity.LastLoginDate,
             LastPasswordChangedDate = entity.LastPasswordChangedDate,
             LastPasswordFailureDate = entity.LastPasswordFailureDate,
             PasswordFailuresSinceLastSuccess = entity.PasswordFailuresSinceLastSuccess,
             PasswordVerificationToken = entity.PasswordVerificationToken,
             PasswordVerificationTokenExpirationDate = entity.PasswordVerificationTokenExpirationDate
         };
     return user;
 }
Ejemplo n.º 7
0
 private void SaveLastUserActivity(User user)
 {
     _log.Debug(m => m("Mark that user with name \"{0}\" is online", user.Username));
     user.LastActivityDate = DateTime.UtcNow;
     UserRepository.SaveUser(user);
 }
Ejemplo n.º 8
0
        public override MembershipUser CreateUser(string username, string password, string email, string passwordQuestion, string passwordAnswer, bool isApproved, object providerUserKey, out MembershipCreateStatus status)
        {
            _log.Trace(m => m("User creation started"));

            status = MembershipCreateStatus.Success;
            if (string.IsNullOrEmpty(username))
            {
                status = MembershipCreateStatus.InvalidUserName;
            }
            if (string.IsNullOrEmpty(password))
            {
                status = MembershipCreateStatus.InvalidPassword;
            }
            if (string.IsNullOrEmpty(email))
            {
                status = MembershipCreateStatus.InvalidEmail;
            }

            var hashedPassword = Crypto.HashPassword(password);
            if (hashedPassword.Length > 128)
            {
                status = MembershipCreateStatus.InvalidPassword;
            }

            var userRepository = RepositoryFactory.Current.CreateUserRepository();
            if (userRepository.HasUserWithName(ApplicationName, username))
            {
                status = MembershipCreateStatus.DuplicateUserName;
            }

            if (userRepository.HasUserWithEmail(ApplicationName, email))
            {
                status = MembershipCreateStatus.DuplicateEmail;
            }

            if (status != MembershipCreateStatus.Success)
            {
                _log.LogUserCreateStatus(username, status);
                return null;
            }

            var newUser = new User(Guid.NewGuid(), username, email, ApplicationName)
            {
                Password = hashedPassword,
                IsApproved = isApproved,
                CreateDate = DateTime.UtcNow,
                LastPasswordChangedDate = DateTime.UtcNow,
                PasswordFailuresSinceLastSuccess = 0,
                LastLoginDate = DateTime.UtcNow,
                LastActivityDate = DateTime.UtcNow,
                LastLockoutDate = DateTime.UtcNow,
                IsLockedOut = false,
                LastPasswordFailureDate = DateTime.UtcNow
            };

            userRepository.AddUser(newUser);

            _log.Trace(m => m("User successfully created"));
            return new MembershipUser(
                System.Web.Security.Membership.Provider.Name,
                newUser.Username,
                newUser.UserId,
                newUser.Email,
                null,
                newUser.Comment,
                newUser.IsApproved,
                newUser.IsLockedOut,
                newUser.CreateDate.Value,
                newUser.LastLoginDate.Value,
                newUser.LastActivityDate.Value,
                newUser.LastPasswordChangedDate.Value,
                newUser.LastLockoutDate.Value
            );
        }
Ejemplo n.º 9
0
        public void SaveUser(User user)
        {
            _log.Trace(m => m("Saving user started"));
            using (var session = OpenSesion())
            {
                session.UseOptimisticConcurrency();

                var userEntity = session.Query<UserEntity>().Single(u => u.UserId == user.UserId);
                _log.UserChanges(user, userEntity);
                userEntity.UpdateUser(user);

                UpdateUsersRolesList(session, userEntity, user.Roles);

                session.Save(userEntity);
                session.SubmitChanges();
            }
            _log.Trace(m => m("User successfully saved"));
        }