Esempio n. 1
0
        async void BtnLogin_TouchUpInsideAsync(object sender, EventArgs e)
        {
            try
            {
                txtPassword.ResignFirstResponder();
                //Validate our Username & Password.
                if (IsUserNameValid() && IsPasswordValid())
                {
                    SVProgressHUD.SetDefaultMaskType(SVProgressHUDMaskType.Black);
                    SVProgressHUD.ShowWithStatus("Checking Your Details...");

                    npcc_authentication oauth = new npcc_authentication();
                    inf_login_info      lg    = await oauth.Login(txtUsername.Text, txtPassword.Text);

                    SVProgressHUD.Dismiss();
                    SVProgressHUD.SetDefaultMaskType(SVProgressHUDMaskType.None);
                    //We have successfully authenticated a the user,
                    //Now fire our OnLoginSuccess Event.
                    if (lg.Authenticated == inf_login_result.SuccessfullyAuthenticated)
                    {
                        await SecureStorage.SetAsync("oauth_token", lg.Token);

                        //We have successfully authenticated a the user,
                        //Now fire our OnLoginSuccess Event.
                        if (OnLoginSuccess != null)
                        {
                            OnLoginSuccess(sender, new EventArgs());
                        }
                    }
                    else
                    {
                        SVProgressHUD.ShowErrorWithStatus(lg.Authenticated.ToString());
                        SVProgressHUD.DismissWithDelay(10);
                    }
                }
                else
                {
                    SVProgressHUD.ShowErrorWithStatus("Empty Username/ Password!");
                    SVProgressHUD.DismissWithDelay(10);
                }
            }
            catch (Exception ex)
            {
                npcc_services.inf_mobile_exception_managerAsync(ex.Message);
            }
        }
Esempio n. 2
0
        protected override async void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            oauth = new npcc_authentication();
            bool isAuth = await oauth.IsAuthenticatedAsync();

            if (isAuth)
            {
                StartActivity(typeof(HomeActivity));
                Finish();
            }
            else
            {
                StartActivity(typeof(LoginActivity));
                Finish();
            }
        }
        public async void setMainControllerAsync()
        {
            oauth = new npcc_authentication();

            bool isAuth = await oauth.IsAuthenticatedAsync();

            if (isAuth)
            {
                //We are already authenticated, so go to the main tab bar controller;
                var tabBarController = GetViewController(MainStoryboard, "InitialController");
                SetRootViewController(tabBarController, false);
            }
            else
            {
                //User needs to log in, so show the Login View Controlller
                var loginController = GetViewController(MainStoryboard, "LoginViewController") as LoginViewController;
                loginController.OnLoginSuccess += LoginController_OnLoginSuccess;
                SetRootViewController(loginController, false);
            }
        }
        async void BtnLogin_ClickAsync(object sender, EventArgs e)
        {
            if (IsUserNameValid() && IsPasswordValid())
            {
                AlertDialog dialog = new SpotsDialog(this, Resource.Style.CustomDialog);
                dialog.SetMessage("Checking Your Details...");
                dialog.SetCancelable(false);
                dialog.Show();

                npcc_authentication oauth = new npcc_authentication();
                inf_login_info      lg    = await oauth.Login(txtUsername.Text, txtPassword.Text);

                dialog.Dismiss();

                //We have successfully authenticated a the user,
                //Now fire our OnLoginSuccess Event.
                if (lg.Authenticated == inf_login_result.SuccessfullyAuthenticated)
                {
                    await SecureStorage.SetAsync("oauth_token", lg.Token);

                    //We have successfully authenticated a the user,
                    //Now fire our OnLoginSuccess Event.
                    DBRepository dBRepository = new DBRepository();
                    dBRepository.DropTable();
                    bool b = await dBRepository.RefreshUserInfoAsync();

                    StartActivity(typeof(HomeActivity));
                    Finish();
                }
                else
                {
                    Toast.MakeText(this, lg.Authenticated.ToString(), ToastLength.Long).Show();
                }
            }
            else
            {
                Toast.MakeText(this, "Empty Username/ Password!", ToastLength.Long).Show();
            }
        }