private void okCommand_Click(object sender, EventArgs e)
        {
            if (!validateForm())
            {
                return;
            }
            if (!passwordTextEdit.Text.Equals(confirmPasswordTextEdit.Text))
            {
                ViewHelper.ShowErrorMessage("The password was not correctly confirmed. Please ensure that the password and confirmation match exactly.");
                activityLogger.SaveAction(CurrentUser.UserID, 1, "Set Password Window", "The password was not correctly confirmed. Please ensure that the password and confirmation match exactly.");
                this.Close();
            }

            try
            {
                CurrentUser.SetPassword(passwordTextEdit.EditValue.ToString());
                _repository.Users.Update(CurrentUser);
                //SecurityHelper.ResetPassword(CurrentUser.UserName, passwordTextEdit.Text);
                ViewHelper.ShowSuccessMessage("User password has been set.");
                activityLogger.SaveAction(CurrentUser.UserID, 1, "Set Password Window", "User password set succesfully");
                this.Close();
            }
            catch (Exception exception)
            {
                ViewHelper.ShowErrorMessage("Error occured while setting new password.", exception);
                errorLogger.SaveError(CurrentUser.UserID, 1, 1, 2, "Unable to set password", "Warehouse", exception);
            }
        }
        private void DoChangePassword()
        {
            if (!ValidateForm())
            {
                lblMessage.Text = "Please provide the correct Old Password";
                Exception exception = new Exception("New & confirmed passwords doesn't match.");
            }
            else
            {
                lblMessage.Text = "";
            }

            if (newPasswordTextEdit.Text != confirmpasswordtextEdit.Text)
            {
                ViewHelper.ShowErrorMessage("New & confirmed passwords doesn't match.");
                activityLogger.SaveAction(repository.Users.FindByName(Thread.CurrentPrincipal.Identity.Name).UserID, 1,
                                          "Change Password Window", "New & confirmed passwords doesn't match.");
            }

            else if (SecurityHelper.ChangePassword(repository, Thread.CurrentPrincipal.Identity.Name, oldPasswordTextEdit.Text,
                                                   newPasswordTextEdit.Text))
            {
                ViewHelper.ShowSuccessMessage("Password changed successfully.");
                activityLogger.SaveAction(repository.Users.FindByName(Thread.CurrentPrincipal.Identity.Name).UserID, 1,
                                          "Change Password Window", "Password changed successfully.");
                this.Close();
            }
        }
