private void Login_Click(object sender, RoutedEventArgs e) { ToggleError(null); string name = TextBox_Name.Text; string password = TextBox_Password.Password; try { AuthenticationModel authModel = NotesApi.GetAuthenticationModel(name, password); IRestResponse <UserDto> response = NotesApi.Execute <UserDto>("Authentication/Login", Method.POST, authModel); UserDto result = NotesApi.GetData(response); if (string.IsNullOrEmpty(result.Token)) { throw new Exception("Failed to login"); } UserAuthenticated?.Invoke(this, new AuthenticationEventArgs { User = result }); } catch (Exception x) { ToggleError(x.Message); } }
private void Register_Click(object sender, RoutedEventArgs e) { ToggleError(null); string name = TextBox_Name.Text; string password = TextBox_Password.Password; string password2 = TextBox_Password2.Password; try { if (password != password2) { throw new Exception("Passwords must match"); } AuthenticationModel authModel = NotesApi.GetAuthenticationModel(name, password); IRestResponse <UserDto> response = NotesApi.Execute <UserDto>("Authentication/Register", Method.PUT, authModel); UserDto result = response.Data; if (string.IsNullOrEmpty(result.Token)) { throw new Exception("Failed to Register"); } UserAuthenticated?.Invoke(this, new AuthenticationEventArgs { User = result }); Visibility = Visibility.Collapsed; } catch (Exception x) { ToggleError(x.Message); } }