Exemplo n.º 1
0
        private void DoRegister(object sender, EventArgs e)
        {
            if (Functions.IsOffline())
            {
                ResponseManager.ShowMessage("Error", "No internet connection!");
                return;
            }

            if (_txtPassword.Text != _txtPassword2.Text)
            {
                ResponseManager.ShowMessage("Error", "Passwords do not match!");
                return;
            }

            ResponseManager.ShowLoading("Creating account...");

            var data = new NameValueCollection();

            data.Add("register", string.Empty);
            data.Add("email", _txtEmail.Text);
            data.Add("password", Functions.GetSha256(_txtPassword.Text));
            data.Add("firstname", _txtFirstName.Text);
            data.Add("lastname", _txtLastName.Text);
            data.Add("class", _txtClass.Text);

            string reply = WebFunctions.Request(data);

            ResponseManager.DismissLoading();

            if (reply != "Account created!")
            {
                ResponseManager.ShowMessage("Error", reply);
                WebFunctions.ClearCookies();
                return;
            }

            RunOnUiThread(delegate {
                var dialogFragment = new DialogFragment();

                dialogFragment.InitializeOk(reply, "Success", delegate {
                    Intent resultData = new Intent();
                    resultData.PutExtra("email", _txtEmail.Text);
                    resultData.PutExtra("password", _txtPassword.Text);
                    SetResult(Result.Ok, resultData);
                    Finish();
                });

                dialogFragment.Show();
            });
        }
Exemplo n.º 2
0
        private void DoLogin(object sender, EventArgs e)
        {
            if (Functions.IsOffline())
            {
                ResponseManager.ShowMessage("Error", "No internet connection!");
                return;
            }

            ResponseManager.ShowLoading("Logging in...");

            var data = new NameValueCollection();

            data.Add("login", string.Empty);
            data.Add("email", _txtEmail.Text);
            data.Add("password", Functions.GetSha256(_txtPassword.Text));

            string reply = WebFunctions.Request(data);

            if (reply != "Login success!")
            {
                ResponseManager.DismissLoading();
                ResponseManager.ShowMessage("Error", reply);
                WebFunctions.ClearCookies();
                return;
            }

            data.Clear();
            data.Add("getaccounttype", string.Empty);

            reply = WebFunctions.Request(data);

            if (reply != "student" && reply != "teacher")
            {
                ResponseManager.DismissLoading();
                ResponseManager.ShowMessage("Error", "Unrecognized account type!");
                WebFunctions.ClearCookies();
                return;
            }

            Functions.SaveSetting("settings", "accountType", reply);
            Functions.SaveSetting("settings", "loggedIn", "true");
            StartActivity(typeof(MainActivity));
            Finish();
        }
Exemplo n.º 3
0
        public override bool OnOptionsItemSelected(IMenuItem item)
        {
            if (item.ItemId == Resource.Id.action_settings)
            {
                ResponseManager.ShowLoading("Logging out...");
                ThreadPool.QueueUserWorkItem(o => DoLogout());
            }
            else if (item.ItemId == Resource.Id.action_refresh)
            {
                if (Functions.IsOffline())
                {
                    ResponseManager.ShowMessage("Error", "Cannot complete action while offline.");
                    return(base.OnOptionsItemSelected(item));
                }

                ResponseManager.ShowLoading("Fetching user data...");
                ThreadPool.QueueUserWorkItem(o => FetchStudentData());
            }

            return(base.OnOptionsItemSelected(item));
        }
Exemplo n.º 4
0
        private void InitializeStudent()
        {
            SetContentView(Resource.Layout.MainStudent);
            this.ActionBar.NavigationMode = ActionBarNavigationMode.Standard;
            this.Title = "APlus Student Panel";

            if (Functions.IsOffline())
            {
                ResponseManager.ShowMessage("Error", "Cannot complete action while offline.");
                return;
            }

            ResponseManager.ShowLoading("Fetching user data...");

            ThreadPool.QueueUserWorkItem(o => {
                while (!_checkedStatus)
                {
                    Thread.Sleep(100);
                }

                FetchStudentData();
            });
        }