From 7f9513083454ccf04fa754cf26c266403949b9ff Mon Sep 17 00:00:00 2001 From: Pilzinsel64 Date: Mon, 10 Jun 2024 21:13:59 +0200 Subject: [PATCH] login! --- OwnChar.App.Desktop/Api/IMainWindowApi.cs | 1 + OwnChar.App.Desktop/Api/LoginProvider.cs | 18 ++ OwnChar.App.Desktop/AppApi.cs | 18 +- OwnChar.App.Desktop/FeatureCodes.cs | 1 + .../LoginProviders/JsonFileLoginProvider.cs | 43 ++++ ....cs => CharListControlLangRes.Designer.cs} | 6 +- ...ntrol.resx => CharListControlLangRes.resx} | 0 ...signer.cs => LoginPageLangRes.Designer.cs} | 26 ++- ...PageLangRes.resx => LoginPageLangRes.resx} | 8 +- .../OwnChar.App.Desktop.csproj | 16 +- .../Settings/JsonFileLoginProviderSettings.cs | 15 ++ .../UI/MainTabs/TabLoginView.Designer.cs | 184 ++++++++++++------ .../UI/MainTabs/TabLoginView.cs | 82 ++++++-- .../UI/Windows/MainWindow.Designer.cs | 1 + OwnChar.App.Desktop/UI/Windows/MainWindow.cs | 7 + 15 files changed, 330 insertions(+), 96 deletions(-) create mode 100644 OwnChar.App.Desktop/Api/LoginProvider.cs create mode 100644 OwnChar.App.Desktop/Features/LoginProviders/JsonFileLoginProvider.cs rename OwnChar.App.Desktop/LangRes/{LangResCharListControl.Designer.cs => CharListControlLangRes.Designer.cs} (95%) rename OwnChar.App.Desktop/LangRes/{LangResCharListControl.resx => CharListControlLangRes.resx} (100%) rename OwnChar.App.Desktop/LangRes/{HomePageLangRes.Designer.cs => LoginPageLangRes.Designer.cs} (76%) rename OwnChar.App.Desktop/LangRes/{HomePageLangRes.resx => LoginPageLangRes.resx} (94%) create mode 100644 OwnChar.App.Desktop/Settings/JsonFileLoginProviderSettings.cs diff --git a/OwnChar.App.Desktop/Api/IMainWindowApi.cs b/OwnChar.App.Desktop/Api/IMainWindowApi.cs index 8187294..5859654 100644 --- a/OwnChar.App.Desktop/Api/IMainWindowApi.cs +++ b/OwnChar.App.Desktop/Api/IMainWindowApi.cs @@ -5,6 +5,7 @@ namespace OwnChar.App.Desktop.Api { public interface IMainWindowApi { + Form Window { get; } OwnCharManager? Manager { get; } void OpenTab(Control content, string title); void CloseTab(Control content); diff --git a/OwnChar.App.Desktop/Api/LoginProvider.cs b/OwnChar.App.Desktop/Api/LoginProvider.cs new file mode 100644 index 0000000..2e984d1 --- /dev/null +++ b/OwnChar.App.Desktop/Api/LoginProvider.cs @@ -0,0 +1,18 @@ +using OwnChar.Data; +using Pilz.Plugins.Advanced; + +namespace OwnChar.App.Desktop.Api; + +public abstract class LoginProvider : PluginFeature +{ + public abstract IDataManager GetDefault(IMainWindowApi api); + public abstract void Configure(IMainWindowApi api, ref IDataManager? manager); + + protected LoginProvider(string featureType, string identifier) : base(featureType, identifier) + { + } + + protected LoginProvider(string featureType, string featureIdentifier, string? featureName) : base(featureType, featureIdentifier, featureName) + { + } +} diff --git a/OwnChar.App.Desktop/AppApi.cs b/OwnChar.App.Desktop/AppApi.cs index cccac22..66c2671 100644 --- a/OwnChar.App.Desktop/AppApi.cs +++ b/OwnChar.App.Desktop/AppApi.cs @@ -1,17 +1,11 @@ using OwnChar.App.Desktop.Api; using Pilz.Configuration; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -namespace OwnChar.App.Desktop +namespace OwnChar.App.Desktop; + +public sealed class AppApi : IOwnCharApi { - public sealed class AppApi : IOwnCharApi - { - public static AppApi Instance { get; } = new(); - public IMainWindowApi? MainWindow { get; internal set; } - public ISettings? Settings { get; internal set; } - } + public static AppApi Instance { get; } = new(); + public IMainWindowApi? MainWindow { get; internal set; } + public ISettings Settings { get; internal set; } = null!; } diff --git a/OwnChar.App.Desktop/FeatureCodes.cs b/OwnChar.App.Desktop/FeatureCodes.cs index 2dea80d..3193422 100644 --- a/OwnChar.App.Desktop/FeatureCodes.cs +++ b/OwnChar.App.Desktop/FeatureCodes.cs @@ -4,5 +4,6 @@ { public const string MainTab = "ownchar.app.desktop.main.tab"; public const string QuickAction = "ownchar.app.desktop.main.quickaction"; + public const string LoginProvider = "ownchar.app.desktop.main.login.provider"; } } diff --git a/OwnChar.App.Desktop/Features/LoginProviders/JsonFileLoginProvider.cs b/OwnChar.App.Desktop/Features/LoginProviders/JsonFileLoginProvider.cs new file mode 100644 index 0000000..1a10fd7 --- /dev/null +++ b/OwnChar.App.Desktop/Features/LoginProviders/JsonFileLoginProvider.cs @@ -0,0 +1,43 @@ +using OwnChar.App.Desktop.Api; +using OwnChar.App.Desktop.Settings; +using OwnChar.Data; +using OwnChar.Data.Managers; +using OwnChar.Data.Providers.JsonFile; +using Pilz.Plugins.Advanced; +using Telerik.WinControls.UI; + +namespace OwnChar.App.Desktop.Features.LoginProviders; + +internal class JsonFileLoginProvider() : LoginProvider(FeatureCodes.LoginProvider, "ownchar.jsonfile"), IPluginFeatureProvider +{ + private const string defaultJsonFileName = "ownchar.db.json"; + + public static JsonFileLoginProvider Instance { get; } = new(); + + public override IDataManager GetDefault(IMainWindowApi api) + { + var settings = AppApi.Instance.Settings.Get(); + return new DefaultDataManager(new JsonFileDataProvider(settings?.RecentFilePath ?? defaultJsonFileName)); + } + + public override void Configure(IMainWindowApi api, ref IDataManager? manager) + { + var settings = AppApi.Instance.Settings.Get(); + using var ofd = new RadOpenFileDialog + { + Filter = "OwnChar Json database (*.json)|*.json" + }; + + if (manager is DefaultDataManager defaultManager && defaultManager.DataProvider is JsonFileDataProvider jsonFileDataProvider) + ofd.FileName = jsonFileDataProvider.JsonFilePath; + else + ofd.FileName = settings.RecentFilePath; + + if (ofd.ShowDialog(api.Window) != System.Windows.Forms.DialogResult.OK) + return; + + settings.RecentFilePath = ofd.FileName; + + manager = new DefaultDataManager(new JsonFileDataProvider(ofd.FileName ?? defaultJsonFileName)); + } +} diff --git a/OwnChar.App.Desktop/LangRes/LangResCharListControl.Designer.cs b/OwnChar.App.Desktop/LangRes/CharListControlLangRes.Designer.cs similarity index 95% rename from OwnChar.App.Desktop/LangRes/LangResCharListControl.Designer.cs rename to OwnChar.App.Desktop/LangRes/CharListControlLangRes.Designer.cs index 56f3e61..673bbbb 100644 --- a/OwnChar.App.Desktop/LangRes/LangResCharListControl.Designer.cs +++ b/OwnChar.App.Desktop/LangRes/CharListControlLangRes.Designer.cs @@ -22,14 +22,14 @@ namespace OwnChar.App.Desktop.LangRes { [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")] [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] - internal class LangResCharListControl { + internal class CharListControlLangRes { private static global::System.Resources.ResourceManager resourceMan; private static global::System.Globalization.CultureInfo resourceCulture; [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] - internal LangResCharListControl() { + internal CharListControlLangRes() { } /// @@ -39,7 +39,7 @@ namespace OwnChar.App.Desktop.LangRes { internal static global::System.Resources.ResourceManager ResourceManager { get { if (object.ReferenceEquals(resourceMan, null)) { - global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("OwnChar.App.Desktop.LangRes.LangResCharListControl", typeof(LangResCharListControl).Assembly); + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("OwnChar.App.Desktop.LangRes.CharListControlLangRes", typeof(CharListControlLangRes).Assembly); resourceMan = temp; } return resourceMan; diff --git a/OwnChar.App.Desktop/LangRes/LangResCharListControl.resx b/OwnChar.App.Desktop/LangRes/CharListControlLangRes.resx similarity index 100% rename from OwnChar.App.Desktop/LangRes/LangResCharListControl.resx rename to OwnChar.App.Desktop/LangRes/CharListControlLangRes.resx diff --git a/OwnChar.App.Desktop/LangRes/HomePageLangRes.Designer.cs b/OwnChar.App.Desktop/LangRes/LoginPageLangRes.Designer.cs similarity index 76% rename from OwnChar.App.Desktop/LangRes/HomePageLangRes.Designer.cs rename to OwnChar.App.Desktop/LangRes/LoginPageLangRes.Designer.cs index 771695d..1ba1f8c 100644 --- a/OwnChar.App.Desktop/LangRes/HomePageLangRes.Designer.cs +++ b/OwnChar.App.Desktop/LangRes/LoginPageLangRes.Designer.cs @@ -22,14 +22,14 @@ namespace OwnChar.App.Desktop.LangRes { [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")] [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] - internal class HomePageLangRes { + internal class LoginPageLangRes { private static global::System.Resources.ResourceManager resourceMan; private static global::System.Globalization.CultureInfo resourceCulture; [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] - internal HomePageLangRes() { + internal LoginPageLangRes() { } /// @@ -39,7 +39,7 @@ namespace OwnChar.App.Desktop.LangRes { internal static global::System.Resources.ResourceManager ResourceManager { get { if (object.ReferenceEquals(resourceMan, null)) { - global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("OwnChar.App.Desktop.LangRes.HomePageLangRes", typeof(HomePageLangRes).Assembly); + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("OwnChar.App.Desktop.LangRes.LoginPageLangRes", typeof(LoginPageLangRes).Assembly); resourceMan = temp; } return resourceMan; @@ -61,7 +61,25 @@ namespace OwnChar.App.Desktop.LangRes { } /// - /// Sucht eine lokalisierte Zeichenfolge, die Home ähnelt. + /// Sucht eine lokalisierte Zeichenfolge, die Login failed. Please ensure username and password are correct and choose and configure a provider. If nothing helps try restart the app. ähnelt. + /// + internal static string MsgBox_LoginFailed { + get { + return ResourceManager.GetString("MsgBox_LoginFailed", resourceCulture); + } + } + + /// + /// Sucht eine lokalisierte Zeichenfolge, die Login failed ähnelt. + /// + internal static string MsgBox_LoginFailed_Title { + get { + return ResourceManager.GetString("MsgBox_LoginFailed_Title", resourceCulture); + } + } + + /// + /// Sucht eine lokalisierte Zeichenfolge, die Login ähnelt. /// internal static string Title { get { diff --git a/OwnChar.App.Desktop/LangRes/HomePageLangRes.resx b/OwnChar.App.Desktop/LangRes/LoginPageLangRes.resx similarity index 94% rename from OwnChar.App.Desktop/LangRes/HomePageLangRes.resx rename to OwnChar.App.Desktop/LangRes/LoginPageLangRes.resx index 9a35477..fdf3d51 100644 --- a/OwnChar.App.Desktop/LangRes/HomePageLangRes.resx +++ b/OwnChar.App.Desktop/LangRes/LoginPageLangRes.resx @@ -117,7 +117,13 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + Login failed. Please ensure username and password are correct and choose and configure a provider. If nothing helps try restart the app. + + + Login failed + - Home + Login \ No newline at end of file diff --git a/OwnChar.App.Desktop/OwnChar.App.Desktop.csproj b/OwnChar.App.Desktop/OwnChar.App.Desktop.csproj index 67fb99b..a51a813 100644 --- a/OwnChar.App.Desktop/OwnChar.App.Desktop.csproj +++ b/OwnChar.App.Desktop/OwnChar.App.Desktop.csproj @@ -31,10 +31,10 @@ - + True True - HomePageLangRes.resx + LoginPageLangRes.resx True @@ -44,9 +44,9 @@ - + ResXFileCodeGenerator - HomePageLangRes.Designer.cs + LoginPageLangRes.Designer.cs ResXFileCodeGenerator @@ -55,17 +55,17 @@ - + True True - LangResCharListControl.resx + CharListControlLangRes.resx - + ResXFileCodeGenerator - LangResCharListControl.Designer.cs + CharListControlLangRes.Designer.cs diff --git a/OwnChar.App.Desktop/Settings/JsonFileLoginProviderSettings.cs b/OwnChar.App.Desktop/Settings/JsonFileLoginProviderSettings.cs new file mode 100644 index 0000000..9f5db61 --- /dev/null +++ b/OwnChar.App.Desktop/Settings/JsonFileLoginProviderSettings.cs @@ -0,0 +1,15 @@ +using Pilz.Configuration; + +namespace OwnChar.App.Desktop.Settings; + +internal class JsonFileLoginProviderSettings : IChildSettings, ISettingsIdentifier +{ + public static string Identifier => "ownchar.login.providers.jsonfile"; + + public string? RecentFilePath { get; set; } + + public void Reset() + { + RecentFilePath = null; + } +} diff --git a/OwnChar.App.Desktop/UI/MainTabs/TabLoginView.Designer.cs b/OwnChar.App.Desktop/UI/MainTabs/TabLoginView.Designer.cs index 93c908b..0e5ef45 100644 --- a/OwnChar.App.Desktop/UI/MainTabs/TabLoginView.Designer.cs +++ b/OwnChar.App.Desktop/UI/MainTabs/TabLoginView.Designer.cs @@ -29,18 +29,26 @@ private void InitializeComponent() { tableLayoutPanel1 = new System.Windows.Forms.TableLayoutPanel(); - radButton1 = new Telerik.WinControls.UI.RadButton(); - radLabel1 = new Telerik.WinControls.UI.RadLabel(); - radTextBoxControl1 = new Telerik.WinControls.UI.RadTextBoxControl(); - radTextBoxControl2 = new Telerik.WinControls.UI.RadTextBoxControl(); + radTextBoxControl_Password = new Telerik.WinControls.UI.RadTextBoxControl(); radLabel2 = new Telerik.WinControls.UI.RadLabel(); + radTextBoxControl_Username = new Telerik.WinControls.UI.RadTextBoxControl(); + radButton_Login = new Telerik.WinControls.UI.RadButton(); + radLabel1 = new Telerik.WinControls.UI.RadLabel(); + radLabel3 = new Telerik.WinControls.UI.RadLabel(); + tableLayoutPanel3 = new System.Windows.Forms.TableLayoutPanel(); + radDropDownList_LoginProvider = new Telerik.WinControls.UI.RadDropDownList(); + radButton_ConfigureProvider = new Telerik.WinControls.UI.RadButton(); tableLayoutPanel2 = new System.Windows.Forms.TableLayoutPanel(); tableLayoutPanel1.SuspendLayout(); - ((System.ComponentModel.ISupportInitialize)radButton1).BeginInit(); - ((System.ComponentModel.ISupportInitialize)radLabel1).BeginInit(); - ((System.ComponentModel.ISupportInitialize)radTextBoxControl1).BeginInit(); - ((System.ComponentModel.ISupportInitialize)radTextBoxControl2).BeginInit(); + ((System.ComponentModel.ISupportInitialize)radTextBoxControl_Password).BeginInit(); ((System.ComponentModel.ISupportInitialize)radLabel2).BeginInit(); + ((System.ComponentModel.ISupportInitialize)radTextBoxControl_Username).BeginInit(); + ((System.ComponentModel.ISupportInitialize)radButton_Login).BeginInit(); + ((System.ComponentModel.ISupportInitialize)radLabel1).BeginInit(); + ((System.ComponentModel.ISupportInitialize)radLabel3).BeginInit(); + tableLayoutPanel3.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)radDropDownList_LoginProvider).BeginInit(); + ((System.ComponentModel.ISupportInitialize)radButton_ConfigureProvider).BeginInit(); tableLayoutPanel2.SuspendLayout(); SuspendLayout(); // @@ -51,64 +59,116 @@ tableLayoutPanel1.ColumnCount = 2; tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 40F)); tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 60F)); - tableLayoutPanel1.Controls.Add(radTextBoxControl2, 1, 1); - tableLayoutPanel1.Controls.Add(radLabel2, 0, 1); - tableLayoutPanel1.Controls.Add(radTextBoxControl1, 1, 0); - tableLayoutPanel1.Controls.Add(radButton1, 1, 2); - tableLayoutPanel1.Controls.Add(radLabel1, 0, 0); - tableLayoutPanel1.Location = new System.Drawing.Point(129, 81); + tableLayoutPanel1.Controls.Add(radTextBoxControl_Password, 1, 2); + tableLayoutPanel1.Controls.Add(radLabel2, 0, 2); + tableLayoutPanel1.Controls.Add(radTextBoxControl_Username, 1, 1); + tableLayoutPanel1.Controls.Add(radButton_Login, 1, 3); + tableLayoutPanel1.Controls.Add(radLabel1, 0, 1); + tableLayoutPanel1.Controls.Add(radLabel3, 0, 0); + tableLayoutPanel1.Controls.Add(tableLayoutPanel3, 1, 0); + tableLayoutPanel1.Location = new System.Drawing.Point(129, 74); tableLayoutPanel1.Margin = new System.Windows.Forms.Padding(0); tableLayoutPanel1.Name = "tableLayoutPanel1"; - tableLayoutPanel1.RowCount = 3; + tableLayoutPanel1.RowCount = 4; tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle()); tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle()); tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle()); - tableLayoutPanel1.Size = new System.Drawing.Size(259, 86); + tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle()); + tableLayoutPanel1.Size = new System.Drawing.Size(259, 114); tableLayoutPanel1.TabIndex = 0; // - // radButton1 + // radTextBoxControl_Password // - radButton1.Location = new System.Drawing.Point(106, 59); - radButton1.Name = "radButton1"; - radButton1.Size = new System.Drawing.Size(110, 24); - radButton1.TabIndex = 1; - radButton1.Text = "radButton1"; - // - // radLabel1 - // - radLabel1.Anchor = System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right; - radLabel1.AutoSize = false; - radLabel1.Location = new System.Drawing.Point(3, 3); - radLabel1.Name = "radLabel1"; - radLabel1.Size = new System.Drawing.Size(97, 22); - radLabel1.TabIndex = 1; - radLabel1.Text = "radLabel1"; - // - // radTextBoxControl1 - // - radTextBoxControl1.Anchor = System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right; - radTextBoxControl1.Location = new System.Drawing.Point(106, 3); - radTextBoxControl1.Name = "radTextBoxControl1"; - radTextBoxControl1.Size = new System.Drawing.Size(150, 22); - radTextBoxControl1.TabIndex = 2; - // - // radTextBoxControl2 - // - radTextBoxControl2.Anchor = System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right; - radTextBoxControl2.Location = new System.Drawing.Point(106, 31); - radTextBoxControl2.Name = "radTextBoxControl2"; - radTextBoxControl2.Size = new System.Drawing.Size(150, 22); - radTextBoxControl2.TabIndex = 1; + radTextBoxControl_Password.Anchor = System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right; + radTextBoxControl_Password.Location = new System.Drawing.Point(106, 59); + radTextBoxControl_Password.Name = "radTextBoxControl_Password"; + radTextBoxControl_Password.Size = new System.Drawing.Size(150, 22); + radTextBoxControl_Password.TabIndex = 1; // // radLabel2 // radLabel2.Anchor = System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right; radLabel2.AutoSize = false; - radLabel2.Location = new System.Drawing.Point(3, 31); + radLabel2.Location = new System.Drawing.Point(3, 59); radLabel2.Name = "radLabel2"; radLabel2.Size = new System.Drawing.Size(97, 22); radLabel2.TabIndex = 0; - radLabel2.Text = "radLabel2"; + radLabel2.Text = "Password"; + // + // radTextBoxControl_Username + // + radTextBoxControl_Username.Anchor = System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right; + radTextBoxControl_Username.Location = new System.Drawing.Point(106, 31); + radTextBoxControl_Username.Name = "radTextBoxControl_Username"; + radTextBoxControl_Username.Size = new System.Drawing.Size(150, 22); + radTextBoxControl_Username.TabIndex = 2; + // + // radButton_Login + // + radButton_Login.Location = new System.Drawing.Point(106, 87); + radButton_Login.Name = "radButton_Login"; + radButton_Login.Size = new System.Drawing.Size(110, 24); + radButton_Login.TabIndex = 1; + radButton_Login.Text = "Login"; + radButton_Login.Click += RadButton_Login_Click; + // + // radLabel1 + // + radLabel1.Anchor = System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right; + radLabel1.AutoSize = false; + radLabel1.Location = new System.Drawing.Point(3, 31); + radLabel1.Name = "radLabel1"; + radLabel1.Size = new System.Drawing.Size(97, 22); + radLabel1.TabIndex = 1; + radLabel1.Text = "Username"; + // + // radLabel3 + // + radLabel3.Anchor = System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right; + radLabel3.AutoSize = false; + radLabel3.Location = new System.Drawing.Point(3, 3); + radLabel3.Name = "radLabel3"; + radLabel3.Size = new System.Drawing.Size(97, 22); + radLabel3.TabIndex = 3; + radLabel3.Text = "Provider"; + // + // tableLayoutPanel3 + // + tableLayoutPanel3.AutoSize = true; + tableLayoutPanel3.ColumnCount = 2; + tableLayoutPanel3.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 100F)); + tableLayoutPanel3.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle()); + tableLayoutPanel3.Controls.Add(radDropDownList_LoginProvider, 0, 0); + tableLayoutPanel3.Controls.Add(radButton_ConfigureProvider, 1, 0); + tableLayoutPanel3.Dock = System.Windows.Forms.DockStyle.Fill; + tableLayoutPanel3.Location = new System.Drawing.Point(103, 0); + tableLayoutPanel3.Margin = new System.Windows.Forms.Padding(0); + tableLayoutPanel3.Name = "tableLayoutPanel3"; + tableLayoutPanel3.RowCount = 1; + tableLayoutPanel3.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 100F)); + tableLayoutPanel3.Size = new System.Drawing.Size(156, 28); + tableLayoutPanel3.TabIndex = 4; + // + // radDropDownList_LoginProvider + // + radDropDownList_LoginProvider.Anchor = System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right; + radDropDownList_LoginProvider.DropDownStyle = Telerik.WinControls.RadDropDownStyle.DropDownList; + radDropDownList_LoginProvider.Location = new System.Drawing.Point(3, 3); + radDropDownList_LoginProvider.Name = "radDropDownList_LoginProvider"; + radDropDownList_LoginProvider.Size = new System.Drawing.Size(122, 22); + radDropDownList_LoginProvider.TabIndex = 0; + radDropDownList_LoginProvider.SelectedValueChanged += RadDropDownList_LoginProvider_SelectedValueChanged; + // + // radButton_ConfigureProvider + // + radButton_ConfigureProvider.DisplayStyle = Telerik.WinControls.DisplayStyle.Image; + radButton_ConfigureProvider.ImageAlignment = System.Drawing.ContentAlignment.MiddleCenter; + radButton_ConfigureProvider.Location = new System.Drawing.Point(131, 3); + radButton_ConfigureProvider.Name = "radButton_ConfigureProvider"; + radButton_ConfigureProvider.Size = new System.Drawing.Size(22, 22); + radButton_ConfigureProvider.TabIndex = 1; + radButton_ConfigureProvider.Text = "Configure"; + radButton_ConfigureProvider.Click += RadButton_ConfigureProvider_Click; // // tableLayoutPanel2 // @@ -135,11 +195,17 @@ Name = "TabLoginView"; Size = new System.Drawing.Size(519, 412); tableLayoutPanel1.ResumeLayout(false); - ((System.ComponentModel.ISupportInitialize)radButton1).EndInit(); - ((System.ComponentModel.ISupportInitialize)radLabel1).EndInit(); - ((System.ComponentModel.ISupportInitialize)radTextBoxControl1).EndInit(); - ((System.ComponentModel.ISupportInitialize)radTextBoxControl2).EndInit(); + tableLayoutPanel1.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)radTextBoxControl_Password).EndInit(); ((System.ComponentModel.ISupportInitialize)radLabel2).EndInit(); + ((System.ComponentModel.ISupportInitialize)radTextBoxControl_Username).EndInit(); + ((System.ComponentModel.ISupportInitialize)radButton_Login).EndInit(); + ((System.ComponentModel.ISupportInitialize)radLabel1).EndInit(); + ((System.ComponentModel.ISupportInitialize)radLabel3).EndInit(); + tableLayoutPanel3.ResumeLayout(false); + tableLayoutPanel3.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)radDropDownList_LoginProvider).EndInit(); + ((System.ComponentModel.ISupportInitialize)radButton_ConfigureProvider).EndInit(); tableLayoutPanel2.ResumeLayout(false); tableLayoutPanel2.PerformLayout(); ResumeLayout(false); @@ -148,11 +214,15 @@ #endregion private System.Windows.Forms.TableLayoutPanel tableLayoutPanel1; - private Telerik.WinControls.UI.RadTextBoxControl radTextBoxControl2; + private Telerik.WinControls.UI.RadTextBoxControl radTextBoxControl_Password; private Telerik.WinControls.UI.RadLabel radLabel2; - private Telerik.WinControls.UI.RadTextBoxControl radTextBoxControl1; - private Telerik.WinControls.UI.RadButton radButton1; + private Telerik.WinControls.UI.RadTextBoxControl radTextBoxControl_Username; + private Telerik.WinControls.UI.RadButton radButton_Login; private Telerik.WinControls.UI.RadLabel radLabel1; private System.Windows.Forms.TableLayoutPanel tableLayoutPanel2; + private Telerik.WinControls.UI.RadLabel radLabel3; + private System.Windows.Forms.TableLayoutPanel tableLayoutPanel3; + private Telerik.WinControls.UI.RadDropDownList radDropDownList_LoginProvider; + private Telerik.WinControls.UI.RadButton radButton_ConfigureProvider; } } diff --git a/OwnChar.App.Desktop/UI/MainTabs/TabLoginView.cs b/OwnChar.App.Desktop/UI/MainTabs/TabLoginView.cs index 8c38be0..81fdda9 100644 --- a/OwnChar.App.Desktop/UI/MainTabs/TabLoginView.cs +++ b/OwnChar.App.Desktop/UI/MainTabs/TabLoginView.cs @@ -1,20 +1,80 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Data; +using OwnChar.App.Desktop.Api; +using OwnChar.App.Desktop.LangRes; +using OwnChar.Data; +using Pilz.Cryptography; +using Pilz.Plugins.Advanced; +using Pilz.UI.Telerik.Dialogs; +using System; using System.Drawing; -using System.Linq; -using System.Text; -using System.Threading.Tasks; using System.Windows.Forms; +using Telerik.WinControls; +using Telerik.WinControls.UI; -namespace OwnChar.App.Desktop.UI.MainTabs +namespace OwnChar.App.Desktop.UI.MainTabs; + +public partial class TabLoginView : UserControl, ILoadContent { - public partial class TabLoginView : UserControl + private readonly IMainWindowApi mainApi; + private IDataManager? dataManager; + + public TabLoginView(IMainWindowApi mainApi) { - public TabLoginView() + this.mainApi = mainApi; + InitializeComponent(); + } + + public void LoadContent() + { + LoadProvidersList(); + } + + private void LoadProvidersList() + { + radDropDownList_LoginProvider.BeginUpdate(); + + foreach (var feat in PluginFeatureController.Instance.Features.Get(FeatureCodes.LoginProvider)) { - InitializeComponent(); + if (feat is LoginProvider provider) + { + var item = new RadListDataItem(feat.Name, provider) + { + SvgImage = feat.Icon as RadSvgImage, + Image = feat.Icon as Image, + }; + radDropDownList_LoginProvider.Items.Add(item); + } } + + radDropDownList_LoginProvider.EndUpdate(); + + if (radDropDownList_LoginProvider.Items.Count > 0) + radDropDownList_LoginProvider.SelectedIndex = 0; + } + + private void RadDropDownList_LoginProvider_SelectedValueChanged(object sender, EventArgs e) + { + if (radDropDownList_LoginProvider.SelectedValue is LoginProvider provider) + dataManager = provider.GetDefault(mainApi); + } + + private void RadButton_Login_Click(object sender, EventArgs e) + { + var username = radTextBoxControl_Username.Text.Trim(); + var password = (SecureString)radTextBoxControl_Password.Text; + + if (mainApi.Manager?.Login(dataManager, username, password) is not bool success || !success) + { + RadMessageBox.Show(LoginPageLangRes.MsgBox_LoginFailed, LoginPageLangRes.MsgBox_LoginFailed_Title, MessageBoxButtons.YesNo, RadMessageIcon.Exclamation); + return; + } + + mainApi.OpenTab(new TabUserView(mainApi, mainApi.Manager.CurrentUser), mainApi.Manager.CurrentUser!.Username!); + mainApi.CloseTab(this); + } + + private void RadButton_ConfigureProvider_Click(object sender, EventArgs e) + { + if (radDropDownList_LoginProvider.SelectedValue is LoginProvider provider) + provider.Configure(mainApi, ref dataManager); } } diff --git a/OwnChar.App.Desktop/UI/Windows/MainWindow.Designer.cs b/OwnChar.App.Desktop/UI/Windows/MainWindow.Designer.cs index f34107d..51d44ef 100644 --- a/OwnChar.App.Desktop/UI/Windows/MainWindow.Designer.cs +++ b/OwnChar.App.Desktop/UI/Windows/MainWindow.Designer.cs @@ -78,6 +78,7 @@ namespace OwnChar.App.Desktop.UI.Windows Name = "MainWindow"; ShowIcon = false; Text = "RadForm1"; + Load += MainWindow_Load; ((System.ComponentModel.ISupportInitialize)radTabbedFormControl1).EndInit(); ((System.ComponentModel.ISupportInitialize)radTabbedFormControl2).EndInit(); radTabbedFormControl2.ResumeLayout(false); diff --git a/OwnChar.App.Desktop/UI/Windows/MainWindow.cs b/OwnChar.App.Desktop/UI/Windows/MainWindow.cs index 46ffe9c..a48cf1c 100644 --- a/OwnChar.App.Desktop/UI/Windows/MainWindow.cs +++ b/OwnChar.App.Desktop/UI/Windows/MainWindow.cs @@ -1,5 +1,7 @@ using OwnChar.App.Desktop.Api; using OwnChar.App.Desktop.Api.Parameters; +using OwnChar.App.Desktop.LangRes; +using OwnChar.App.Desktop.UI.MainTabs; using OwnChar.Data; using OwnChar.Data.Managers; using OwnChar.Data.Providers.JsonFile; @@ -92,5 +94,10 @@ namespace OwnChar.App.Desktop.UI.Windows if (sender is RadMenuItem item && item.Tag is PluginFunction function) function.Execute(GetMainWindowParams()); } + + private void MainWindow_Load(object sender, EventArgs e) + { + Api.OpenTab(new TabLoginView(Api), LoginPageLangRes.Title); + } } }