Exemple #3
0
        private void BtnSaveUserDetailClick(object sender, EventArgs e)
        {
            currentUserBindingSource.EndEdit();
            if (!ValidateForm())
            {
                return;
            }
            try
            {
                if (NewMode)
                {
                    if (!repository.Users.UsernameIsAvailable(usernametextEdit.Text))
                    {
                        ViewHelper.ShowErrorMessage("Username already exist,Please provide a new one.");
                        activityLogger.SaveAction(CurrentUser.UserID, 1, "New user Window", "Username already exist,Please provide a new one.");
                        return;
                    }
                    CurrentUser.IsActive    = true;
                    CurrentUser.CreatedDate = Security.Helpers.DateTimeHelper.ServerDateTime;
                    if (CurrentUser.Password == null)
                    {
                        CurrentUser.Password = passwordtextEdit.Text;
                    }
                    CurrentUser.SetPassword(CurrentUser.Password);
                    CurrentUser.FullName = CurrentUser.FirstName + " " + CurrentUser.LastName;
                    // this is for supporting legacy code.
                    CurrentUser.UserType        = 1;
                    CurrentUser.PasswordExpires = true;
                    repository.Users.Add(CurrentUser);

                    ViewHelper.ShowSuccessMessage("User information added succesfully!");
                    // activityLogger.SaveAction(CurrentUser.UserID, 1, "New user Window", "New user added Succesfully");
                    Refresh(CurrentUser.UserID);
                }

                else
                {
                    if (!(_username == usernametextEdit.Text) && !repository.Users.UsernameIsAvailable(usernametextEdit.Text))
                    {
                        ViewHelper.ShowErrorMessage("Username already exist,Please enter another one");
                        return;
                    }
                    CurrentUser.ModifiedDate = Security.Helpers.DateTimeHelper.ServerDateTime;
                    CurrentUser.FullName     = CurrentUser.FirstName + " " + CurrentUser.LastName;
                    repository.Users.Update(CurrentUser);

                    ViewHelper.ShowSuccessMessage("User information updated succesfully!");
                    activityLogger.SaveAction(CurrentUser.UserID, 1, "User detail Window", "User updated Succesfully");
                }
            }
            catch (Exception ex)
            {
                this.Close();
            }
        }
        private void BtnSaveGroupClick(object sender, EventArgs e)
        {
            if (grouplistbox.SelectedItem == null)
            {
                ViewHelper.ShowErrorMessage("There is no group to be added.");
                activityLogger.SaveAction(CurrentUser.UserID, 1, "Group Window", "There is no group to be added.");
                this.Close();
            }
            usergroupbindingSource.EndEdit();
            var obj = usergroupbindingSource.DataSource as List <UserGroup>;

            try
            {
                var selectedItems = grouplistbox.SelectedItems;
                foreach (var anItem in selectedItems)
                {
                    var item = anItem as Group;
                    //foreach (var groupPermission in item.GroupPermissions)
                    //{
                    //    var permission = new Permission
                    //    {
                    //        UserID = CurrentUser.UserID,
                    //        OperationID = groupPermission.OperationID,
                    //        Allow = groupPermission.Allow
                    //    };
                    //    repository.Permissions.Add(permission);
                    //   activityLogger.SaveAction(CurrentUser.UserID, 1, "User Permission Window", "User Permission Succesfully Added");
                    //  }
                    var ug = repository.UserGroups.FindBy(g => g.GroupID == item.GroupID && g.UserID == CurrentUser.UserID).FirstOrDefault();
                    if (ug != null)
                    {
                        ug.GroupStatus = true;
                        repository.UserGroups.Update(ug);
                    }
                    else
                    {
                        var usergroup = new UserGroup
                        {
                            GroupID     = item.GroupID,
                            UserID      = CurrentUser.UserID,
                            GroupStatus = true
                        };
                        repository.UserGroups.Add(usergroup);
                        activityLogger.SaveAction(CurrentUser.UserID, 1, "Group Window", "Group Succesfully Added");
                    }
                }
                this.Close();
            }
            catch (Exception ex)
            {
                ViewHelper.ShowErrorMessage("Unable to create user group!");
                errorLogger.SaveError(CurrentUser.UserID, 1, 1, 2, "Add group attempt", "Warehouse", ex);
            }
        }
        private void BtnSaveAccountClick(object sender, EventArgs e)
        {
            if (accountlistBox.SelectedItem == null)
            {
                ViewHelper.ShowErrorMessage("There is no account to be added.");
                activityLogger.SaveAction(CurrentUser.UserID, 1, "User Account list", "There is no account to be added.");
                this.Close();
            }
            accountuserbindingSource.EndEdit();
            var obj = accountuserbindingSource.DataSource as List <AccountUser>;

            try
            {
                var selectedItems = accountlistBox.SelectedItems;
                foreach (var anItem in selectedItems)
                {
                    var item = anItem as Activity;
                    // check if there is a deactivated account by the same account id
                    var aUser =
                        repository.AccountUsers.FindBy(u => u.UserID == CurrentUser.UserID && u.AccountID == item.ActivityID).FirstOrDefault();

                    if (aUser != null)
                    {
                        aUser.IsActive = true;
                        repository.AccountUsers.Update(aUser);
                    }
                    else
                    {
                        var accountUser = new AccountUser
                        {
                            AccountID = item.ActivityID,
                            UserID    = CurrentUser.UserID,
                            IsActive  = true
                        };

                        repository.AccountUsers.Add(accountUser);
                    }
                }

                activityLogger.SaveAction(CurrentUser.UserID, 1, "User Account list", "Account Succesfully Added");
                this.Close();
            }
            catch (Exception ex)
            {
                ViewHelper.ShowErrorMessage("Unable to create account", ex);
                errorLogger.SaveError(CurrentUser.UserID, 1, 1, 2, "Add account attempt", "Warehouse", ex);
            }
        }
        private void btnStoreSave_Click(object sender, EventArgs e)
        {
            if (storelistBox.SelectedItem == null)
            {
                ViewHelper.ShowErrorMessage("There is no store to be added.");
                activityLogger.SaveAction(CurrentUser.UserID, 1, "User Store Window", "There is no store to be added.");
                this.Close();
            }
            userstorebindingSource.EndEdit();
            var obj = userstorebindingSource.DataSource as List <StoreUser>;

            try
            {
                var selectedItems = storelistBox.SelectedItems;
                foreach (var anItem in selectedItems)
                {
                    var item = anItem as Store;

                    // check if there is a diabled store entity
                    var aStore = repository.StoreUsers.FindBy(s => s.UserID == CurrentUser.UserID && s.StoreID == item.StoreID).
                                 FirstOrDefault();
                    if (aStore != null)
                    {
                        aStore.IsActive = true;
                        repository.StoreUsers.Update(aStore);
                    }
                    else
                    {
                        var storeuser = new StoreUser
                        {
                            StoreID  = item.StoreID,
                            UserID   = CurrentUser.UserID,
                            IsActive = true
                        };
                        repository.StoreUsers.Add(storeuser);
                        activityLogger.SaveAction(CurrentUser.UserID, 1, "User Store Window",
                                                  "User store added Succesfully");
                    }
                }
                this.Close();
            }
            catch (Exception ex)
            {
                ViewHelper.ShowErrorMessage("Unable to create store", ex);
                errorLogger.SaveError(CurrentUser.UserID, 1, 1, 2, "Add store attempt", "Warehouse", ex);
            }
        }
Exemple #7
0
        public static bool Login(string username, string password)
        {
            var userInfo = Auth.Authenticate(username, password);

            if (userInfo == null)
            {
                errorLogger.SaveError(0, 1, 1, 2, "Login Attempt", "Warehouse", new InvalidCredentialException("Invalid credentials, Username = "******"Login Window", "Successful Login");
            return(true);
        }