private static void DoLogout() { if (Functions.IsOffline()) { Functions.CurrentContext.StartActivity(typeof(LoginActivity)); Functions.CurrentContext.Finish(); // Rest of log in data cleared in constructor return; } var data = new NameValueCollection(); data.Add("logout", string.Empty); string response = WebFunctions.Request(data); if (response == "Logged out successfully" || response == "Not logged in!") { Functions.CurrentContext.StartActivity(typeof(LoginActivity)); Functions.CurrentContext.Finish(); // Rest of log in data cleared in constructor } else { ResponseManager.ShowMessage("Error", response); ResponseManager.DismissLoading(); } }
private void FetchStudentData() { var data = new NameValueCollection(); data.Add("checkuser", string.Empty); string rawReply = WebFunctions.Request(data); if (!rawReply.Contains("Registered")) { StartActivity(typeof(LoginActivity)); Finish(); return; } string[] reply = Regex.Split(rawReply, "<br>").TrimArray(); Regex userMatch = new Regex(":.*"); string user = (from a in reply where !string.IsNullOrWhiteSpace(userMatch.Match(a).Value) select userMatch.Match(a).Value.Remove(0, 2)).First(); var listView = FindViewById <ListView> (Resource.Id.listView1); var adapter = new ArrayAdapter <String> (this, Android.Resource.Layout.SimpleListItem1, reply); RunOnUiThread(() => listView.Adapter = adapter); ResponseManager.DismissLoading(); }
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(); }); }
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(); }