Esempio n. 1
0
        public static UserLogin AddUser(string username, string firstname, string lastname)
        {
            UserLogin newUser = null;

            if (!database.Users.Any(u => u.Username == username))
            {
                newUser = new UserLogin()
                {
                    Username               = username.ToLower(),
                    Firstname              = firstname,
                    Lastname               = lastname,
                    UserPermissions        = UserPermissions.ReportsOnly,
                    Password               = PasswordEncrypter.EncryptPassword(username.ToLower(), "ffj" + username.ToLower()),
                    LastLogin              = DateTime.Today,
                    FailedLoginCount       = 0,
                    FailedLoginTimestamp   = DateTime.Today.AddDays(-1),
                    AccountLocked          = false,
                    UserMustChangePassword = true,
                };

                database.Users.Add(newUser);
                database.SaveChanges();
                ESB2UserEventLog.LogUserEvent(newUser.Username, EventLoggerEvents.UserCreated);

                LoadUserList();
            }

            return(newUser);
        }
Esempio n. 2
0
        private static void CreateAdminAccount()
        {
            var createAdminAccount = new CreateAdminAccount();

            createAdminAccount.ShowDialog();

            if (createAdminAccount.Password != null)
            {
                database.Users.Add(new UserLogin()
                {
                    Username               = "******",
                    Firstname              = "Administrator",
                    Lastname               = "Account",
                    UserPermissions        = UserPermissions.Admin,
                    Password               = createAdminAccount.Password,
                    LastLogin              = DateTime.Today,
                    FailedLoginCount       = 0,
                    FailedLoginTimestamp   = DateTime.Today.AddDays(-1),
                    AccountLocked          = false,
                    UserMustChangePassword = false,
                });

                database.SaveChanges();
                ESB2UserEventLog.LogUserEvent("admin", EventLoggerEvents.UserCreated);
            }
        }
Esempio n. 3
0
        private static User ProcessLogin(UserLogin user, string password)
        {
            if (user.AccountLocked)
            {
                user = HandleAccountLocked(user);
            }

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

            if (ValidatePassword(user, password))
            {
                user.FailedLoginCount = 0;
                user.LastLogin        = DateTime.Now;
            }
            else
            {
                user.FailedLoginCount++;

                if (user.FailedLoginCount == 1)
                {
                    user.FailedLoginTimestamp = DateTime.Now;
                }

                new LoginFailDialog().ShowDialog(user.FailedLoginCount);
                user.AccountLocked = user.FailedLoginCount == 5;

                user = null;
            }

            database.SaveChanges();
            return(user);
        }
Esempio n. 4
0
 public static void LogExceptionEvent(Exception ex)
 {
     if (ex != null)
     {
         new ApplicationExceptionDialog().ShowDialog();
         database.ExceptionEventLog.Add(BuildExceptionEventLogEntry(ex, false));
         database.SaveChanges();
     }
 }
Esempio n. 5
0
 public static void LogUserEvent(string username, EventLoggerEvents userEvent)
 {
     try
     {
         database.EventLogLog.Add(new EventLoggerEvent()
         {
             Timestamp = DateTime.Now,
             User      = username,
             Event     = userEvent
         });
         database.SaveChanges();
     }
     catch (Exception e)
     {
         ESB2ExceptionEventLog.LogExceptionEvent(e);
     }
 }
Esempio n. 6
0
        private static User ProcessLogin(UserLogin user, string password)
        {
            if (user.AccountLocked)
            {
                user = HandleAccountLocked(user);
            }

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

            if (ValidatePassword(user, password))
            {
                user.FailedLoginCount = 0;
                user.LastLogin        = DateTime.Now;
                ESB2UserEventLog.LogUserEvent(user.Username, EventLoggerEvents.LoginSuccess);

                if (user.UserMustChangePassword)
                {
                    new ChangePasswordDialog(user).ShowDialog();
                }
            }
            else
            {
                user.FailedLoginCount++;

                user.FailedLoginTimestamp = DateTime.Now;
                new LoginFailDialog().ShowDialog(user.FailedLoginCount);
                ESB2UserEventLog.LogUserEvent(user.Username, EventLoggerEvents.LoginFail);

                user.AccountLocked = user.FailedLoginCount == 5;
                if (user.AccountLocked)
                {
                    ESB2UserEventLog.LogUserEvent(user.Username, EventLoggerEvents.UserAccountLocked);
                }

                user = null;
            }

            database.SaveChanges();
            return(user);
        }
Esempio n. 7
0
        public static SystemGroup AddNewSystemGroup(string nomenclature, string description)
        {
            var newSystemsGroup = new SystemGroup()
            {
                Nomenclature = nomenclature,
                Description  = description
            };

            database.SystemGroupings.Add(newSystemsGroup);

            database.SaveChanges();
            ESB2UserEventLog.LogUserEvent(CurrentUserNotifications.CurrentUser.Username, EventLoggerEvents.SystemGroupAdded);
            LoadSystemsList();

            return(newSystemsGroup);
        }