Titanic/Titanic/Splash.cs
2023-02-02 18:49:14 +05:30

86 lines
2.3 KiB
C#

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Net;
using System.Security.Policy;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Titanic
{
public partial class Splash : Form
{
public Splash()
{
InitializeComponent();
if(Properties.Settings.Default.username.Length >0 && Properties.Settings.Default.password.Length > 0)
{
textBox1.Text = Properties.Settings.Default.username;
textBox2.Text = Properties.Settings.Default.password;
//Login();
}
}
private void label3_Click(object sender, EventArgs e)
{
Helpers.OpenURL("http://192.168.1.4:3000/user/sign_up");
}
private void btn_login_ClickAsync(object sender, EventArgs e)
{
Login();
}
async void Login()
{
this.Hide();
string curlArgs = $"-u {textBox1.Text}:{textBox2.Text} {Helpers.GOGS_API}users/{textBox1.Text}/tokens";
string uri = $"{Helpers.GOGS_API}users/{textBox1.Text}/tokens";
string loginResponse = await Helpers.GetAsync(uri, textBox1.Text, textBox2.Text);
try
{
//string loginResponse = Helpers.Get(Helpers.GOGS_API + "users/" + textBox1.Text + "/tokens");
if (loginResponse.Contains("[") && loginResponse.Contains("]"))
{
//MessageBox.Show("Success\n"+loginResponse.Split("[")[0].Split("]")[0]);
OnLoginSuccess();
return;
}
}
catch (Exception ex)
{
MessageBox.Show(loginResponse);
}
this.Show();
}
void OnLoginSuccess()
{
Properties.Settings.Default.username = textBox1.Text;
Properties.Settings.Default.password= textBox2.Text;
Properties.Settings.Default.Save();
this.Hide();
Form1 form = new Form1();
form.Show();
}
private void button2_Click(object sender, EventArgs e)
{
Application.Exit();
}
}
}