This repository has been archived by the owner on Mar 6, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SettingsWindow.cs
163 lines (145 loc) · 7.79 KB
/
SettingsWindow.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
using Microsoft.Win32;
using Newtonsoft.Json;
using NHotkey.WindowsForms;
using System;
using System.Diagnostics;
using System.Linq;
using System.Net;
using System.Text;
using System.Text.RegularExpressions;
using System.Windows.Forms;
namespace lxMeets {
public partial class SettingsWindow : Form {
readonly WebClient client = new WebClient();
public SettingsWindow() {
InitializeComponent();
CenterToScreen();
keyboardShortCutText.Text = Properties.Settings.Default.KeyBoardShortCut.Replace("Keys.", "");
cedDefault.Text = Properties.Settings.Default.Cedula;
autoRunCheck.Checked = Properties.Settings.Default.AutoStart;
useKeyboardCheck.Checked = Properties.Settings.Default.UseKeyboard;
sendNotificationsCheck.Checked = Properties.Settings.Default.Notifications;
useCedulaCheck.Checked = Properties.Settings.Default.UseDefaultCed;
usuarioDefault.Text = Decode(Properties.Settings.Default.Usuario);
useUsuarioCheck.Checked = Properties.Settings.Default.UseDefaultUser;
this.KeyPreview = true;
}
private void saveButton_Click(object sender, EventArgs e) {
Close();
}
private void UseKeyboardCheck_CheckedChanged(object sender, EventArgs e) {
try {
var mainForm = Application.OpenForms.OfType<lxMeets>().Single();
if (useKeyboardCheck.Checked) {
HotkeyManager.Current.AddOrReplace("AbrirClase", Keys.Control | Keys.Alt | Keys.Shift, mainForm.FromKeyboard);
Properties.Settings.Default.UseKeyboard = true;
Properties.Settings.Default.Save();
} else {
HotkeyManager.Current.Remove("AbrirClase");
Properties.Settings.Default.UseKeyboard = false;
Properties.Settings.Default.Save();
}
} catch { }
}
private void AutoRunCheck_CheckedChanged(object sender, EventArgs e) {
RegistryKey registryKey = Registry.CurrentUser.OpenSubKey
("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true);
if (autoRunCheck.Checked) {
registryKey.SetValue("lxMeets", $"{Process.GetCurrentProcess().MainModule.FileName} --start-minimized");
Properties.Settings.Default.AutoStart = true;
Properties.Settings.Default.Save();
} else {
registryKey.DeleteValue("lxMeets");
Properties.Settings.Default.AutoStart = false;
Properties.Settings.Default.Save();
}
}
private void SendNotificationsCheck_CheckedChanged(object sender, EventArgs e) {
Properties.Settings.Default.Notifications = sendNotificationsCheck.Checked;
Properties.Settings.Default.Save();
}
private void useCedulaCheck_CheckedChanged(object sender, EventArgs e) {
Properties.Settings.Default.UseDefaultCed = useCedulaCheck.Checked;
Properties.Settings.Default.Save();
}
private async void AuthUser(string cedula) {
try {
string url = @"https://api.lxndr.dev/uae/estudiantes/?cedula=" + cedula;
var json = await client.DownloadStringTaskAsync(url);
dynamic stuff = JsonConvert.DeserializeObject(json);
if ((bool)stuff.error) {
MessageBox.Show(stuff.message.ToString());
while (true) {
cedula = lxMessageInputBox.ShowDialog("Ingresar número de cédula", "Ingresar número de cédula");
while ((cedula.Length < 9 && cedula.Length > 0) || !Regex.IsMatch(cedula, @"^\d+$")) {
if (cedula == "Cancel") break;
MessageBox.Show("Cédula Inválida"); cedula = lxMessageInputBox.ShowDialog("Ingresar número de cédula", "Ingresar número de cédula");
}
if (cedula != "Cancel") AuthUser(cedula);
break;
}
} else {
Properties.Settings.Default.Cedula = cedula;
Properties.Settings.Default.Save();
cedDefault.Text = Properties.Settings.Default.Cedula;
}
} catch { }
}
private void cambiarCedula_Click(object sender, EventArgs e) {
string cedula = lxMessageInputBox.ShowDialog("Ingresar número de cédula", "Ingresar número de cédula");
while ((cedula.Length < 9 && cedula.Length > 0) || !Regex.IsMatch(cedula, @"^\d+$")) {
if (cedula == "Cancel") break;
MessageBox.Show("Cédula Inválida"); cedula = lxMessageInputBox.ShowDialog("Ingresar número de cédula", "Ingresar número de cédula");
}
if (cedula != "Cancel") AuthUser(cedula);
}
private void useUsuarioCheck_CheckedChanged(object sender, EventArgs e) {
Properties.Settings.Default.UseDefaultUser = useUsuarioCheck.Checked;
Properties.Settings.Default.Save();
}
private async void AuthMoodle(string contra, string user) {
try {
string url = @"https://api.lxndr.dev/uae/moodle?usuario=" + Encode(user) + "&contrasena=" + Encode(contra);
var json = await client.DownloadStringTaskAsync(url);
dynamic stuff = JsonConvert.DeserializeObject(json);
if ((bool)stuff.error) {
MessageBox.Show(stuff.message.ToString());
string res = lxMessageInputBox.ShowDialog("Ingresa tus credenciales", "Ingresar Usuario", false, true, "Ingresa Contraseña");
string usuario = res.Split('[', ']')[1];
string contrasena = res.Split('(', ')')[1];
while ((res.Length < 9 && res.Length > 0)) {
if (contrasena == "Cancel") break;
res = lxMessageInputBox.ShowDialog("Ingresa tus credenciales", "Ingresar Usuario", false, true, "Ingresa Contraseña");
usuario = res.Split('[', ']')[1];
contrasena = res.Split('(', ')')[1];
}
if (contrasena != "Cancel") AuthMoodle(usuario, contrasena);
} else {
Properties.Settings.Default.Contrasena = Encode(contra);
Properties.Settings.Default.Usuario = Encode(user);
Properties.Settings.Default.Save();
}
} catch { }
}
public static string Encode(string plainText) {
var plainTextBytes = Encoding.UTF8.GetBytes(plainText);
return Convert.ToBase64String(plainTextBytes);
}
public static string Decode(string encoded) {
var base64EncodedBytes = Convert.FromBase64String(encoded);
return Encoding.UTF8.GetString(base64EncodedBytes);
}
private void cambiarUsuario_Click(object sender, EventArgs e) {
string res = lxMessageInputBox.ShowDialog("Ingresa tus credenciales", "Ingresar Usuario", false, true, "Ingresa Contraseña");
string usuario = res.Split('[', ']')[1];
string contrasena = res.Split('(', ')')[1];
while ((res.Length < 9 && res.Length > 0)) {
if (contrasena == "Cancel") break;
res = lxMessageInputBox.ShowDialog("Ingresa tus credenciales", "Ingresar Usuario", false, true, "Ingresa Contraseña");
usuario = res.Split('[', ']')[1];
contrasena = res.Split('(', ')')[1];
}
if (contrasena != "Cancel") AuthMoodle(usuario, contrasena);
}
}
}