Exemplo n.º 1
0
        public override bool DeleteUser(string username, bool deleteAllRelatedData)
        {
            User user   = User.GetByUserName(username);
            bool result = false;

            try
            {
                if (user != null)
                {
                    user.IsDeleted  = true;
                    user.IsApproved = false;
                    user.Save();
                    if (deleteAllRelatedData)
                    {
                        UserRoleCollection         roles     = UserRole.Where(c => c.UserId == user.Id);
                        AccountCollection          accounts  = Account.Where(c => c.UserId == user.Id);
                        PasswordCollection         passwords = Password.Where(c => c.UserId == user.Id);
                        PasswordResetCollection    resets    = PasswordReset.Where(c => c.UserId == user.Id);
                        PasswordFailureCollection  failures  = PasswordFailure.Where(c => c.UserId == user.Id);
                        LockOutCollection          lockouts  = LockOut.Where(c => c.UserId == user.Id);
                        LoginCollection            logins    = Login.Where(c => c.UserId == user.Id);
                        PasswordQuestionCollection questions = PasswordQuestion.Where(c => c.UserId == user.Id);
                        SettingCollection          settings  = Setting.Where(c => c.UserId == user.Id);

                        SessionCollection session = Session.Where(c => c.UserId == user.Id);

                        Database         db  = Db.For <User>();
                        SqlStringBuilder sql = db.ServiceProvider.Get <SqlStringBuilder>();
                        roles.WriteDelete(sql);
                        accounts.WriteDelete(sql);
                        passwords.WriteDelete(sql);
                        resets.WriteDelete(sql);
                        failures.WriteDelete(sql);
                        lockouts.WriteDelete(sql);
                        logins.WriteDelete(sql);
                        questions.WriteDelete(sql);
                        settings.WriteDelete(sql);
                        session.WriteDelete(sql);

                        sql.Execute(db);
                    }
                }
            }
            catch (Exception ex)
            {
                result = false;
                Log.AddEntry("{0}.{1}::{2}", ex, this.GetType().Name, MethodBase.GetCurrentMethod().Name, ex.Message);
            }
            return(result);
        }
Exemplo n.º 2
0
        public override DateTime GetPasswordChangedDate(string userName)
        {
            User user = User.GetByUserName(userName);

            if (user == null)
            {
                return(DateTime.MinValue);
            }

            PasswordResetCollection resets = PasswordReset.Where(c => c.UserId == user.Id && c.WasReset == true);
            DateTime result = user.CreationDate.Value;

            if (resets.Count > 0)
            {
                List <PasswordReset> sorted = resets.Sorted((l, r) => l.DateTime.Value.CompareTo(r.DateTime.Value));
                result = sorted[0].DateTime.Value;
            }

            return(result);
        }