Beispiel #1
0
        private void btn_Login_Click(object sender, EventArgs e)
        {
            using (UserController userController = new UserController())
            {
                string Username = txt_Username.Text;
                string Password = txt_Password.Text;

                User user = userController.Login(Username, (RequiresPassword) ? Password : null);

                if (user != null)
                {
                    ClearCredentials();

                    lbl_Password.Visible = false;
                    txt_Password.Visible = false;

                    lbl_Status.Text = String.Empty;

                    UserModelDataTransferObject User = userController.GetUserByID(user.UserID);

                    // Move to MainForm
                    Program.frm_Login.Hide();
                    Program.frm_MainForm = new MainForm(User);
                    Program.frm_MainForm.Show();
                }
                else
                {
                    lbl_Status.Text      = "Utilizatorul si parola nu se potrivesc.";
                    lbl_Status.ForeColor = Color.Red;

                    txt_Password.Clear();
                }
            }
        }
Beispiel #2
0
        public ConductSurvey(UserModelDataTransferObject LoggedUser, long SurveyID)
        {
            InitializeComponent();

            materialSkinManager = MaterialSkinManager.Instance;
            materialSkinManager.AddFormToManage(this);
            materialSkinManager.Theme       = MaterialSkinManager.Themes.LIGHT;
            materialSkinManager.ColorScheme = new ColorScheme(Primary.Blue800, Primary.Blue900, Primary.Blue500, Accent.LightBlue200, TextShade.WHITE);

            this.LoggedUser = LoggedUser;
            this.SurveyID   = SurveyID;

            AnswerButtons = new List <MaterialRadioButton>();
            AnswerButtons.Add(btn_Answer_0);
            AnswerButtons.Add(btn_Answer_1);
            AnswerButtons.Add(btn_Answer_2);
            AnswerButtons.Add(btn_Answer_3);
            AnswerButtons.Add(btn_Answer_4);
            AnswerButtons.Add(btn_Answer_5);

            panel_ConductSurvey.Enabled = panel_Finish.Enabled = false;
            panel_ConductSurvey.Visible = panel_Finish.Visible = false;

            lbl_Welcome_SurveyName.Font = lbl_SurveyName.Font = SurveyNameFont;
            btn_Welcome_Start.AutoSize  = btn_Success_Exit.AutoSize = false;
            btn_Welcome_Start.Size      = btn_Success_Exit.Size = new Size(190, 36);
            SetHorizontalMiddle(btn_Welcome_Start); SetHorizontalMiddle(btn_Success_Exit);

            btn_Next.AutoSize = btn_Back.AutoSize = btn_Finish.AutoSize = false;
            btn_Back.Size     = btn_Next.Size = btn_Finish.Size = new Size(195, 36);

            materialDivider_Menu.AutoSize = false;
            materialDivider_Menu.Location = new Point(0, 429);
            materialDivider_Menu.Size     = new Size(927, 10);
        }
Beispiel #3
0
        public Settings(UserModelDataTransferObject LoggedUser)
        {
            InitializeComponent();

            // Initialize MaterialSkinManager
            materialSkinManager = MaterialSkinManager.Instance;
            materialSkinManager.AddFormToManage(this);
            materialSkinManager.Theme       = MaterialSkinManager.Themes.LIGHT;
            materialSkinManager.ColorScheme = new ColorScheme(Primary.Blue800, Primary.Blue900, Primary.Blue500, Accent.LightBlue200, TextShade.WHITE);

            // Logged User
            this.LoggedUser = LoggedUser;

            // Initialize Fonts (Material Skin is buggy)
            lbl_EasySurvey.Font = EasySurveyFont;
            lbl_Owner.Font      = OwnerFont;
            lbl_Username.Font   = UsernameFont;
            lbl_UserRole.Font   = UserRoleFont;
            lbl_Info.ForeColor  = Color.Red;

            // Setting App Logo in middle.
            SetHorizontalMiddle(pic_EasySurveyLogo);
            SetHorizontalMiddle(pic_GitHub);
            SetHorizontalMiddle(btn_MeSaveChanges);

            // Initialize Update Class
            updater = new Updater();
        }
