Beispiel #1
0
        public override int GetPasswordFailuresSinceLastSuccess(string userName)
        {
            User user = User.GetByUserName(userName);

            if (user == null)
            {
                return(-1);
            }

            OrderBy <LoginColumns>    ob          = new OrderBy <LoginColumns>(c => c.DateTime, SortOrder.Descending);
            LoginCollection           latestLogin = Login.Where(c => c.UserId == user.Id, ob);
            PasswordFailureCollection failures    = PasswordFailure.Where(c => c.UserId == user.Id);
            List <PasswordFailure>    sinceLast   = new List <PasswordFailure>();

            if (latestLogin.Count > 0)
            {
                DateTime since = latestLogin[0].DateTime.Value;
                foreach (PasswordFailure failure in failures)
                {
                    if (failure.DateTime > since)
                    {
                        sinceLast.Add(failure);
                    }
                }
            }

            return(sinceLast.Count);
        }
Beispiel #2
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);
        }