From 1124eb01affe535b00f0bb23bb12a1df5fe5fe4a Mon Sep 17 00:00:00 2001 From: Nikotro Date: Tue, 17 May 2022 21:40:01 +0300 Subject: [PATCH 01/15] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D1=8F=D0=B5=D1=82=20=D0=BE=D0=BA=D0=BD=D0=BE=20=D0=B0=D0=B2?= =?UTF-8?q?=D1=82=D0=BE=D1=80=D0=B8=D0=B7=D0=B0=D1=86=D0=B8=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .vs/AwesomeEmailExtractor/project-colors.json | 11 ++ Authorisation.Designer.cs | 46 +++++++ Authorisation.cs | 20 +++ Authorisation.resx | 120 ++++++++++++++++++ AwesomeEmailExtractor.csproj | 9 ++ 5 files changed, 206 insertions(+) create mode 100644 .vs/AwesomeEmailExtractor/project-colors.json create mode 100644 Authorisation.Designer.cs create mode 100644 Authorisation.cs create mode 100644 Authorisation.resx diff --git a/.vs/AwesomeEmailExtractor/project-colors.json b/.vs/AwesomeEmailExtractor/project-colors.json new file mode 100644 index 0000000..e49ce8c --- /dev/null +++ b/.vs/AwesomeEmailExtractor/project-colors.json @@ -0,0 +1,11 @@ +{ + "Version": 1, + "ProjectMap": { + "fe70a2f9-d831-462e-8705-b14623544f1c": { + "ProjectGuid": "fe70a2f9-d831-462e-8705-b14623544f1c", + "DisplayName": "AwesomeEmailExtractor", + "ColorIndex": 0 + } + }, + "NextColorIndex": 1 +} \ No newline at end of file diff --git a/Authorisation.Designer.cs b/Authorisation.Designer.cs new file mode 100644 index 0000000..8dad99e --- /dev/null +++ b/Authorisation.Designer.cs @@ -0,0 +1,46 @@ +namespace AwesomeEmailExtractor +{ + partial class Authorisation + { + /// + /// 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.SuspendLayout(); + // + // Authorisation + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(800, 450); + this.Name = "Authorisation"; + this.Text = "Authorisation"; + this.ResumeLayout(false); + + } + + #endregion + } +} \ No newline at end of file diff --git a/Authorisation.cs b/Authorisation.cs new file mode 100644 index 0000000..c6d8b8b --- /dev/null +++ b/Authorisation.cs @@ -0,0 +1,20 @@ +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 Authorisation : Form + { + public Authorisation() + { + InitializeComponent(); + } + } +} diff --git a/Authorisation.resx b/Authorisation.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/Authorisation.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 diff --git a/AwesomeEmailExtractor.csproj b/AwesomeEmailExtractor.csproj index 3ae428d..210e8cb 100644 --- a/AwesomeEmailExtractor.csproj +++ b/AwesomeEmailExtractor.csproj @@ -46,6 +46,12 @@ + + Form + + + Authorisation.cs + Form @@ -55,6 +61,9 @@ + + Authorisation.cs + MainForm.cs From 43f9cc859e5b416814dcda213a36bf56def6933c Mon Sep 17 00:00:00 2001 From: Nikotro Date: Wed, 18 May 2022 00:29:58 +0300 Subject: [PATCH 02/15] =?UTF-8?q?=D0=A1=D0=B4=D0=B5=D0=BB=D0=B0=D0=BB?= =?UTF-8?q?=D0=BD=D0=BE=20=D0=BE=D0=BA=D0=BD=D0=BE=20=D0=B0=D0=B2=D1=82?= =?UTF-8?q?=D0=BE=D1=80=D0=B8=D0=B7=D0=B0=D1=86=D0=B8=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Authorisation.Designer.cs | 76 ++++++++++++++++++++++++++++++++++++++- Authorisation.cs | 1 + 2 files changed, 76 insertions(+), 1 deletion(-) diff --git a/Authorisation.Designer.cs b/Authorisation.Designer.cs index 8dad99e..900c295 100644 --- a/Authorisation.Designer.cs +++ b/Authorisation.Designer.cs @@ -28,19 +28,93 @@ /// private void InitializeComponent() { + this.loginButton = new System.Windows.Forms.Button(); + this.registerButton = new System.Windows.Forms.Button(); + this.entryLogin = new System.Windows.Forms.TextBox(); + this.label1 = new System.Windows.Forms.Label(); + this.label2 = new System.Windows.Forms.Label(); + this.entryPassword = new System.Windows.Forms.TextBox(); this.SuspendLayout(); // + // loginButton + // + this.loginButton.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(204))); + this.loginButton.Location = new System.Drawing.Point(12, 127); + this.loginButton.Name = "loginButton"; + this.loginButton.Size = new System.Drawing.Size(293, 23); + this.loginButton.TabIndex = 0; + this.loginButton.Text = "Авторизоваться"; + this.loginButton.UseVisualStyleBackColor = true; + // + // registerButton + // + this.registerButton.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(204))); + this.registerButton.Location = new System.Drawing.Point(12, 156); + this.registerButton.Name = "registerButton"; + this.registerButton.Size = new System.Drawing.Size(293, 23); + this.registerButton.TabIndex = 1; + this.registerButton.Text = "Зарегистрироваться"; + this.registerButton.UseVisualStyleBackColor = true; + // + // entryLogin + // + this.entryLogin.Location = new System.Drawing.Point(110, 32); + this.entryLogin.Name = "entryLogin"; + this.entryLogin.Size = new System.Drawing.Size(195, 20); + this.entryLogin.TabIndex = 2; + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Font = new System.Drawing.Font("Microsoft Sans Serif", 15.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(204))); + this.label1.Location = new System.Drawing.Point(12, 30); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(77, 25); + this.label1.TabIndex = 3; + this.label1.Text = "Логин:"; + // + // label2 + // + this.label2.AutoSize = true; + this.label2.Font = new System.Drawing.Font("Microsoft Sans Serif", 15.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(204))); + this.label2.Location = new System.Drawing.Point(12, 77); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(92, 25); + this.label2.TabIndex = 5; + this.label2.Text = "Пароль:"; + // + // entryPassword + // + this.entryPassword.Location = new System.Drawing.Point(110, 79); + this.entryPassword.Name = "entryPassword"; + this.entryPassword.Size = new System.Drawing.Size(195, 20); + this.entryPassword.TabIndex = 4; + // // Authorisation // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(800, 450); + this.ClientSize = new System.Drawing.Size(317, 191); + this.Controls.Add(this.label2); + this.Controls.Add(this.entryPassword); + this.Controls.Add(this.label1); + this.Controls.Add(this.entryLogin); + this.Controls.Add(this.registerButton); + this.Controls.Add(this.loginButton); this.Name = "Authorisation"; this.Text = "Authorisation"; this.ResumeLayout(false); + this.PerformLayout(); } #endregion + + private System.Windows.Forms.Button loginButton; + private System.Windows.Forms.Button registerButton; + private System.Windows.Forms.TextBox entryLogin; + private System.Windows.Forms.Label label1; + private System.Windows.Forms.Label label2; + private System.Windows.Forms.TextBox entryPassword; } } \ No newline at end of file diff --git a/Authorisation.cs b/Authorisation.cs index c6d8b8b..a35c077 100644 --- a/Authorisation.cs +++ b/Authorisation.cs @@ -16,5 +16,6 @@ namespace AwesomeEmailExtractor { InitializeComponent(); } + } } From dfff6faaccbf03eb1fe42f7fd7260cb2db995f55 Mon Sep 17 00:00:00 2001 From: Maxim Slipenko Date: Sat, 21 May 2022 23:33:56 +0300 Subject: [PATCH 03/15] =?UTF-8?q?=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D1=8F=D0=B5=D1=82=20=D0=B1=D0=B0=D0=B7=D0=BE=D0=B2=D1=83=D1=8E?= =?UTF-8?q?=20=D0=B0=D0=B2=D1=82=D0=BE=D1=80=D0=B8=D0=B7=D0=B0=D1=86=D0=B8?= =?UTF-8?q?=D1=8E=20=D1=87=D0=B5=D1=80=D0=B5=D0=B7=20SQLite?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Authorization.cs | 87 ++++++++++++++++++++++++++++++++++++ AwesomeEmailExtractor.csproj | 40 +++++++++++++++++ Globals.cs | 68 ++++++++++++++++++++++++++++ Program.cs | 24 ++++++++++ packages.config | 13 ++++++ 5 files changed, 232 insertions(+) create mode 100644 Authorization.cs create mode 100644 Globals.cs create mode 100644 packages.config diff --git a/Authorization.cs b/Authorization.cs new file mode 100644 index 0000000..8382da4 --- /dev/null +++ b/Authorization.cs @@ -0,0 +1,87 @@ +using System; +using System.Text; +using System.IO; +using System.Security.Cryptography; +using Microsoft.Data.Sqlite; + +namespace AwesomeEmailExtractor +{ + public class Authorization + { + public static User Login(string login, string password) + { + SqliteCommand command = new SqliteCommand(); + command.Connection = Globals.db; + command.CommandText = "SELECT login, role_id FROM users WHERE login = @login AND password = @password"; + + SqliteParameter loginParam = new SqliteParameter("@login", login); + command.Parameters.Add(loginParam); + + SqliteParameter passwordParam = new SqliteParameter("@password", EncryptPassword(password)); + command.Parameters.Add(passwordParam); + + SqliteDataReader reader = command.ExecuteReader(); + + while (reader.Read()) + { + return new User(reader.GetString(0), (UserRoles)reader.GetInt32(1)); + } + + throw new Exception("Пользователь не найден!"); + } + + public static User Register(string login, string password) + { + SqliteCommand command = new SqliteCommand(); + command.Connection = Globals.db; + command.CommandText = "INSERT INTO users (login, password, role_id) VALUES (@login, @password, 0);"; + + SqliteParameter loginParam = new SqliteParameter("@login", login); + command.Parameters.Add(loginParam); + + SqliteParameter passwordParam = new SqliteParameter("@password", EncryptPassword(password)); + command.Parameters.Add(passwordParam); + + try + { + command.ExecuteNonQuery(); + } catch (SqliteException e) + { + if (e.SqliteErrorCode == 19) { + throw new Exception("Имя пользователя занятно!"); + } + + throw new Exception($"Ошибка: {e.Message}"); + }; + + return new User(login, UserRoles.DEFAULT); + } + + public static string EncryptPassword(string password) + { + using (MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider()) + { + UTF8Encoding utf8 = new UTF8Encoding(); + byte[] data = md5.ComputeHash(utf8.GetBytes(password)); + return Convert.ToBase64String(data); + } + } + } + + public enum UserRoles + { + DEFAULT, + ADMIN + } + public class User + { + public string Login { get; set; } + public UserRoles Role { get; } + + public User(string login, UserRoles role) + { + Login = login; + Role = role; + } + } +} diff --git a/AwesomeEmailExtractor.csproj b/AwesomeEmailExtractor.csproj index 3ae428d..681d84e 100644 --- a/AwesomeEmailExtractor.csproj +++ b/AwesomeEmailExtractor.csproj @@ -12,6 +12,8 @@ 512 true true + + AnyCPU @@ -33,8 +35,36 @@ 4 + + packages\Microsoft.Data.Sqlite.Core.5.0.3\lib\netstandard2.0\Microsoft.Data.Sqlite.dll + + + packages\SQLitePCLRaw.bundle_e_sqlite3.2.0.4\lib\net461\SQLitePCLRaw.batteries_v2.dll + + + packages\SQLitePCLRaw.core.2.0.4\lib\netstandard2.0\SQLitePCLRaw.core.dll + + + packages\SQLitePCLRaw.bundle_e_sqlite3.2.0.4\lib\net461\SQLitePCLRaw.nativelibrary.dll + + + packages\SQLitePCLRaw.provider.dynamic_cdecl.2.0.4\lib\netstandard2.0\SQLitePCLRaw.provider.dynamic_cdecl.dll + + + packages\System.Buffers.4.4.0\lib\netstandard2.0\System.Buffers.dll + + + packages\System.Memory.4.5.3\lib\netstandard2.0\System.Memory.dll + + + + packages\System.Numerics.Vectors.4.4.0\lib\net46\System.Numerics.Vectors.dll + + + packages\System.Runtime.CompilerServices.Unsafe.4.5.2\lib\netstandard2.0\System.Runtime.CompilerServices.Unsafe.dll + @@ -46,7 +76,9 @@ + + Form @@ -67,6 +99,7 @@ True Resources.resx + SettingsSingleFileGenerator Settings.Designer.cs @@ -81,4 +114,11 @@ + + + + Данный проект ссылается на пакеты NuGet, отсутствующие на этом компьютере. Используйте восстановление пакетов NuGet, чтобы скачать их. Дополнительную информацию см. по адресу: http://go.microsoft.com/fwlink/?LinkID=322105. Отсутствует следующий файл: {0}. + + + \ No newline at end of file diff --git a/Globals.cs b/Globals.cs new file mode 100644 index 0000000..df03053 --- /dev/null +++ b/Globals.cs @@ -0,0 +1,68 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.IO; +using Microsoft.Data.Sqlite; + + +namespace AwesomeEmailExtractor +{ + internal class Globals + { + // Getter and setter for SQLite database connection + public static SqliteConnection db { get; set; } + + public static string getAppDirectory() + { + return Path.Combine( + Environment.GetFolderPath( + Environment.SpecialFolder.ApplicationData + ), + "AwesomeEmailExtractor" + ); + } + + public static string getAppDatabase() + { + return Path.Combine( + getAppDirectory(), + "database.db" + ); + } + + + + public static void CreateTables() + { + SqliteCommand command = new SqliteCommand(); + command.Connection = db; + + // Создать таблицу для хранения ролей + command.CommandText = "CREATE TABLE IF NOT EXISTS roles (id INTEGER PRIMARY KEY, name TEXT NOT NULL);"; + command.ExecuteNonQuery(); + + // Добавить роли + command.CommandText = "INSERT OR IGNORE INTO roles (id, name) VALUES (0, 'DEFAULT'), (1, 'ADMIN');"; + command.ExecuteNonQuery(); + + // Создать таблицу для хранения пользователей + command.CommandText = "CREATE TABLE IF NOT EXISTS users (id INTEGER PRIMARY KEY AUTOINCREMENT, login TEXT NOT NULL UNIQUE, password TEXT NOT NULL, role_id INTEGER NOT NULL, FOREIGN KEY(role_id) REFERENCES roles(id));"; + command.ExecuteNonQuery(); + + // Если таблица пуста - добавить пользователя по умолчанию + command.CommandText = "SELECT COUNT(*) FROM users"; + + if (Convert.ToInt32(command.ExecuteScalar()) == 0) + { + command.CommandText = "INSERT INTO users (login, password, role_id) VALUES ('admin', @password, 1);"; + + SqliteParameter passwordParam = new SqliteParameter("@password", Authorization.EncryptPassword("admin")); + command.Parameters.Add(passwordParam); + command.ExecuteNonQuery(); + command.Parameters.Clear(); + } + } + } +} diff --git a/Program.cs b/Program.cs index a06ccf4..874679d 100644 --- a/Program.cs +++ b/Program.cs @@ -3,6 +3,8 @@ using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using System.Windows.Forms; +using System.IO; +using Microsoft.Data.Sqlite; namespace AwesomeEmailExtractor { @@ -14,9 +16,31 @@ namespace AwesomeEmailExtractor [STAThread] static void Main() { + preMain(); + Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new MainForm()); + + postMain(); + } + + static void preMain() + { + if (!Directory.Exists(Globals.getAppDirectory())) + { + Directory.CreateDirectory(Globals.getAppDirectory()); + } + + Globals.db = new SqliteConnection("Data Source=" + Globals.getAppDatabase()); + Globals.db.Open(); + + Globals.CreateTables(); + } + + static void postMain() + { + Globals.db.Close(); } } } diff --git a/packages.config b/packages.config new file mode 100644 index 0000000..277899e --- /dev/null +++ b/packages.config @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file From a38dfe230860240bf4a436ff11d50fdceac79f83 Mon Sep 17 00:00:00 2001 From: Maxim Slipenko Date: Sun, 22 May 2022 00:01:07 +0300 Subject: [PATCH 04/15] =?UTF-8?q?=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D1=8F=D0=B5=D1=82=20=D0=BA=D0=BB=D0=B0=D1=81=D1=81=20AdminUtil?= =?UTF-8?q?s?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Authorization.cs | 66 ++++++++++++++++++++++++++++++++++++++++++++---- Program.cs | 6 +++++ 2 files changed, 67 insertions(+), 5 deletions(-) diff --git a/Authorization.cs b/Authorization.cs index 8382da4..233693e 100644 --- a/Authorization.cs +++ b/Authorization.cs @@ -3,6 +3,7 @@ using System.Text; using System.IO; using System.Security.Cryptography; using Microsoft.Data.Sqlite; +using System.Collections.Generic; namespace AwesomeEmailExtractor { @@ -12,7 +13,7 @@ namespace AwesomeEmailExtractor { SqliteCommand command = new SqliteCommand(); command.Connection = Globals.db; - command.CommandText = "SELECT login, role_id FROM users WHERE login = @login AND password = @password"; + command.CommandText = "SELECT * FROM users WHERE login = @login AND password = @password"; SqliteParameter loginParam = new SqliteParameter("@login", login); command.Parameters.Add(loginParam); @@ -24,7 +25,7 @@ namespace AwesomeEmailExtractor while (reader.Read()) { - return new User(reader.GetString(0), (UserRoles)reader.GetInt32(1)); + return new User(reader.GetInt32(0), reader.GetString(1), (UserRoles)reader.GetInt32(1)); } throw new Exception("Пользователь не найден!"); @@ -54,7 +55,7 @@ namespace AwesomeEmailExtractor throw new Exception($"Ошибка: {e.Message}"); }; - return new User(login, UserRoles.DEFAULT); + return Login(login, password); } public static string EncryptPassword(string password) @@ -75,13 +76,68 @@ namespace AwesomeEmailExtractor } public class User { - public string Login { get; set; } + public int ID { get; } + public string Login { get; } public UserRoles Role { get; } - public User(string login, UserRoles role) + public User(int id, string login, UserRoles role) { + ID = id; Login = login; Role = role; } + + } + + public class AdminUtils + { + public User User { get; set; } + + public AdminUtils(User user) + { + User = user; + } + public void setRole(string login, UserRoles role) + { + if (User.Role != UserRoles.ADMIN) + { + throw new Exception("Недостаточно прав!"); + } + + SqliteCommand command = new SqliteCommand(); + command.Connection = Globals.db; + command.CommandText = "UPDATE users SET role_id = @role WHERE login = @login"; + + SqliteParameter roleParam = new SqliteParameter("@role", (int)role); + command.Parameters.Add(roleParam); + + SqliteParameter loginParam = new SqliteParameter("@login", login); + command.Parameters.Add(loginParam); + + command.ExecuteNonQuery(); + } + + public List getAllUsers() + { + if (User.Role != UserRoles.ADMIN) + { + throw new Exception("Недостаточно прав!"); + } + + SqliteCommand command = new SqliteCommand(); + command.Connection = Globals.db; + command.CommandText = "SELECT * FROM users"; + + SqliteDataReader reader = command.ExecuteReader(); + + List users = new List(); + + while (reader.Read()) + { + users.Add(new User(reader.GetInt32(0), reader.GetString(1), (UserRoles)reader.GetInt32(2))); + } + + return users; + } } } diff --git a/Program.cs b/Program.cs index 874679d..eebf76d 100644 --- a/Program.cs +++ b/Program.cs @@ -17,7 +17,13 @@ namespace AwesomeEmailExtractor static void Main() { preMain(); + + User user = new User(1, "admin", UserRoles.ADMIN); + AdminUtils admin = new AdminUtils(user); + + + Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new MainForm()); From 7f9ca4200e2b3ff5d9bec0b1e039b379af6ea10d Mon Sep 17 00:00:00 2001 From: Maxim Slipenko Date: Sun, 22 May 2022 01:19:10 +0300 Subject: [PATCH 05/15] =?UTF-8?q?=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D1=8F=D0=B5=D1=82=20=D0=BA=D0=BB=D0=B0=D1=81=D1=81=20Logs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AwesomeEmailExtractor.csproj | 1 + Globals.cs | 58 ++++++++++++++++++- Logs.cs | 109 +++++++++++++++++++++++++++++++++++ MainForm.cs | 23 ++++++-- Program.cs | 13 +++-- 5 files changed, 192 insertions(+), 12 deletions(-) create mode 100644 Logs.cs diff --git a/AwesomeEmailExtractor.csproj b/AwesomeEmailExtractor.csproj index 681d84e..e40ec8d 100644 --- a/AwesomeEmailExtractor.csproj +++ b/AwesomeEmailExtractor.csproj @@ -79,6 +79,7 @@ + Form diff --git a/Globals.cs b/Globals.cs index df03053..4739d57 100644 --- a/Globals.cs +++ b/Globals.cs @@ -13,6 +13,7 @@ namespace AwesomeEmailExtractor { // Getter and setter for SQLite database connection public static SqliteConnection db { get; set; } + public static SqliteConnection logsDb { get; set; } public static string getAppDirectory() { @@ -32,7 +33,44 @@ namespace AwesomeEmailExtractor ); } - + public static string getDefaultPathAppLogs() + { + return Path.Combine( + getAppDirectory(), + "logs.db" + ); + } + + public static string getPathAppLogs() + { + SqliteCommand command = new SqliteCommand(); + command.Connection = db; + command.CommandText = "SELECT logs_db_path FROM app_settings LIMIT 1"; + + SqliteDataReader reader = command.ExecuteReader(); + while (reader.Read()) + { + return reader["logs_db_path"].ToString(); + } + + return getDefaultPathAppLogs(); + } + + public static void CreateLogsTable() + { + SqliteCommand command = new SqliteCommand(); + command.Connection = logsDb; + + command.CommandText = "CREATE TABLE IF NOT EXISTS logs_actions (id INTEGER PRIMARY KEY, name TEXT NOT NULL)"; + command.ExecuteNonQuery(); + + command.CommandText = "INSERT OR IGNORE INTO logs_actions (id, name) VALUES (0, 'Выполнение');"; + command.ExecuteNonQuery(); + + command.CommandText = "CREATE TABLE IF NOT EXISTS logs (id INTEGER PRIMARY KEY AUTOINCREMENT, user_id INTEGER NOT NULL, date TEXT NOT NULL, action INTEGER NOT NULL, message TEXT NOT NULL, FOREIGN KEY(action) REFERENCES logs_actions(id));"; + command.ExecuteNonQuery(); + + } public static void CreateTables() { @@ -44,7 +82,11 @@ namespace AwesomeEmailExtractor command.ExecuteNonQuery(); // Добавить роли - command.CommandText = "INSERT OR IGNORE INTO roles (id, name) VALUES (0, 'DEFAULT'), (1, 'ADMIN');"; + command.CommandText = "INSERT OR IGNORE INTO roles (id, name) VALUES (0, 'Обычный'), (1, 'Администратор');"; + command.ExecuteNonQuery(); + + // Создать таблицу для хранения настроек (знаю, так плохо, но сойдет) + command.CommandText = "CREATE TABLE IF NOT EXISTS app_settings (logs_db_path TEXT);"; command.ExecuteNonQuery(); // Создать таблицу для хранения пользователей @@ -63,6 +105,18 @@ namespace AwesomeEmailExtractor command.ExecuteNonQuery(); command.Parameters.Clear(); } + + command.CommandText = "SELECT COUNT(*) FROM app_settings"; + + if (Convert.ToInt32(command.ExecuteScalar()) == 0) + { + command.CommandText = "INSERT INTO app_settings (logs_db_path) VALUES (@logs_db_path);"; + + SqliteParameter logsDbPathParam = new SqliteParameter("@logs_db_path", getDefaultPathAppLogs()); + command.Parameters.Add(logsDbPathParam); + command.ExecuteNonQuery(); + command.Parameters.Clear(); + } } } } diff --git a/Logs.cs b/Logs.cs new file mode 100644 index 0000000..fa1a1bf --- /dev/null +++ b/Logs.cs @@ -0,0 +1,109 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Microsoft.Data.Sqlite; + +namespace AwesomeEmailExtractor +{ + public class Logs + { + public class LogData { + public User user; + public string date; + public Action action; + public string message; + } + + public enum Action + { + Execute, + } + + public static void Log(User user, Action action, Dictionary options) + { + SqliteCommand command = new SqliteCommand(); + command.Connection = Globals.logsDb; + + command.CommandText = "INSERT INTO logs (user_id, date, action, message) VALUES (@user_id, strftime('%Y-%m-%d %H:%M:%S', datetime('now')), @action, @message)"; + + command.Parameters.AddWithValue("@user_id", user.ID); + command.Parameters.AddWithValue("@action", action); + command.Parameters.AddWithValue("@message", GetLogMessage(action, options)); + + command.ExecuteNonQuery(); + } + + public static List GetLogs(User user) + { + SqliteCommand command = new SqliteCommand(); + command.Connection = Globals.logsDb; + + command.CommandText = "SELECT date, action, message FROM logs WHERE user_id = @user_id ORDER BY date DESC"; + command.Parameters.AddWithValue("@user_id", user.ID); + + SqliteDataReader reader = command.ExecuteReader(); + + List logs = new List(); + while (reader.Read()) + { + logs.Add(new LogData() + { + user = user, + date = reader.GetString(0), + action = (Action)reader.GetInt32(1), + message = reader.GetString(2) + }); + } + + return logs; + } + + public static List GetLogs() + { + SqliteCommand command = new SqliteCommand(); + command.Connection = Globals.logsDb; + command.CommandText = "ATTACH DATABASE @dbpath AS appDB"; + command.Parameters.AddWithValue("@dbpath", Globals.getAppDatabase()); + command.ExecuteNonQuery(); + + command.CommandText = "SELECT user_id, appDB.users.login, appDB.users.id as role_id, date, action, message FROM logs LEFT JOIN appDB.users ON logs.user_id = appDB.users.id ORDER BY date DESC "; + + SqliteDataReader reader = command.ExecuteReader(); + + List logs = new List(); + while (reader.Read()) + { + logs.Add(new LogData() + { + user = new User(reader.GetInt32(0), reader.GetString(1), (UserRoles)reader.GetInt32(2)), + date = reader.GetString(3), + action = (Action)reader.GetInt32(4), + message = reader.GetString(5) + }); + } + + return logs; + } + + public static string GetLogMessage(Action action, Dictionary options) + { + if (action == Action.Execute) + { + string sourceText = (string)options["sourceText"]; + int count = (int)options["count"]; + List uniqueEmails = options["uniqueEmails"] as List; + + + return $"Пользователь выполнил поиск email-ов c таким исходным текстом: [ {sourceText}. ]\n" + + $"Найдено {count} email-ов.\n" + + $"Список уникальных: {String.Join(", ", uniqueEmails)}."; + } + else + { + return ""; + } + } + } +} diff --git a/MainForm.cs b/MainForm.cs index c66334d..5317cb7 100644 --- a/MainForm.cs +++ b/MainForm.cs @@ -16,9 +16,18 @@ namespace AwesomeEmailExtractor { InitializeComponent(); } - + private void executeButton_Click(object sender, EventArgs e) { + // Получаем исходный текст из sourceRichTextBox + string sourceText = sourceRichTextBox.Text; + + if (sourceText.Length == 0) + { + MessageBox.Show("Введите текст в поле исходного текста", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + // Чистим предыдущий результат toolStripStatusLabel.Text = ""; resultCountLabel.Text = ""; @@ -27,9 +36,6 @@ namespace AwesomeEmailExtractor // Объявляем список уникальных e-mail-ов List uniqueEmails = new List(); - // Получаем исходный текст из sourceRichTextBox - string sourceText = sourceRichTextBox.Text; - // Вызываем метод для извлечения e-mail-ов int count = ExtactEmailsAlgorithm.Extract(sourceText, out uniqueEmails); @@ -37,6 +43,15 @@ namespace AwesomeEmailExtractor toolStripStatusLabel.Text = "Успех!"; resultCountLabel.Text = $"Количество e-mail-ов в тексте: {count}"; uniqueListBox.DataSource = uniqueEmails; + + Logs.Log( + new User(1, "", UserRoles.ADMIN), + Logs.Action.Execute, + new Dictionary() { + { "sourceText", sourceText }, + { "count", count }, + { "uniqueEmails", uniqueEmails } + }); } } } diff --git a/Program.cs b/Program.cs index eebf76d..5067411 100644 --- a/Program.cs +++ b/Program.cs @@ -18,11 +18,7 @@ namespace AwesomeEmailExtractor { preMain(); - User user = new User(1, "admin", UserRoles.ADMIN); - AdminUtils admin = new AdminUtils(user); - - - + Logs.GetLogs(); Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); @@ -37,11 +33,16 @@ namespace AwesomeEmailExtractor { Directory.CreateDirectory(Globals.getAppDirectory()); } - + Globals.db = new SqliteConnection("Data Source=" + Globals.getAppDatabase()); Globals.db.Open(); Globals.CreateTables(); + + Globals.logsDb = new SqliteConnection("Data Source=" + Globals.getPathAppLogs()); + Globals.logsDb.Open(); + + Globals.CreateLogsTable(); } static void postMain() From 613315a9881ecce8d0c756437ccbdd4778d7d06e Mon Sep 17 00:00:00 2001 From: Maxim Slipenko Date: Sun, 22 May 2022 07:19:14 +0300 Subject: [PATCH 06/15] =?UTF-8?q?=D0=BF=D0=B5=D1=80=D0=B5=D0=B8=D0=BC?= =?UTF-8?q?=D0=B5=D0=BD=D0=BE=D0=B2=D1=8B=D0=B2=D0=B0=D0=B5=D1=82=20=D1=84?= =?UTF-8?q?=D0=B0=D0=B9=D0=BB=20Autorisation=20>AuthorizationForm?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...sation.Designer.cs => AuthorizationForm.Designer.cs | 8 ++++---- Authorisation.cs => AuthorizationForm.cs | 4 ++-- Authorisation.resx => AuthorizationForm.resx | 0 AwesomeEmailExtractor.csproj | 10 +++++----- 4 files changed, 11 insertions(+), 11 deletions(-) rename Authorisation.Designer.cs => AuthorizationForm.Designer.cs (96%) rename Authorisation.cs => AuthorizationForm.cs (79%) rename Authorisation.resx => AuthorizationForm.resx (100%) diff --git a/Authorisation.Designer.cs b/AuthorizationForm.Designer.cs similarity index 96% rename from Authorisation.Designer.cs rename to AuthorizationForm.Designer.cs index 900c295..88bda87 100644 --- a/Authorisation.Designer.cs +++ b/AuthorizationForm.Designer.cs @@ -1,6 +1,6 @@ namespace AwesomeEmailExtractor { - partial class Authorisation + partial class AuthorizationForm { /// /// Required designer variable. @@ -90,7 +90,7 @@ this.entryPassword.Size = new System.Drawing.Size(195, 20); this.entryPassword.TabIndex = 4; // - // Authorisation + // AuthorizationForm // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; @@ -101,8 +101,8 @@ this.Controls.Add(this.entryLogin); this.Controls.Add(this.registerButton); this.Controls.Add(this.loginButton); - this.Name = "Authorisation"; - this.Text = "Authorisation"; + this.Name = "AuthorizationForm"; + this.Text = "Авторизоваться"; this.ResumeLayout(false); this.PerformLayout(); diff --git a/Authorisation.cs b/AuthorizationForm.cs similarity index 79% rename from Authorisation.cs rename to AuthorizationForm.cs index a35c077..5c3193b 100644 --- a/Authorisation.cs +++ b/AuthorizationForm.cs @@ -10,9 +10,9 @@ using System.Windows.Forms; namespace AwesomeEmailExtractor { - public partial class Authorisation : Form + public partial class AuthorizationForm : Form { - public Authorisation() + public AuthorizationForm() { InitializeComponent(); } diff --git a/Authorisation.resx b/AuthorizationForm.resx similarity index 100% rename from Authorisation.resx rename to AuthorizationForm.resx diff --git a/AwesomeEmailExtractor.csproj b/AwesomeEmailExtractor.csproj index 210e8cb..250de0e 100644 --- a/AwesomeEmailExtractor.csproj +++ b/AwesomeEmailExtractor.csproj @@ -46,11 +46,11 @@ - + Form - - Authorisation.cs + + AuthorizationForm.cs @@ -61,8 +61,8 @@ - - Authorisation.cs + + AuthorizationForm.cs MainForm.cs From 8e69fa569da18f64c4ce45c7432149f18a71d5d8 Mon Sep 17 00:00:00 2001 From: Maxim Slipenko Date: Sun, 22 May 2022 07:56:31 +0300 Subject: [PATCH 07/15] =?UTF-8?q?=D1=81=D0=BE=D0=B5=D0=B4=D0=B8=D0=BD?= =?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=20=D1=81=20=D1=84=D0=BE=D1=80=D0=BC?= =?UTF-8?q?=D0=BE=D0=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AuthorizationForm.Designer.cs | 4 ++++ AuthorizationForm.cs | 14 ++++++++++++++ Globals.cs | 2 ++ Program.cs | 6 +++--- 4 files changed, 23 insertions(+), 3 deletions(-) diff --git a/AuthorizationForm.Designer.cs b/AuthorizationForm.Designer.cs index 88bda87..1171308 100644 --- a/AuthorizationForm.Designer.cs +++ b/AuthorizationForm.Designer.cs @@ -45,6 +45,7 @@ this.loginButton.TabIndex = 0; this.loginButton.Text = "Авторизоваться"; this.loginButton.UseVisualStyleBackColor = true; + this.loginButton.Click += new System.EventHandler(this.loginButton_Click); // // registerButton // @@ -89,6 +90,7 @@ this.entryPassword.Name = "entryPassword"; this.entryPassword.Size = new System.Drawing.Size(195, 20); this.entryPassword.TabIndex = 4; + this.entryPassword.UseSystemPasswordChar = true; // // AuthorizationForm // @@ -101,6 +103,8 @@ this.Controls.Add(this.entryLogin); this.Controls.Add(this.registerButton); this.Controls.Add(this.loginButton); + this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle; + this.MaximizeBox = false; this.Name = "AuthorizationForm"; this.Text = "Авторизоваться"; this.ResumeLayout(false); diff --git a/AuthorizationForm.cs b/AuthorizationForm.cs index 5c3193b..e21020f 100644 --- a/AuthorizationForm.cs +++ b/AuthorizationForm.cs @@ -17,5 +17,19 @@ namespace AwesomeEmailExtractor InitializeComponent(); } + private void loginButton_Click(object sender, EventArgs e) + { + try + { + Globals.currentUser = Authorization.Login(entryLogin.Text, entryPassword.Text); + this.Close(); + + new MainForm().Show(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message); + } + } } } diff --git a/Globals.cs b/Globals.cs index 4739d57..afb38d5 100644 --- a/Globals.cs +++ b/Globals.cs @@ -15,6 +15,8 @@ namespace AwesomeEmailExtractor public static SqliteConnection db { get; set; } public static SqliteConnection logsDb { get; set; } + public static User currentUser { get; set; } + public static string getAppDirectory() { return Path.Combine( diff --git a/Program.cs b/Program.cs index 5067411..9047a40 100644 --- a/Program.cs +++ b/Program.cs @@ -18,11 +18,11 @@ namespace AwesomeEmailExtractor { preMain(); - Logs.GetLogs(); - Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); - Application.Run(new MainForm()); + + new AuthorizationForm().Show(); + Application.Run(); postMain(); } From d47b3ee319289bf3ecabeaa94d571351e141d75c Mon Sep 17 00:00:00 2001 From: Maxim Slipenko Date: Sun, 22 May 2022 08:14:59 +0300 Subject: [PATCH 08/15] =?UTF-8?q?=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D1=8F=D0=B5=D1=82=20=D1=84=D0=BE=D1=80=D0=BC=D1=83=20=D1=80?= =?UTF-8?q?=D0=B5=D0=B3=D0=B8=D1=81=D1=82=D1=80=D0=B0=D1=86=D0=B8=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AuthorizationForm.Designer.cs | 1 + AuthorizationForm.cs | 6 ++ AwesomeEmailExtractor.csproj | 9 ++ RegistrationForm.Designer.cs | 160 ++++++++++++++++++++++++++++++++++ RegistrationForm.cs | 32 +++++++ RegistrationForm.resx | 120 +++++++++++++++++++++++++ 6 files changed, 328 insertions(+) create mode 100644 RegistrationForm.Designer.cs create mode 100644 RegistrationForm.cs create mode 100644 RegistrationForm.resx diff --git a/AuthorizationForm.Designer.cs b/AuthorizationForm.Designer.cs index 88bda87..aef46bc 100644 --- a/AuthorizationForm.Designer.cs +++ b/AuthorizationForm.Designer.cs @@ -55,6 +55,7 @@ this.registerButton.TabIndex = 1; this.registerButton.Text = "Зарегистрироваться"; this.registerButton.UseVisualStyleBackColor = true; + this.registerButton.Click += new System.EventHandler(this.registerButton_Click); // // entryLogin // diff --git a/AuthorizationForm.cs b/AuthorizationForm.cs index 5c3193b..85fd7c0 100644 --- a/AuthorizationForm.cs +++ b/AuthorizationForm.cs @@ -17,5 +17,11 @@ namespace AwesomeEmailExtractor InitializeComponent(); } + private void registerButton_Click(object sender, EventArgs e) + { + this.Close(); + + new RegistrationForm().Show(); + } } } diff --git a/AwesomeEmailExtractor.csproj b/AwesomeEmailExtractor.csproj index 250de0e..546ede3 100644 --- a/AwesomeEmailExtractor.csproj +++ b/AwesomeEmailExtractor.csproj @@ -61,6 +61,12 @@ + + Form + + + RegistrationForm.cs + AuthorizationForm.cs @@ -76,6 +82,9 @@ True Resources.resx + + RegistrationForm.cs + SettingsSingleFileGenerator Settings.Designer.cs diff --git a/RegistrationForm.Designer.cs b/RegistrationForm.Designer.cs new file mode 100644 index 0000000..fde80ad --- /dev/null +++ b/RegistrationForm.Designer.cs @@ -0,0 +1,160 @@ +namespace AwesomeEmailExtractor +{ + partial class RegistrationForm + { + /// + /// 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.label2 = new System.Windows.Forms.Label(); + this.entryPassword = new System.Windows.Forms.TextBox(); + this.label1 = new System.Windows.Forms.Label(); + this.entryLogin = new System.Windows.Forms.TextBox(); + this.registerButton = new System.Windows.Forms.Button(); + this.loginButton = new System.Windows.Forms.Button(); + this.label3 = new System.Windows.Forms.Label(); + this.entryRePassword = new System.Windows.Forms.TextBox(); + this.label4 = new System.Windows.Forms.Label(); + this.SuspendLayout(); + // + // label2 + // + this.label2.AutoSize = true; + this.label2.Font = new System.Drawing.Font("Microsoft Sans Serif", 15.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(204))); + this.label2.Location = new System.Drawing.Point(9, 52); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(92, 25); + this.label2.TabIndex = 11; + this.label2.Text = "Пароль:"; + // + // entryPassword + // + this.entryPassword.Location = new System.Drawing.Point(183, 52); + this.entryPassword.Name = "entryPassword"; + this.entryPassword.Size = new System.Drawing.Size(195, 20); + this.entryPassword.TabIndex = 10; + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Font = new System.Drawing.Font("Microsoft Sans Serif", 15.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(204))); + this.label1.Location = new System.Drawing.Point(9, 10); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(77, 25); + this.label1.TabIndex = 9; + this.label1.Text = "Логин:"; + // + // entryLogin + // + this.entryLogin.Location = new System.Drawing.Point(183, 10); + this.entryLogin.Name = "entryLogin"; + this.entryLogin.Size = new System.Drawing.Size(195, 20); + this.entryLogin.TabIndex = 8; + // + // registerButton + // + this.registerButton.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(204))); + this.registerButton.Location = new System.Drawing.Point(14, 135); + this.registerButton.Name = "registerButton"; + this.registerButton.Size = new System.Drawing.Size(364, 23); + this.registerButton.TabIndex = 7; + this.registerButton.Text = "Зарегистрироваться"; + this.registerButton.UseVisualStyleBackColor = true; + // + // loginButton + // + this.loginButton.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(204))); + this.loginButton.Location = new System.Drawing.Point(14, 187); + this.loginButton.Name = "loginButton"; + this.loginButton.Size = new System.Drawing.Size(364, 23); + this.loginButton.TabIndex = 6; + this.loginButton.Text = "Авторизоваться"; + this.loginButton.UseVisualStyleBackColor = true; + this.loginButton.Click += new System.EventHandler(this.loginButton_Click); + // + // label3 + // + this.label3.AutoSize = true; + this.label3.Font = new System.Drawing.Font("Microsoft Sans Serif", 15.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(204))); + this.label3.Location = new System.Drawing.Point(9, 94); + this.label3.Name = "label3"; + this.label3.Size = new System.Drawing.Size(167, 25); + this.label3.TabIndex = 13; + this.label3.Text = "Повтор пароля:"; + // + // entryRePassword + // + this.entryRePassword.Location = new System.Drawing.Point(183, 94); + this.entryRePassword.Name = "entryRePassword"; + this.entryRePassword.Size = new System.Drawing.Size(195, 20); + this.entryRePassword.TabIndex = 12; + this.entryRePassword.UseSystemPasswordChar = true; + // + // label4 + // + this.label4.AutoSize = true; + this.label4.Font = new System.Drawing.Font("Microsoft Sans Serif", 11.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(204))); + this.label4.Location = new System.Drawing.Point(12, 166); + this.label4.Name = "label4"; + this.label4.Size = new System.Drawing.Size(178, 18); + this.label4.TabIndex = 14; + this.label4.Text = "Уже зарегистрированы?"; + this.label4.Click += new System.EventHandler(this.label4_Click); + // + // RegistrationForm + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(391, 222); + this.Controls.Add(this.label4); + this.Controls.Add(this.label3); + this.Controls.Add(this.entryRePassword); + this.Controls.Add(this.label2); + this.Controls.Add(this.entryPassword); + this.Controls.Add(this.label1); + this.Controls.Add(this.entryLogin); + this.Controls.Add(this.registerButton); + this.Controls.Add(this.loginButton); + this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle; + this.Name = "RegistrationForm"; + this.Text = "Зарегистрироваться"; + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private System.Windows.Forms.Label label2; + private System.Windows.Forms.TextBox entryPassword; + private System.Windows.Forms.Label label1; + private System.Windows.Forms.TextBox entryLogin; + private System.Windows.Forms.Button registerButton; + private System.Windows.Forms.Button loginButton; + private System.Windows.Forms.Label label3; + private System.Windows.Forms.TextBox entryRePassword; + private System.Windows.Forms.Label label4; + } +} \ No newline at end of file diff --git a/RegistrationForm.cs b/RegistrationForm.cs new file mode 100644 index 0000000..d996d9b --- /dev/null +++ b/RegistrationForm.cs @@ -0,0 +1,32 @@ +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 RegistrationForm : Form + { + public RegistrationForm() + { + InitializeComponent(); + } + + private void label4_Click(object sender, EventArgs e) + { + + } + + private void loginButton_Click(object sender, EventArgs e) + { + this.Close(); + + new AuthorizationForm().Show(); + } + } +} diff --git a/RegistrationForm.resx b/RegistrationForm.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/RegistrationForm.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 ff9e5827b7a82257c7b831ca50143930ab3c1a06 Mon Sep 17 00:00:00 2001 From: Maxim Slipenko Date: Sun, 22 May 2022 09:04:08 +0300 Subject: [PATCH 09/15] =?UTF-8?q?=D1=81=D0=BE=D0=B5=D0=B4=D0=B8=D0=BD?= =?UTF-8?q?=D1=8F=D0=B5=D1=82=20=D1=80=D0=B5=D0=B3=D0=B8=D1=81=D1=82=D1=80?= =?UTF-8?q?=D0=B0=D1=86=D0=B8=D1=8E=20=D1=81=20=D1=84=D0=BE=D1=80=D0=BC?= =?UTF-8?q?=D0=BE=D0=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AuthorizationForm.cs | 9 ++++--- AwesomeEmailExtractor.csproj | 1 + FormManager.cs | 46 ++++++++++++++++++++++++++++++++++++ Program.cs | 4 +--- RegistrationForm.Designer.cs | 8 ++++--- RegistrationForm.cs | 26 +++++++++++++++++--- 6 files changed, 80 insertions(+), 14 deletions(-) create mode 100644 FormManager.cs diff --git a/AuthorizationForm.cs b/AuthorizationForm.cs index ab3a202..d53f6da 100644 --- a/AuthorizationForm.cs +++ b/AuthorizationForm.cs @@ -22,9 +22,9 @@ namespace AwesomeEmailExtractor try { Globals.currentUser = Authorization.Login(entryLogin.Text, entryPassword.Text); - this.Close(); - new MainForm().Show(); + var mainForm = FormManager.Current.CreateForm(); + FormManager.Current.Navigate(this, mainForm); } catch (Exception ex) { @@ -34,9 +34,8 @@ namespace AwesomeEmailExtractor private void registerButton_Click(object sender, EventArgs e) { - this.Close(); - - new RegistrationForm().Show(); + var form = FormManager.Current.CreateForm(); + FormManager.Current.Navigate(this, form); } } } diff --git a/AwesomeEmailExtractor.csproj b/AwesomeEmailExtractor.csproj index 67135ee..e634b53 100644 --- a/AwesomeEmailExtractor.csproj +++ b/AwesomeEmailExtractor.csproj @@ -84,6 +84,7 @@ AuthorizationForm.cs + diff --git a/FormManager.cs b/FormManager.cs new file mode 100644 index 0000000..39a3473 --- /dev/null +++ b/FormManager.cs @@ -0,0 +1,46 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace AwesomeEmailExtractor +{ + public class FormManager : ApplicationContext + { + private void onFormClosed(object sender, EventArgs e) + { + if (Application.OpenForms.Count == 0) + { + if (((Form)sender).Name == currentForm) + ExitThread(); + } + } + + public T CreateForm() where T : Form, new() + { + var ret = new T(); + ret.FormClosed += onFormClosed; + return ret; + } + + public void Navigate(Form from, Form to) + { + currentForm = to.Name; + from.Close(); + to.Show(); + } + + public string currentForm = "AuthorizationForm"; + + private static Lazy _current = new Lazy(); + public static FormManager Current => _current.Value; + + public FormManager() + { + var authorization = CreateForm(); + authorization.Show(); + } + } +} diff --git a/Program.cs b/Program.cs index 9047a40..e40a3e9 100644 --- a/Program.cs +++ b/Program.cs @@ -20,9 +20,7 @@ namespace AwesomeEmailExtractor Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); - - new AuthorizationForm().Show(); - Application.Run(); + Application.Run(FormManager.Current); postMain(); } diff --git a/RegistrationForm.Designer.cs b/RegistrationForm.Designer.cs index fde80ad..7fe7ef6 100644 --- a/RegistrationForm.Designer.cs +++ b/RegistrationForm.Designer.cs @@ -55,6 +55,7 @@ this.entryPassword.Name = "entryPassword"; this.entryPassword.Size = new System.Drawing.Size(195, 20); this.entryPassword.TabIndex = 10; + this.entryPassword.UseSystemPasswordChar = true; // // label1 // @@ -79,9 +80,10 @@ this.registerButton.Location = new System.Drawing.Point(14, 135); this.registerButton.Name = "registerButton"; this.registerButton.Size = new System.Drawing.Size(364, 23); - this.registerButton.TabIndex = 7; + this.registerButton.TabIndex = 6; this.registerButton.Text = "Зарегистрироваться"; this.registerButton.UseVisualStyleBackColor = true; + this.registerButton.Click += new System.EventHandler(this.registerButton_Click); // // loginButton // @@ -89,7 +91,7 @@ this.loginButton.Location = new System.Drawing.Point(14, 187); this.loginButton.Name = "loginButton"; this.loginButton.Size = new System.Drawing.Size(364, 23); - this.loginButton.TabIndex = 6; + this.loginButton.TabIndex = 7; this.loginButton.Text = "Авторизоваться"; this.loginButton.UseVisualStyleBackColor = true; this.loginButton.Click += new System.EventHandler(this.loginButton_Click); @@ -121,7 +123,6 @@ this.label4.Size = new System.Drawing.Size(178, 18); this.label4.TabIndex = 14; this.label4.Text = "Уже зарегистрированы?"; - this.label4.Click += new System.EventHandler(this.label4_Click); // // RegistrationForm // @@ -140,6 +141,7 @@ this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle; this.Name = "RegistrationForm"; this.Text = "Зарегистрироваться"; + this.FormClosed += new System.Windows.Forms.FormClosedEventHandler(this.RegistrationForm_FormClosed); this.ResumeLayout(false); this.PerformLayout(); diff --git a/RegistrationForm.cs b/RegistrationForm.cs index d996d9b..18d62f5 100644 --- a/RegistrationForm.cs +++ b/RegistrationForm.cs @@ -17,16 +17,36 @@ namespace AwesomeEmailExtractor InitializeComponent(); } - private void label4_Click(object sender, EventArgs e) + private void registerButton_Click(object sender, EventArgs e) { + if (!string.Equals(entryPassword.Text, entryRePassword.Text)) + { + MessageBox.Show("Пароли не совпадают!"); + return; + } + try + { + Globals.currentUser = Authorization.Register(entryLogin.Text, entryPassword.Text); + + var form = FormManager.Current.CreateForm(); + FormManager.Current.Navigate(this, form); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message); + } } private void loginButton_Click(object sender, EventArgs e) { - this.Close(); + AuthorizationForm form = FormManager.Current.CreateForm(); + FormManager.Current.Navigate(this, form); + } - new AuthorizationForm().Show(); + private void RegistrationForm_FormClosed(object sender, FormClosedEventArgs e) + { + } } } From c8bb88a734715745dcee97b804d5868d5ce43a3d Mon Sep 17 00:00:00 2001 From: Maxim Slipenko Date: Sun, 22 May 2022 10:00:00 +0300 Subject: [PATCH 10/15] =?UTF-8?q?=D1=83=D0=BB=D1=83=D1=87=D1=88=D0=B0?= =?UTF-8?q?=D0=B5=D1=82=20=D0=BB=D0=BE=D0=B3=D0=B8=20=D0=B8=20=D0=B4=D0=BE?= =?UTF-8?q?=D0=B1=D0=B0=D0=B2=D0=BB=D1=8F=D0=B5=D1=82=20=D0=BC=D0=B5=D1=82?= =?UTF-8?q?=D0=BE=D0=B4=20=D0=B4=D0=BB=D1=8F=20=D1=83=D0=B4=D0=B0=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D1=8F=20=D0=BF=D0=BE=D0=BB=D1=8C=D0=B7=D0=BE?= =?UTF-8?q?=D0=B2=D0=B0=D1=82=D0=B5=D0=BB=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Authorization.cs | 16 ++++++++++++++++ AuthorizationForm.cs | 1 + Globals.cs | 2 +- Logs.cs | 22 +++++++++++++++++++--- MainForm.cs | 2 +- RegistrationForm.cs | 3 ++- 6 files changed, 40 insertions(+), 6 deletions(-) diff --git a/Authorization.cs b/Authorization.cs index 233693e..561041b 100644 --- a/Authorization.cs +++ b/Authorization.cs @@ -117,6 +117,22 @@ namespace AwesomeEmailExtractor command.ExecuteNonQuery(); } + public void deleteUser(string login) + { + if (User.Role != UserRoles.ADMIN) + { + throw new Exception("Недостаточно прав!"); + } + + SqliteCommand command = new SqliteCommand(); + command.Connection = Globals.db; + command.CommandText = "DELETE FROM users WHERE login = @login"; + + SqliteParameter loginParam = new SqliteParameter("@login", login); + command.Parameters.Add(loginParam); + + command.ExecuteNonQuery(); + } public List getAllUsers() { if (User.Role != UserRoles.ADMIN) diff --git a/AuthorizationForm.cs b/AuthorizationForm.cs index d53f6da..741cb61 100644 --- a/AuthorizationForm.cs +++ b/AuthorizationForm.cs @@ -22,6 +22,7 @@ namespace AwesomeEmailExtractor try { Globals.currentUser = Authorization.Login(entryLogin.Text, entryPassword.Text); + Logs.Log(Globals.currentUser, Logs.Action.Login, new Dictionary()); var mainForm = FormManager.Current.CreateForm(); FormManager.Current.Navigate(this, mainForm); diff --git a/Globals.cs b/Globals.cs index afb38d5..9ba88dd 100644 --- a/Globals.cs +++ b/Globals.cs @@ -66,7 +66,7 @@ namespace AwesomeEmailExtractor command.CommandText = "CREATE TABLE IF NOT EXISTS logs_actions (id INTEGER PRIMARY KEY, name TEXT NOT NULL)"; command.ExecuteNonQuery(); - command.CommandText = "INSERT OR IGNORE INTO logs_actions (id, name) VALUES (0, 'Выполнение');"; + command.CommandText = "INSERT OR IGNORE INTO logs_actions (id, name) VALUES (0, 'Выполнение'), (1, 'Вход'), (2, 'Регистрация');"; command.ExecuteNonQuery(); command.CommandText = "CREATE TABLE IF NOT EXISTS logs (id INTEGER PRIMARY KEY AUTOINCREMENT, user_id INTEGER NOT NULL, date TEXT NOT NULL, action INTEGER NOT NULL, message TEXT NOT NULL, FOREIGN KEY(action) REFERENCES logs_actions(id));"; diff --git a/Logs.cs b/Logs.cs index fa1a1bf..9b0a52d 100644 --- a/Logs.cs +++ b/Logs.cs @@ -19,6 +19,8 @@ namespace AwesomeEmailExtractor public enum Action { Execute, + Login, + Registration } public static void Log(User user, Action action, Dictionary options) @@ -68,7 +70,15 @@ namespace AwesomeEmailExtractor command.Parameters.AddWithValue("@dbpath", Globals.getAppDatabase()); command.ExecuteNonQuery(); - command.CommandText = "SELECT user_id, appDB.users.login, appDB.users.id as role_id, date, action, message FROM logs LEFT JOIN appDB.users ON logs.user_id = appDB.users.id ORDER BY date DESC "; + command.CommandText = @" + SELECT + user_id, + CASE WHEN appDB.users.login is NULL THEN 'Deleted_' || user_id ELSE appDB.users.login END AS login + appDB.users.role, + date, + action, + message + from logs LEFT JOIN appDB.users on logs.user_id = appDB.users.id ORDER BY date DESC"; SqliteDataReader reader = command.ExecuteReader(); @@ -100,10 +110,16 @@ namespace AwesomeEmailExtractor $"Найдено {count} email-ов.\n" + $"Список уникальных: {String.Join(", ", uniqueEmails)}."; } - else + if (action == Action.Login) { - return ""; + return "Пользователь вошел в систему."; } + if (action == Action.Registration) + { + return "Пользователь зарегистрировался в системе."; + } + + return ""; } } } diff --git a/MainForm.cs b/MainForm.cs index 5317cb7..ca6ca5a 100644 --- a/MainForm.cs +++ b/MainForm.cs @@ -45,7 +45,7 @@ namespace AwesomeEmailExtractor uniqueListBox.DataSource = uniqueEmails; Logs.Log( - new User(1, "", UserRoles.ADMIN), + Globals.currentUser, Logs.Action.Execute, new Dictionary() { { "sourceText", sourceText }, diff --git a/RegistrationForm.cs b/RegistrationForm.cs index 18d62f5..308f39b 100644 --- a/RegistrationForm.cs +++ b/RegistrationForm.cs @@ -28,7 +28,8 @@ namespace AwesomeEmailExtractor try { Globals.currentUser = Authorization.Register(entryLogin.Text, entryPassword.Text); - + Logs.Log(Globals.currentUser, Logs.Action.Registration, new Dictionary()); + var form = FormManager.Current.CreateForm(); FormManager.Current.Navigate(this, form); } From c412738640c407ad6248b9fc3a13611ee9377c0b Mon Sep 17 00:00:00 2001 From: Maxim Slipenko Date: Sun, 22 May 2022 10:56:32 +0300 Subject: [PATCH 11/15] =?UTF-8?q?=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D1=8F=D0=B5=D1=82=20=D1=83=D0=B4=D0=B0=D0=BB=D0=B5=D0=BD=D0=B8?= =?UTF-8?q?=D0=B5=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 12/15] =?UTF-8?q?=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D1=8F=D0=B5=D1=82=20=D1=81=D0=BC=D0=B5=D0=BD=D1=83=20=D0=BF?= =?UTF-8?q?=D0=B0=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 13/15] =?UTF-8?q?=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D1=8F=D0=B5=D1=82=20=D0=B2=D1=8B=D1=85=D0=BE=D0=B4=20=D0=B8?= =?UTF-8?q?=D0=B7=20=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 14/15] =?UTF-8?q?=D0=B8=D1=81=D0=BF=D1=80=D0=B0=D0=B2?= =?UTF-8?q?=D0=BB=D1=8F=D0=B5=D1=82=20=D0=B0=D0=B2=D1=82=D0=BE=D1=80=D0=B8?= =?UTF-8?q?=D0=B7=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 15/15] =?UTF-8?q?=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D1=8F=D0=B5=D1=82=20=D0=BE=D1=82=D0=BA=D0=BB=D1=8E=D1=87=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D0=B5=20=D0=BA=D0=BD=D0=BE=D0=BF=D0=BA=D0=B8=20?= =?UTF-8?q?=D0=90=D0=B4=D0=BC=D0=B8=D0=BD=D0=B8=D1=81=D1=82=D1=80=D0=B8?= =?UTF-8?q?=D1=80=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)