Beispiel #4
0
        private void LoadPasswordSettings()
        {
            using (UserController userController = new UserController())
                LoggedUser = userController.GetUserByID(LoggedUser.UserID);

            string UserPassword = LoggedUser.UserPassword;

            if (UserPassword == null) // No Password protection
            {
                rdb_UnlockPassword.Checked = true;
            }
            else // Password protected
            {
                rdb_LockPassword.Checked = true;
            }
        }
Beispiel #5
0
        public MainForm(UserModelDataTransferObject loggedUser)
        {
            InitializeComponent();

            var materialSkinManager = MaterialSkinManager.Instance;

            materialSkinManager.AddFormToManage(this);
            materialSkinManager.Theme       = MaterialSkinManager.Themes.LIGHT;
            materialSkinManager.ColorScheme = new ColorScheme(Primary.Blue800, Primary.Blue900, Primary.Blue500, Accent.LightBlue200, TextShade.WHITE);

            #region Initialize Component

            lbl_AboutUser.ForeColor      = AboutUser_ForeColor;
            lbl_AboutUser.Font           = AboutUser_FontDefault;
            lbl_AttitudeReportsInfo.Font = AttitudeReportsInfoFont;

            grb_SelectedSurveyAdmin.Location = new Point(472, 6);
            grb_SelectedSurveyUser.Location  = new Point(472, 6);

            #endregion

            this.LoggedUser = loggedUser;
        }
Beispiel #6
0
        // Promote / Demote users
        private void promoteDemoteToolStripMenuItem_Click(object sender, EventArgs e)
        {
            int SelectedUsersCount = listView_Users.SelectedItems.Count;

            if (SelectedUsersCount == 0)
            {
                return;
            }

            long AdminCount;
            long SelectedAdminCount;

            long AdminRoleID;
            long UserRoleID;

            using (UserController userController = new UserController())
                using (RoleController roleController = new RoleController())
                {
                    AdminRoleID = roleController.GetRoleID("Admin");
                    UserRoleID  = roleController.GetRoleID("User");

                    // Check if Admin want to demote all Admins
                    List <UserModelDataTransferObject> AdminsList = userController.GetUsersByRoleID(AdminRoleID);
                    AdminCount         = AdminsList.Count;
                    SelectedAdminCount = 0;

                    foreach (ListViewItem item in listView_Users.SelectedItems)
                    {
                        long UserID = Convert.ToInt64(item.Tag);
                        UserModelDataTransferObject CurrentUser = userController.GetUserByID(UserID);
                        if (CurrentUser.IsAdministrator())
                        {
                            ++SelectedAdminCount;
                        }
                    }
                }

            if (AdminCount == SelectedAdminCount && AdminCount == listView_Users.SelectedItems.Count)
            {
                MaterialMessageBox.Show("You cannot demote all Administrators.", "Easy Survey - Demote Users", MaterialMessageBox.MessageBoxButtons.OK, MaterialMessageBox.MessageBoxIcon.Error);
                return;
            }


            // Check if Admin wants to demote himself
            bool AdminSelectedHimself = false;

            foreach (ListViewItem item in listView_Users.SelectedItems)
            {
                long UserID = Convert.ToInt64(item.Tag);
                if (LoggedUser.UserID == UserID)
                {
                    AdminSelectedHimself = true; break;
                }
            }
            if (AdminSelectedHimself)
            {
                MaterialMessageBox.Show("You cannot demote yourself.", "Easy Survey - Demote Users", MaterialMessageBox.MessageBoxButtons.OK, MaterialMessageBox.MessageBoxIcon.Error);
                return;
            }

            // Demote / Promote selected users.
            using (UserController userController = new UserController())
                using (UserRoleController userRoleController = new UserRoleController())
                    foreach (ListViewItem item in listView_Users.SelectedItems)
                    {
                        long UserID = Convert.ToInt64(item.Tag);
                        UserModelDataTransferObject CurrentUser = userController.GetUserByID(UserID);
                        if (CurrentUser.IsAdministrator()) // Demote to standard user.
                        {
                            userRoleController.SetUserRole(UserID, UserRoleID);
                            item.Group = listView_Users.Groups["User"];
                        }
                        else if (!CurrentUser.IsAdministrator()) // Promote to admin.
                        {
                            userRoleController.SetUserRole(UserID, AdminRoleID);
                            item.Group = listView_Users.Groups["Administrator"];
                        }
                    }
        }
