-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSignUpManager.cs
72 lines (68 loc) · 1.9 KB
/
SignUpManager.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
using Godot;
using System;
using System.Threading.Tasks;
public partial class SignUpManager : Control
{
private Button _submitButton;
private Button _login_button;
private Label _error_lable;
private LineEdit _username;
private LineEdit _password;
// Called when the node enters the scene tree for the first time.
public override void _Ready()
{
_submitButton = GetNode<Button>("Panel/Button");
_username = GetNode<LineEdit>("Panel/UserName");
_login_button = GetNode<Button>("Panel/Button2");
_password = GetNode<LineEdit>("Panel/Password");
_error_lable= GetNode<Label>("Panel/Label4");
_error_lable.Text = "";
_submitButton.Pressed += OnSubmitButtonPressed;
_login_button.Pressed += GoToLogin;
}
private void GoToLogin() {
GetTree().ChangeSceneToFile("res://Login.tscn");
}
private async void OnSubmitButtonPressed()
{
GD.Print("Starting tasks...");
try
{
var emailTask = Task.Run(() =>
{
GD.Print("task 1");
var emailHandler = new EmailHandler();
emailHandler.Send(_username.Text, "Flappy Bird Signup Confirmation", "Thank you for joining Flappy Bird!");
return true;
});
var saveUserTask = Task.Run(() =>
{
GD.Print("task 2");
var userInformationHandler = new UserInformationHandler();
return userInformationHandler.CreateUser(_username.Text, _password.Text);
});
bool[] results = await Task.WhenAll(emailTask, saveUserTask);
if (!results[1]) {
_error_lable.Text = "Username Already Exists";
} else {
GD.Print("Tasks completed successfully.");
this.GoToLogin();
}
}
catch (AggregateException ex)
{
foreach (var inner in ex.InnerExceptions)
{
GD.PrintErr("Task failed: " + inner.Message);
}
}
catch (Exception ex)
{
GD.PrintErr("Unexpected error: " + ex.Message);
}
}
// Called every frame. 'delta' is the elapsed time since the previous frame.
public override void _Process(double delta)
{
}
}