static void Main(string[] args) { var authenticationService = new AuthenticationService( "http://192.168.56.22/app_dev.php", "token", "1_random_id", "secret" ); if (!authenticationService.Authenticate("test", "test")) Console.WriteLine("Failed to authenticate!"); _coursesRepository = new CoursesRepository("http://192.168.56.22/app_dev.php", authenticationService); int courseId = AddCourse(); EditCourse(courseId); PrintCourses(); RemoveCourse(courseId); }
private void SignInButton_OnClick(object sender, RoutedEventArgs e) { if (_isAuthenticationBegun) return; _isAuthenticationBegun = true; string username = "******"; string password = "******"; if (string.IsNullOrWhiteSpace(username) || string.IsNullOrWhiteSpace(password)) return; try { var authService = new AuthenticationService( AppConfig.ServiceUrl, AppConfig.AuthPath, AppConfig.ClientId, AppConfig.Secret ); if (authService.Authenticate(username, password)) { /*IQuestionsRepository questionsService = new QuestionsRepository(authenticationService.AuthResponse.access_token, new JsonSerializer()); var question = new VariantQuestionModel() { Content = "Choose an answer!", Enabled = true, TopicId = 1, Type = QuestionType.choice, UserId = 1, Variants = new List<VariantModel> { new VariantModel() { Body = "Answer A", Correct = false}, new VariantModel() { Body = "Answer B", Correct = false}, new VariantModel() { Body = "Answer C", Correct = true}, } }; var result = await questionsService.AddQuestion(question.TopicId, question); MessageBox.Show(result.ToString());*/ IUsersRepository usersService = new UsersRepository(AppConfig.ServiceUrl, authService); // TODO should find a method to get logged in user id //User user = usersService.Get(); //if (!user.Roles.Any( // r => r.Equals(RoleType.Teacher.ToString()) // || r.Equals(RoleType.Admin.ToString()))) //return; lock (AuthenticationMonitor) { var mainWindow = new MainWindow(authService); Close(); mainWindow.Show(); } } } catch (Exception ex) { MessageBox.Show("Email address or Password are incorrect."); MessageBox.Show(ex.ToString()); } _isAuthenticationBegun = false; }