Beispiel #7
0
        private void materialContextMenuStrip_Users_Opening(object sender, CancelEventArgs e)
        {
            long SelectedUsers = listView_Users.SelectedItems.Count;

            // Promote / Demote ...
            bool Promote = false;
            bool Demote  = false;

            using (UserController userController = new UserController())
                foreach (ListViewItem item in listView_Users.SelectedItems)
                {
                    long UserID = Convert.ToInt64(item.Tag);
                    UserModelDataTransferObject CurrentUser = userController.GetUserByID(UserID);
                    if (CurrentUser.IsAdministrator())
                    {
                        Demote = true;
                    }
                    else
                    {
                        Promote = true;
                    }
                }

            if (Promote == Demote)
            {
                promoteDemoteToolStripMenuItem.Enabled = false;
                promoteDemoteToolStripMenuItem.Text    = "Promote / Demote...";
            }
            else
            {
                promoteDemoteToolStripMenuItem.Enabled = true;
                if (Promote)
                {
                    promoteDemoteToolStripMenuItem.Image = Properties.Resources.promote_icon_16x16;
                    promoteDemoteToolStripMenuItem.Text  = "Promote...";
                }
                else if (Demote)
                {
                    promoteDemoteToolStripMenuItem.Image = Properties.Resources.demote_icon_16x16;
                    promoteDemoteToolStripMenuItem.Text  = "Demote...";
                }
            }

            // Change / New ...
            bool Change = false;
            bool New    = false;

            if (SelectedUsers == 0)
            {
                return;
            }

            foreach (ListViewItem item in listView_Users.SelectedItems)
            {
                long UserID = Convert.ToInt64(item.Tag);
                UserModelDataTransferObject CurrentUser;
                using (UserController userController = new UserController())
                    CurrentUser = userController.GetUserByID(UserID);
                if (CurrentUser.UserPassword == null)
                {
                    New = true;
                }
                else
                {
                    Change = true;
                }
            }

            if (Change && New)
            {
                newToolStripMenuItem.Text = "Change / New...";
            }
            else if (Change)
            {
                newToolStripMenuItem.Text = "Change...";
            }
            else if (New)
            {
                newToolStripMenuItem.Text = "New...";
            }
        }
