diff --git a/VisualPlugins/TraningControlPlugin/LoginForm.cs b/VisualPlugins/TraningControlPlugin/LoginForm.cs index 9867dfd63..667008186 100644 --- a/VisualPlugins/TraningControlPlugin/LoginForm.cs +++ b/VisualPlugins/TraningControlPlugin/LoginForm.cs @@ -29,11 +29,18 @@ namespace DBAccessPluginNamespace var res = true; try { - using (var sw = new System.IO.StreamWriter(filename)) + var encryptedstring = login + (char)10 + pass; + var encr = LoginUtils.Encrypt(encryptedstring); + using (var fs = new FileStream(filename, FileMode.Create)) + { + fs.Write(encr, 0, encr.Length); + } + // записать массив байт в бинарный файл + /*using (var sw = new System.IO.StreamWriter(filename)) { sw.WriteLine(login); sw.WriteLine(pass); - } + }*/ } catch (Exception) { diff --git a/VisualPlugins/TraningControlPlugin/LoginUtils.cs b/VisualPlugins/TraningControlPlugin/LoginUtils.cs index 3a7eebb7f..cb957b6af 100644 --- a/VisualPlugins/TraningControlPlugin/LoginUtils.cs +++ b/VisualPlugins/TraningControlPlugin/LoginUtils.cs @@ -16,7 +16,7 @@ namespace VisualPascalABCPlugins var mbsList = mbs.Get(); foreach (ManagementObject mo in mbsList) { - return mo['ProcessorId'].ToString(); + return mo["ProcessorId"].ToString(); } return ""; } diff --git a/VisualPlugins/TraningControlPlugin/SiteAccessInfo.cs b/VisualPlugins/TraningControlPlugin/SiteAccessInfo.cs index 047ada4c9..5a2da6592 100644 --- a/VisualPlugins/TraningControlPlugin/SiteAccessInfo.cs +++ b/VisualPlugins/TraningControlPlugin/SiteAccessInfo.cs @@ -43,8 +43,11 @@ namespace DBAccessPluginNamespace if (UserType != UserTypeEnum.Student) return "Cannot write activity, because you're teacher!"; // Если клиент ещё не создан был, пересоздаём - if (client == null) client = new HttpClient(); - client.Timeout = TimeSpan.FromSeconds(10); + if (client == null) + { + client = new HttpClient(); + client.Timeout = TimeSpan.FromSeconds(10); + } // Словарик для параметров запроса var values = new Dictionary { @@ -79,8 +82,11 @@ namespace DBAccessPluginNamespace async public Task GetContents() { // Если клиент ещё не создан был, пересоздаём - if (client == null) client = new HttpClient(); - client.Timeout = TimeSpan.FromSeconds(10); + if (client == null) + { + client = new HttpClient(); + client.Timeout = TimeSpan.FromSeconds(10); + } // Тут не столь важно что отправлять, можно и пустой список параметров var values = new Dictionary { @@ -103,8 +109,11 @@ namespace DBAccessPluginNamespace if (ServAddr == "") return "Error"; // Если клиент ещё не создан был, пересоздаём - if (client == null) client = new HttpClient(); - client.Timeout = TimeSpan.FromSeconds(10); + if (client == null) + { + client = new HttpClient(); + client.Timeout = TimeSpan.FromSeconds(10); + } var values = new Dictionary(); var content = new FormUrlEncodedContent(values); var response = await client.PostAsync(ServAddr + "/groupslist.php", content); @@ -122,8 +131,11 @@ namespace DBAccessPluginNamespace ServAddr = ServerAddr; if (ServAddr == "") return "Error"; // Если клиент ещё не создан был, пересоздаём - if (client == null) client = new HttpClient(); - client.Timeout = TimeSpan.FromSeconds(10); + if (client == null) + { + client = new HttpClient(); + client.Timeout = TimeSpan.FromSeconds(10); + } Group = GroupName; var values = new Dictionary { @@ -148,8 +160,11 @@ namespace DBAccessPluginNamespace ShortFIO = shortFIO; FullFIO = fullFIO; Password = password; - if (client == null) client = new HttpClient(); - client.Timeout = TimeSpan.FromSeconds(10); + if (client == null) + { + client = new HttpClient(); + client.Timeout = TimeSpan.FromSeconds(10); + } // Словарик для параметров запроса var values = new Dictionary diff --git a/VisualPlugins/TraningControlPlugin/TeacherControlPlugin.cs b/VisualPlugins/TraningControlPlugin/TeacherControlPlugin.cs index 8351072f7..775730285 100644 --- a/VisualPlugins/TraningControlPlugin/TeacherControlPlugin.cs +++ b/VisualPlugins/TraningControlPlugin/TeacherControlPlugin.cs @@ -2,6 +2,7 @@ using System; using System.Collections.Generic; using System.Windows.Forms; using System.Text; +using System.IO; using System.Linq; using PascalABCCompiler.SyntaxTreeConverters; using PascalABCCompiler.SyntaxTree; @@ -165,6 +166,22 @@ namespace VisualPascalABCPlugins } } + string[] ReadLoginPassFromAuth(string AuthFileFullName) + { + var n = 10000; + var arr = new byte[n]; + int nbytes; + using (var fs = new FileStream(AuthFileFullName, FileMode.Open)) + { + nbytes = fs.Read(arr, 0, n); + } + var data = new byte[nbytes]; + System.Array.Copy(arr, data, nbytes); + var lp = LoginUtils.Decrypt(data); + var lparr = lp.Split((char)10); + return lparr; + } + public void AfterAddInGUI() { menuItem = (ToolStripMenuItem)Item.menuItem; @@ -191,12 +208,18 @@ namespace VisualPascalABCPlugins // искать auth в папке на уровень выше auth = System.IO.Path.Combine(WorkingDir, "..", "auth.dat"); if (System.IO.File.Exists(auth)) - AuthFileFullName = auth; + { + var fi = new System.IO.FileInfo(auth); + AuthFileFullName = fi.FullName; + } + } } + // Попытка автоматического входа if (AuthFileFullName != "") { - var ss = System.IO.File.ReadAllLines(AuthFileFullName); + //var ss = System.IO.File.ReadAllLines(AuthFileFullName); + var ss = ReadLoginPassFromAuth(AuthFileFullName); if (ss.Length >= 2) { var login = ss[0]; @@ -205,8 +228,10 @@ namespace VisualPascalABCPlugins } } } - catch (Exception) - { } + catch (Exception e) + { + e = e; + } } private void RunStartingHandler(string filename) diff --git a/VisualPlugins/TraningControlPlugin/TeacherControlPlugin.csproj b/VisualPlugins/TraningControlPlugin/TeacherControlPlugin.csproj index 261967dcb..6b69c15c4 100644 --- a/VisualPlugins/TraningControlPlugin/TeacherControlPlugin.csproj +++ b/VisualPlugins/TraningControlPlugin/TeacherControlPlugin.csproj @@ -59,7 +59,9 @@ + + @@ -70,6 +72,7 @@ LoginForm.cs + True True