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 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(); } }
public static bool IsLoggedIn() { var data = new NameValueCollection(); data.Add("login", string.Empty); if (WebFunctions.Request(data) == "Already logged in!") { return(true); } return(false); }
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(); }
protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); Functions.CurrentContext = this; Functions.DeleteSetting("signedInCookie"); Functions.DeleteSetting("settings", "loggedIn"); WebFunctions.ClearCookies(); SetContentView(Resource.Layout.Login); _btnLogin = FindViewById <Button> (Resource.Id.btnLogin); _txtEmail = FindViewById <EditText> (Resource.Id.txtEmail); _txtPassword = FindViewById <EditText> (Resource.Id.txtPassword); _lblRegister = FindViewById <TextView> (Resource.Id.lblRegister); _btnLogin.Click += btnLogin_OnClick; _lblRegister.Click += btnRegister_OnClick; }
public static void Sync() { Load(); if (_scannedCodes.Count == 0) { ResponseManager.ShowMessage("Note", "No grades to sync!"); return; } StringBuilder stringBuilder = new StringBuilder(); foreach (var code in _scannedCodes) { stringBuilder.AppendFormat("{0}-|-{1}-|-{2}-||-", code.Subject, code.Grade, code.Code); } var data = new NameValueCollection(); data.Add("newgrades", string.Empty); data.Add("data", stringBuilder.ToString()); string reply = WebFunctions.Request(data); string[] formattedReply = Regex.Split(reply, Environment.NewLine); foreach (string line in formattedReply) { if (line.StartsWith("Grade saved")) { DeleteFirstCode(); } else if (line.StartsWith("Code already used")) { DeleteFirstCode(); } } reply = reply.Replace("Grade saved!", string.Empty); reply = reply.Replace("Code already used!", string.Empty); formattedReply = Regex.Split(reply, Environment.NewLine); formattedReply = formattedReply.TrimArray(); List <string> gradedStudents = new List <string> (); StringBuilder resultMessage = new StringBuilder(); foreach (string line in formattedReply) { if (line.StartsWith("Graded student")) { gradedStudents.Add(line.Replace("Graded student: ", string.Empty)); } else { foreach (string line2 in formattedReply) { resultMessage.AppendLine(line2); } Functions.CurrentContext.RunOnUiThread(() => ResponseManager.ShowMessage("Success", resultMessage.ToString())); return; } } if (gradedStudents.Count == 0) { resultMessage.AppendLine("All sent codes were already graded!"); } else { resultMessage.AppendLine("Grades successfully synced to server! Results:"); resultMessage.AppendLine(); foreach (string student in Functions.ShuffleArray(gradedStudents.ToArray())) { resultMessage.AppendLine(student); } } Functions.CurrentContext.RunOnUiThread(() => ResponseManager.ShowMessage("Success", resultMessage.ToString())); }