Beispiel #8
0
        private void deleteToolStripMenuItem_Click(object sender, EventArgs e)
        {
            int SelectedUsersCount = listView_Users.SelectedItems.Count;

            if (SelectedUsersCount == 0)
            {
                return;
            }

            IEnumerable <ListViewItem> SelectedUsers = listView_Users.SelectedItems.Cast <ListViewItem>();

            using (UserController userController = new UserController())
                using (RoleController roleController = new RoleController())
                {
                    // Check if Admin selected all Admins to be deleted.
                    long AdminRoleID = roleController.GetRoleID("Admin");
                    List <UserModelDataTransferObject> AdminsList = userController.GetUsersByRoleID(AdminRoleID);
                    long AdminCount         = AdminsList.Count;
                    long SelectedAdminCount = 0;
                    foreach (ListViewItem item in SelectedUsers)
                    {
                        long UserID = Convert.ToInt64(item.Tag);
                        UserModelDataTransferObject SelectedUser = userController.GetUserByID(UserID);
                        if (SelectedUser.IsAdministrator())
                        {
                            ++SelectedAdminCount;
                        }
                    }
                    if (AdminCount == SelectedAdminCount)
                    {
                        MaterialMessageBox.Show("You cannot delete all Administrators.", "Easy Survey - Delete Users", MaterialMessageBox.MessageBoxButtons.OK, MaterialMessageBox.MessageBoxIcon.Error);
                        return;
                    }

                    // Check if Admin selected his account to de deleted.
                    bool SelectedSelfAccount = false;
                    foreach (ListViewItem item in SelectedUsers)
                    {
                        long UserID = Convert.ToInt64(item.Tag);
                        if (LoggedUser.UserID == UserID)
                        {
                            SelectedSelfAccount = true; break;
                        }
                    }
                    if (SelectedSelfAccount)
                    {
                        MaterialMessageBox.Show("You cannot delete your own account.", "Easy Survey - Delete Users", MaterialMessageBox.MessageBoxButtons.OK, MaterialMessageBox.MessageBoxIcon.Error);
                        return;
                    }

                    // Delete selected users.
                    MaterialMessageBox.MessageBoxResult result = MaterialMessageBox.MessageBoxResult.None;
                    result = MaterialMessageBox.Show("Are you sure you want to delete all " + SelectedUsersCount + " selected users?", "Easy Survey - Delete Users", MaterialMessageBox.MessageBoxButtons.YesNo, MaterialMessageBox.MessageBoxIcon.Warning);

                    if (result == MaterialMessageBox.MessageBoxResult.Yes)
                    {
                        foreach (ListViewItem item in SelectedUsers)
                        {
                            long UserID = Convert.ToInt64(item.Tag);

                            // Delete from Database
                            userController.Delete(UserID);

                            // Delete from ListView
                            foreach (ListViewItem listViewItemToDelete in listView_Users.SelectedItems)
                            {
                                long ListViewUserID = Convert.ToInt64(listViewItemToDelete.Tag);
                                if (UserID == ListViewUserID)
                                {
                                    listView_Users.Items.Remove(listViewItemToDelete);
                                }
                            }
                        }
                    }
                }
        }
Beispiel #9
0
        private void btn_MeSaveChanges_Click(object sender, EventArgs e)
        {
            string ErrorMessage = String.Empty;

            using (UserController userController = new UserController())
            {
                long UserID = LoggedUser.UserID;
                ErrorMessage = String.Empty;

                if (!ProtectUserByPassword)
                {
                    userController.UpdatePassword(LoggedUser.UserID, null);
                    LoggedUser = userController.GetUserByID(UserID);
                }
                else
                {
                    string CurrentPassword   = SHA256.Hash(txt_CurrentPassword.Text);
                    string NewPassword       = txt_NewPassword.Text;
                    string ReTypeNewPassword = txt_ReTypeNewPassword.Text;

                    if (CurrentPassword != String.Empty || LoggedUser.UserPassword == null)
                    {
                        if (CurrentPassword == LoggedUser.UserPassword || LoggedUser.UserPassword == null)
                        {
                            if (NewPassword != String.Empty)
                            {
                                if (NewPassword.Equals(ReTypeNewPassword))
                                {
                                    NewPassword = SHA256.Hash(NewPassword);
                                    userController.UpdatePassword(LoggedUser.UserID, NewPassword);
                                    LoggedUser = userController.GetUserByID(UserID);
                                }
                                else
                                {
                                    ErrorMessage = "The new passwords are not the same";
                                }
                            }
                            else
                            {
                                ErrorMessage = "New password cannot be empty";
                            }
                        }
                        else
                        {
                            ErrorMessage = "Current password do not match";
                        }
                    }
                    else
                    {
                        ErrorMessage = "Current password cannot be empty";
                    }
                }
            }



            if (ErrorMessage == String.Empty)
            {
                txt_CurrentPassword.Clear();
                txt_NewPassword.Clear();
                txt_ReTypeNewPassword.Clear();
                PasswordSetStatus("You password has been successfully changed", false);
            }
            else
            {
                PasswordSetStatus(ErrorMessage);
            }
        }