void PasswordEntryCompleted(object sender, EventArgs eventArgs) { UsernameEntry.IsEnabled = false; PasswordEntry.IsEnabled = false; LoadingIndicator.IsRunning = true; StatusLabel.IsVisible = false; LoginButton.IsVisible = false; Application.Current.Properties["notificationTimestamp"] = (long)-1; // Dependency injection per interfaces IAuthenticator auth = AuthenticationSystemManager.NewAuthenticator(); auth.Result += LoginResponse; auth.Login(UsernameEntry.Text, PasswordEntry.Text); }
public LoginPage() { InitializeComponent(); #pragma warning disable CS0618 // Type or member is obsolete RegisterLabel.GestureRecognizers.Add(new TapGestureRecognizer(async(view) => { if (!LoadingIndicator.IsRunning && !IsRegisterPageOpen) { IsRegisterPageOpen = true; await Navigation.PushModalAsync(new NavigationPage(new RegisterPage())); } })); #pragma warning restore CS0618 // Type or member is obsolete UsernameEntry.Completed += (o, e) => { PasswordEntry.Focus(); }; PasswordEntry.Completed += PasswordEntryCompleted; if (Application.Current.Properties.ContainsKey("PrivateKey")) { UsernameEntry.IsEnabled = false; PasswordEntry.IsEnabled = false; LoadingIndicator.IsRunning = true; StatusLabel.IsVisible = false; LoginButton.IsVisible = false; // Dependency injection per interfaces var auth = AuthenticationSystemManager.NewAuthenticator(); auth.Result += LoginResponse; auth.Login((string)Application.Current.Properties["PrivateKey"]); } MessagingCenter.Subscribe <RegisterPage, Tuple <string, string> >(this, "Success", (obj, loginInfo) => { UsernameEntry.Text = loginInfo.Item1; PasswordEntry.Text = loginInfo.Item2; PasswordEntryCompleted(null, null); }); MessagingCenter.Subscribe <RegisterPage>(this, "Closing", (obj) => { IsRegisterPageOpen = false; }); }
public void PrivateKeyTest() { LocalUser user = Login(); bool done = false; LocalUser user1 = null; AuthenticatorStatus status = AuthenticatorStatus.UnknownError; var auth = AuthenticationSystemManager.NewAuthenticator(); auth.Result += (_status, _user) => { status = _status; user1 = _user; done = true; }; auth.Login(user.PrivateKey); while (!done) { } Assert.AreEqual(status, AuthenticatorStatus.Success); Assert.AreEqual(user.PrivateKey, user1.PrivateKey); Assert.AreEqual(user.Username, user1.Username); }
public static LocalUser Login(string username = "******", string password = "******") { AuthenticatorStatus status = AuthenticatorStatus.UnknownError; LocalUser user = null; bool done = false; var auth = AuthenticationSystemManager.NewAuthenticator(); auth.Result += (_status, _user) => { status = _status; user = _user; done = true; }; auth.Login(username, password); while (!done) { } Assert.AreEqual(status, AuthenticatorStatus.Success); Assert.AreNotEqual(user, null); Assert.AreEqual(user.Username, username); LocalUserManager.LocalUser = user; return(user); }