Beispiel #1
0
        async void onLoginBtnClicked(object sender, EventArgs e)
        {
            errorLbl.Text = "";
            bool   isInputsValid = true;
            string username = "", password = "";

            if (String.IsNullOrEmpty(userIdEntry.Text) || String.IsNullOrWhiteSpace(userIdEntry.Text))
            {
                errorLbl.Text += "Please enter User Id. ";
                isInputsValid  = false;
            }

            if (String.IsNullOrEmpty(passwordEntry.Text) || String.IsNullOrWhiteSpace(passwordEntry.Text))
            {
                errorLbl.Text += "Please enter your password.";
                isInputsValid  = false;
            }

            if (isInputsValid)
            {
                activityIndicator.IsVisible = true;
                activityIndicator.IsRunning = true;
                username = userIdEntry.Text;
                password = passwordEntry.Text;

                //Send HTTP request to log user in
                string httpTask = await Task.Run <string>(() => HttpRequestHandler.PostUserLogin(username, password));

                var httpResult = httpTask.ToString();
                activityIndicator.IsVisible = false;
                activityIndicator.IsRunning = false;
                if (httpResult == "Success")
                {
                    //Navigate to tender page
                    errorLbl.TextColor = Color.Green;

                    errorLbl.Text = "Login success! You will be redirected soon";
                    await Task.Delay(1000);

                    errorLbl.TextColor = Color.Red;
                    errorLbl.Text      = "";
                    Console.WriteLine("My cookie: " + httpResult);
                    Console.WriteLine("Cookie result: " + userSession.userLoginCookie);
                    //await Navigation.PushAsync(new tenderPage());
                    //App.Current.MainPage = new rootPage { Detail = new NavigationPage(new tenderEligiblePage()) };
                    App.Current.MainPage = new rootPage(true);
                    //rootPage.changeDetailPage(typeof(tenderPage));
                }
                else
                {
                    //Display error message
                    errorLbl.Text = httpResult;
                }
            }
        }
Beispiel #2
0
 private static string checkUserLogin()
 {
     if (String.IsNullOrEmpty(Settings.Username)) //user not logged in
     {
         Console.WriteLine("No username");
         return("false");
     }
     else
     {
         if (Settings.Role == "user")
         {
             //Send HTTP request to log user in
             Task <string> httpTask   = Task.Run <string>(() => HttpRequestHandler.PostUserLogin(Settings.Username, Settings.Password));
             var           httpResult = httpTask.Result.ToString();
             Console.WriteLine("User runned");
             Console.WriteLine("HTTP Result: " + httpResult);
             if (httpResult == "Login successful!")
             {
                 Console.WriteLine("User returned");
                 return("user");
             }
             else
             {
                 return("false");
             }
         }
         else
         {
             //Login as admin
             Task <string> httpTask   = Task.Run <string>(() => HttpRequestHandler.PostAdminLogin(Settings.Username, Settings.Password));
             var           httpResult = httpTask.Result.ToString();
             Console.WriteLine("HTTP Result for admin: " + httpResult);
             if (httpResult != "admin" && httpResult != "editor")
             {
                 return("false");
             }
             else
             {
                 adminAuth.saveCredentials(Settings.Username, Settings.Password);
                 userSession.adminRole = httpResult;
                 return("admin");
             }
         }
     }
 }