From c412738640c407ad6248b9fc3a13611ee9377c0b Mon Sep 17 00:00:00 2001 From: Maxim Slipenko Date: Sun, 22 May 2022 10:56:32 +0300 Subject: [PATCH 1/5] =?UTF-8?q?=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D1=8F?= =?UTF-8?q?=D0=B5=D1=82=20=D1=83=D0=B4=D0=B0=D0=BB=D0=B5=D0=BD=D0=B8=D0=B5?= =?UTF-8?q?=20=D0=B0=D0=BA=D0=BA=D0=B0=D1=83=D0=BD=D1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Authorization.cs | 11 ++++ AwesomeEmailExtractor.csproj | 9 +++ MainForm.Designer.cs | 38 +++++++++++ MainForm.cs | 6 ++ SettingsForm.Designer.cs | 122 +++++++++++++++++++++++++++++++++++ SettingsForm.cs | 36 +++++++++++ SettingsForm.resx | 120 ++++++++++++++++++++++++++++++++++ 7 files changed, 342 insertions(+) create mode 100644 SettingsForm.Designer.cs create mode 100644 SettingsForm.cs create mode 100644 SettingsForm.resx diff --git a/Authorization.cs b/Authorization.cs index 561041b..66eddc8 100644 --- a/Authorization.cs +++ b/Authorization.cs @@ -87,6 +87,17 @@ namespace AwesomeEmailExtractor Role = role; } + public void Delete() + { + SqliteCommand command = new SqliteCommand(); + command.Connection = Globals.db; + command.CommandText = "DELETE FROM users WHERE id = @id"; + + SqliteParameter loginParam = new SqliteParameter("@id", ID); + command.Parameters.Add(loginParam); + + command.ExecuteNonQuery(); + } } public class AdminUtils diff --git a/AwesomeEmailExtractor.csproj b/AwesomeEmailExtractor.csproj index e634b53..d078b5e 100644 --- a/AwesomeEmailExtractor.csproj +++ b/AwesomeEmailExtractor.csproj @@ -101,6 +101,12 @@ RegistrationForm.cs + + Form + + + SettingsForm.cs + AuthorizationForm.cs @@ -116,6 +122,9 @@ True Resources.resx + + SettingsForm.cs + RegistrationForm.cs diff --git a/MainForm.Designer.cs b/MainForm.Designer.cs index 8ce0ef9..d0cf934 100644 --- a/MainForm.Designer.cs +++ b/MainForm.Designer.cs @@ -37,6 +37,10 @@ this.menuStrip1 = new System.Windows.Forms.MenuStrip(); this.fileToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.helpToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.аккаунтToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.settingsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.administrationToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.exitToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.resultStatusStrip.SuspendLayout(); this.menuStrip1.SuspendLayout(); this.SuspendLayout(); @@ -112,6 +116,7 @@ // this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { this.fileToolStripMenuItem, + this.аккаунтToolStripMenuItem, this.helpToolStripMenuItem}); this.menuStrip1.Location = new System.Drawing.Point(0, 0); this.menuStrip1.Name = "menuStrip1"; @@ -131,6 +136,35 @@ this.helpToolStripMenuItem.Size = new System.Drawing.Size(65, 20); this.helpToolStripMenuItem.Text = "Справка"; // + // аккаунтToolStripMenuItem + // + this.аккаунтToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.settingsToolStripMenuItem, + this.administrationToolStripMenuItem, + this.exitToolStripMenuItem}); + this.аккаунтToolStripMenuItem.Name = "аккаунтToolStripMenuItem"; + this.аккаунтToolStripMenuItem.Size = new System.Drawing.Size(63, 20); + this.аккаунтToolStripMenuItem.Text = "Аккаунт"; + // + // settingsToolStripMenuItem + // + this.settingsToolStripMenuItem.Name = "settingsToolStripMenuItem"; + this.settingsToolStripMenuItem.Size = new System.Drawing.Size(189, 22); + this.settingsToolStripMenuItem.Text = "Настройки"; + this.settingsToolStripMenuItem.Click += new System.EventHandler(this.settingsToolStripMenuItem_Click); + // + // administrationToolStripMenuItem + // + this.administrationToolStripMenuItem.Name = "administrationToolStripMenuItem"; + this.administrationToolStripMenuItem.Size = new System.Drawing.Size(189, 22); + this.administrationToolStripMenuItem.Text = "Администрирование"; + // + // exitToolStripMenuItem + // + this.exitToolStripMenuItem.Name = "exitToolStripMenuItem"; + this.exitToolStripMenuItem.Size = new System.Drawing.Size(189, 22); + this.exitToolStripMenuItem.Text = "Выход"; + // // MainForm // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); @@ -166,6 +200,10 @@ private System.Windows.Forms.ToolStripMenuItem fileToolStripMenuItem; private System.Windows.Forms.ToolStripMenuItem helpToolStripMenuItem; private System.Windows.Forms.ToolStripStatusLabel toolStripStatusLabel; + private System.Windows.Forms.ToolStripMenuItem аккаунтToolStripMenuItem; + private System.Windows.Forms.ToolStripMenuItem settingsToolStripMenuItem; + private System.Windows.Forms.ToolStripMenuItem administrationToolStripMenuItem; + private System.Windows.Forms.ToolStripMenuItem exitToolStripMenuItem; } } diff --git a/MainForm.cs b/MainForm.cs index ca6ca5a..c37dbf9 100644 --- a/MainForm.cs +++ b/MainForm.cs @@ -53,5 +53,11 @@ namespace AwesomeEmailExtractor { "uniqueEmails", uniqueEmails } }); } + + private void settingsToolStripMenuItem_Click(object sender, EventArgs e) + { + SettingsForm settingsForm = FormManager.Current.CreateForm(); + settingsForm.ShowDialog(this); + } } } diff --git a/SettingsForm.Designer.cs b/SettingsForm.Designer.cs new file mode 100644 index 0000000..c139b18 --- /dev/null +++ b/SettingsForm.Designer.cs @@ -0,0 +1,122 @@ +namespace AwesomeEmailExtractor +{ + partial class SettingsForm + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.changePasswordButton = new System.Windows.Forms.Button(); + this.entryNewPassword = new System.Windows.Forms.TextBox(); + this.label2 = new System.Windows.Forms.Label(); + this.label3 = new System.Windows.Forms.Label(); + this.entryRePassword = new System.Windows.Forms.TextBox(); + this.deleteAccountButton = new System.Windows.Forms.Button(); + this.SuspendLayout(); + // + // changePasswordButton + // + this.changePasswordButton.Location = new System.Drawing.Point(34, 96); + this.changePasswordButton.Name = "changePasswordButton"; + this.changePasswordButton.Size = new System.Drawing.Size(275, 26); + this.changePasswordButton.TabIndex = 0; + this.changePasswordButton.Text = "Изменить пароль"; + this.changePasswordButton.UseVisualStyleBackColor = true; + // + // entryNewPassword + // + this.entryNewPassword.Location = new System.Drawing.Point(158, 12); + this.entryNewPassword.Name = "entryNewPassword"; + this.entryNewPassword.Size = new System.Drawing.Size(151, 20); + this.entryNewPassword.TabIndex = 2; + this.entryNewPassword.UseSystemPasswordChar = true; + // + // label2 + // + this.label2.AutoSize = true; + this.label2.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(204))); + this.label2.Location = new System.Drawing.Point(30, 12); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(118, 20); + this.label2.TabIndex = 4; + this.label2.Text = "Новый пароль"; + // + // label3 + // + this.label3.AutoSize = true; + this.label3.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(204))); + this.label3.Location = new System.Drawing.Point(30, 53); + this.label3.Name = "label3"; + this.label3.Size = new System.Drawing.Size(125, 20); + this.label3.TabIndex = 5; + this.label3.Text = "Повтор пароля"; + // + // entryRePassword + // + this.entryRePassword.Location = new System.Drawing.Point(158, 53); + this.entryRePassword.Name = "entryRePassword"; + this.entryRePassword.Size = new System.Drawing.Size(151, 20); + this.entryRePassword.TabIndex = 6; + this.entryRePassword.UseSystemPasswordChar = true; + // + // deleteAccountButton + // + this.deleteAccountButton.Location = new System.Drawing.Point(34, 137); + this.deleteAccountButton.Name = "deleteAccountButton"; + this.deleteAccountButton.Size = new System.Drawing.Size(275, 26); + this.deleteAccountButton.TabIndex = 7; + this.deleteAccountButton.Text = "Удалить аккаунт"; + this.deleteAccountButton.UseVisualStyleBackColor = true; + this.deleteAccountButton.Click += new System.EventHandler(this.deleteAccountButton_Click); + // + // SettingsForm + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(338, 184); + this.Controls.Add(this.deleteAccountButton); + this.Controls.Add(this.entryRePassword); + this.Controls.Add(this.label3); + this.Controls.Add(this.label2); + this.Controls.Add(this.entryNewPassword); + this.Controls.Add(this.changePasswordButton); + this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle; + this.Name = "SettingsForm"; + this.Text = "Настройки"; + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private System.Windows.Forms.Button changePasswordButton; + private System.Windows.Forms.TextBox entryNewPassword; + private System.Windows.Forms.Label label2; + private System.Windows.Forms.Label label3; + private System.Windows.Forms.TextBox entryRePassword; + private System.Windows.Forms.Button deleteAccountButton; + } +} \ No newline at end of file diff --git a/SettingsForm.cs b/SettingsForm.cs new file mode 100644 index 0000000..5d516e9 --- /dev/null +++ b/SettingsForm.cs @@ -0,0 +1,36 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace AwesomeEmailExtractor +{ + public partial class SettingsForm : Form + { + public SettingsForm() + { + InitializeComponent(); + } + + private void deleteAccountButton_Click(object sender, EventArgs e) + { + DialogResult result = MessageBox.Show("Вы уверены что хотите удалить аккаунт?", "Удаление аккаунта", MessageBoxButtons.YesNo); + + if (result == DialogResult.Yes) + { + Globals.currentUser.Delete(); + MessageBox.Show("Аккаунт удален"); + + this.Close(); + + AuthorizationForm authorization = FormManager.Current.CreateForm(); + FormManager.Current.Navigate(this.Owner, authorization); + } + } + } +} diff --git a/SettingsForm.resx b/SettingsForm.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/SettingsForm.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file From 121abac88e2e3e13bb9cd6e34679223fb30e311c Mon Sep 17 00:00:00 2001 From: Maxim Slipenko Date: Sun, 22 May 2022 11:08:55 +0300 Subject: [PATCH 2/5] =?UTF-8?q?=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D1=8F?= =?UTF-8?q?=D0=B5=D1=82=20=D1=81=D0=BC=D0=B5=D0=BD=D1=83=20=D0=BF=D0=B0?= =?UTF-8?q?=D1=80=D0=BE=D0=BB=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Authorization.cs | 21 ++++++++++++++++++--- SettingsForm.Designer.cs | 1 + SettingsForm.cs | 14 +++++++++++++- 3 files changed, 32 insertions(+), 4 deletions(-) diff --git a/Authorization.cs b/Authorization.cs index 66eddc8..25b3ded 100644 --- a/Authorization.cs +++ b/Authorization.cs @@ -91,13 +91,28 @@ namespace AwesomeEmailExtractor { SqliteCommand command = new SqliteCommand(); command.Connection = Globals.db; - command.CommandText = "DELETE FROM users WHERE id = @id"; + command.CommandText = "DELETE FROM users WHERE id = @id;"; - SqliteParameter loginParam = new SqliteParameter("@id", ID); - command.Parameters.Add(loginParam); + SqliteParameter idParam = new SqliteParameter("@id", ID); + command.Parameters.Add(idParam); command.ExecuteNonQuery(); } + + public void ChangePassword(string password) + { + SqliteCommand command = new SqliteCommand(); + command.Connection = Globals.db; + command.CommandText = "UPDATE users SET password = @password WHERE id = @id;"; + + SqliteParameter idParam = new SqliteParameter("@id", ID); + command.Parameters.Add(idParam); + + SqliteParameter passwordParam = new SqliteParameter("@password", Authorization.EncryptPassword(password)); + command.Parameters.Add(passwordParam); + + command.ExecuteNonQuery(); + } } public class AdminUtils diff --git a/SettingsForm.Designer.cs b/SettingsForm.Designer.cs index c139b18..e4c61bf 100644 --- a/SettingsForm.Designer.cs +++ b/SettingsForm.Designer.cs @@ -44,6 +44,7 @@ this.changePasswordButton.TabIndex = 0; this.changePasswordButton.Text = "Изменить пароль"; this.changePasswordButton.UseVisualStyleBackColor = true; + this.changePasswordButton.Click += new System.EventHandler(this.changePasswordButton_Click); // // entryNewPassword // diff --git a/SettingsForm.cs b/SettingsForm.cs index 5d516e9..9d3aaac 100644 --- a/SettingsForm.cs +++ b/SettingsForm.cs @@ -24,7 +24,7 @@ namespace AwesomeEmailExtractor if (result == DialogResult.Yes) { Globals.currentUser.Delete(); - MessageBox.Show("Аккаунт удален"); + MessageBox.Show("Аккаунт удален!"); this.Close(); @@ -32,5 +32,17 @@ namespace AwesomeEmailExtractor FormManager.Current.Navigate(this.Owner, authorization); } } + + private void changePasswordButton_Click(object sender, EventArgs e) + { + if (!string.Equals(entryNewPassword.Text, entryRePassword.Text)) + { + MessageBox.Show("Пароли не совпадают!"); + return; + } + + Globals.currentUser.ChangePassword(entryNewPassword.Text); + MessageBox.Show("Пароль изменен!"); + } } } From 5e5aff5f7d8d44dcd6552eda470e1fcca3537fd1 Mon Sep 17 00:00:00 2001 From: Maxim Slipenko Date: Sun, 22 May 2022 11:12:41 +0300 Subject: [PATCH 3/5] =?UTF-8?q?=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D1=8F?= =?UTF-8?q?=D0=B5=D1=82=20=D0=B2=D1=8B=D1=85=D0=BE=D0=B4=20=D0=B8=D0=B7=20?= =?UTF-8?q?=D0=B0=D0=BA=D0=BA=D0=B0=D1=83=D0=BD=D1=82=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- MainForm.Designer.cs | 15 ++++++++------- MainForm.cs | 7 +++++++ 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/MainForm.Designer.cs b/MainForm.Designer.cs index d0cf934..f949bab 100644 --- a/MainForm.Designer.cs +++ b/MainForm.Designer.cs @@ -36,11 +36,11 @@ this.toolStripStatusLabel = new System.Windows.Forms.ToolStripStatusLabel(); this.menuStrip1 = new System.Windows.Forms.MenuStrip(); this.fileToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.helpToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.аккаунтToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.settingsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.administrationToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.exitToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.helpToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.resultStatusStrip.SuspendLayout(); this.menuStrip1.SuspendLayout(); this.SuspendLayout(); @@ -130,12 +130,6 @@ this.fileToolStripMenuItem.Size = new System.Drawing.Size(48, 20); this.fileToolStripMenuItem.Text = "Файл"; // - // helpToolStripMenuItem - // - this.helpToolStripMenuItem.Name = "helpToolStripMenuItem"; - this.helpToolStripMenuItem.Size = new System.Drawing.Size(65, 20); - this.helpToolStripMenuItem.Text = "Справка"; - // // аккаунтToolStripMenuItem // this.аккаунтToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { @@ -164,6 +158,13 @@ this.exitToolStripMenuItem.Name = "exitToolStripMenuItem"; this.exitToolStripMenuItem.Size = new System.Drawing.Size(189, 22); this.exitToolStripMenuItem.Text = "Выход"; + this.exitToolStripMenuItem.Click += new System.EventHandler(this.exitToolStripMenuItem_Click); + // + // helpToolStripMenuItem + // + this.helpToolStripMenuItem.Name = "helpToolStripMenuItem"; + this.helpToolStripMenuItem.Size = new System.Drawing.Size(65, 20); + this.helpToolStripMenuItem.Text = "Справка"; // // MainForm // diff --git a/MainForm.cs b/MainForm.cs index c37dbf9..9297da1 100644 --- a/MainForm.cs +++ b/MainForm.cs @@ -59,5 +59,12 @@ namespace AwesomeEmailExtractor SettingsForm settingsForm = FormManager.Current.CreateForm(); settingsForm.ShowDialog(this); } + + private void exitToolStripMenuItem_Click(object sender, EventArgs e) + { + Globals.currentUser = null; + AuthorizationForm authorization = FormManager.Current.CreateForm(); + FormManager.Current.Navigate(this, authorization); + } } } From a8ea3fe2794ddddc7e30dc002f34006c20592673 Mon Sep 17 00:00:00 2001 From: Maxim Slipenko Date: Sun, 22 May 2022 11:17:53 +0300 Subject: [PATCH 4/5] =?UTF-8?q?=D0=B8=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D1=8F=D0=B5=D1=82=20=D0=B0=D0=B2=D1=82=D0=BE=D1=80=D0=B8=D0=B7?= =?UTF-8?q?=D0=B0=D1=86=D0=B8=D1=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Authorization.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Authorization.cs b/Authorization.cs index 25b3ded..81f550d 100644 --- a/Authorization.cs +++ b/Authorization.cs @@ -13,7 +13,7 @@ namespace AwesomeEmailExtractor { SqliteCommand command = new SqliteCommand(); command.Connection = Globals.db; - command.CommandText = "SELECT * FROM users WHERE login = @login AND password = @password"; + command.CommandText = "SELECT id, login, role_id FROM users WHERE login = @login AND password = @password"; SqliteParameter loginParam = new SqliteParameter("@login", login); command.Parameters.Add(loginParam); @@ -25,7 +25,7 @@ namespace AwesomeEmailExtractor while (reader.Read()) { - return new User(reader.GetInt32(0), reader.GetString(1), (UserRoles)reader.GetInt32(1)); + return new User(reader.GetInt32(0), reader.GetString(1), (UserRoles)reader.GetInt32(2)); } throw new Exception("Пользователь не найден!"); From 5f3aa8fcd068031fb112f4b6ca1dec713ab879fc Mon Sep 17 00:00:00 2001 From: Maxim Slipenko Date: Sun, 22 May 2022 11:18:49 +0300 Subject: [PATCH 5/5] =?UTF-8?q?=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D1=8F?= =?UTF-8?q?=D0=B5=D1=82=20=D0=BE=D1=82=D0=BA=D0=BB=D1=8E=D1=87=D0=B5=D0=BD?= =?UTF-8?q?=D0=B8=D0=B5=20=D0=BA=D0=BD=D0=BE=D0=BF=D0=BA=D0=B8=20=D0=90?= =?UTF-8?q?=D0=B4=D0=BC=D0=B8=D0=BD=D0=B8=D1=81=D1=82=D1=80=D0=B8=D1=80?= =?UTF-8?q?=D0=BE=D0=B2=D0=B0=D0=BD=D0=B8=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- MainForm.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/MainForm.cs b/MainForm.cs index 9297da1..5ebee65 100644 --- a/MainForm.cs +++ b/MainForm.cs @@ -15,6 +15,8 @@ namespace AwesomeEmailExtractor public MainForm() { InitializeComponent(); + + administrationToolStripMenuItem.Enabled = Globals.currentUser.Role == UserRoles.ADMIN; } private void executeButton_Click(object sender, EventArgs e)