public async Task IsUserAuthenticated() { ServiceConnector connector = new ServiceConnector(); ServiceResponse response = await connector.Login("*****@*****.**", "123456"); Assert.IsTrue(response.Success, "Authentication error"); }
public async Task <IActionResult> Login(UserLoginViewModel user) { if (ModelState.IsValid) { (IActionResult res, bool serviceIsRunning) = await ServiceConnector.Login(user.UserName, user.PasswordString, _myConfig.Value.ServiceUrl); if (serviceIsRunning) { if (res is OkResult) { HttpContext.Session.SetString("LoggedUserName", user.UserName); return(RedirectToAction("Dialogue")); } else if (res is NotFoundResult) { ModelState.AddModelError(string.Empty, "Incorrect username or password"); } return(View(user)); } return(Content("Please, turn on your Dialogue Web Service")); } ModelState.AddModelError(string.Empty, "Invalid login attempt."); return(View(user)); }
async void Login() { if (NetworkCheck.IsInternet()) { IsIndicatorLoading = true; svcconnector = new ServiceConnector(); var response = await svcconnector.Login(UserName, Password); if (response.Success) { IsIndicatorLoading = false; var result = response.ResponseObject as UserAccount; //save the access token in singleton object AccessTokenSingleton.Instance.AccessToken = result.accessToken; var parameter = new NavigationParameters(); parameter.Add(AppConstants.AccessToken, result.accessToken); await _navigationservice.NavigateAsync("ClientPage", parameter); } else { IsIndicatorLoading = false; await _displayAlert.DisplayAlertAsync(response.ErrorObject.error.name, response.ErrorObject.error.message, "ok"); } } else { await _displayAlert.DisplayAlertAsync(AppConstants.NoInternetConnection, String.Empty, "ok"); } }