public static void Alert(ChatsViewController thisView) { UIAlertController loginAlert = UIAlertController.Create("Login Online", "Please enter your email and password", UIAlertControllerStyle.Alert); loginAlert.AddTextField((field) => { field.Placeholder = "Email"; field.KeyboardType = UIKeyboardType.EmailAddress; }); loginAlert.AddTextField((field) => { field.Placeholder = "Password"; field.SecureTextEntry = true; }); UIAlertAction loginAction; loginAction = UIAlertAction.Create("Login", UIAlertActionStyle.Default, async(UIAlertAction obj) => await Login(thisView, loginAlert.TextFields[0].Text, loginAlert.TextFields[1].Text)); loginAlert.AddAction(loginAction); loginAlert.AddAction(UIAlertAction.Create("Cancel", UIAlertActionStyle.Destructive, null)); thisView.PresentViewController(loginAlert, true, null); }
public static async Task Login(ChatsViewController thisView, string inputEmail, string inputPassword) { bool done = false; AppData.auth.SignInWithPassword(inputEmail, inputPassword, async(user, error) => { if (error != null) { AlertShow.Alert(thisView, "Error", "The following Error has occured: " + error.ToString()); return; } UserClass newUser = new UserClass { Name = user.User.DisplayName, Uid = user.User.Uid, Email = user.User.Email }; SetLocalUser.Set(newUser); await thisView.ReloadData(); AlertShow.Alert(thisView, "Login Was Successful", "Welcome back " + newUser.Name); done = true; }); while (!done) { await Task.Delay(50); } }
public static void Alert(ChatsViewController thisView) { UIAlertController registerAlert; registerAlert = UIAlertController.Create("Register", "Please enter name, email and password", UIAlertControllerStyle.Alert); registerAlert.AddTextField((textFld) => { textFld.Placeholder = "Name"; }); registerAlert.AddTextField((textFld) => { textFld.Placeholder = "Email"; textFld.KeyboardType = UIKeyboardType.EmailAddress; }); registerAlert.AddTextField((textFld) => { textFld.Placeholder = "Password"; textFld.SecureTextEntry = true; }); UIAlertAction register = UIAlertAction.Create("Register", UIAlertActionStyle.Default, async(obj) => await Register(thisView, registerAlert.TextFields[0].Text, registerAlert.TextFields[1].Text, registerAlert.TextFields[2].Text)); registerAlert.AddAction(register); registerAlert.AddAction(UIAlertAction.Create("Cancel", UIAlertActionStyle.Cancel, null)); thisView.PresentViewController(registerAlert, true, null); }
public static async Task Register(ChatsViewController thisView, string inputName, string inputEmail, string inputPassword) { bool done = false; AppData.auth.CreateUser(inputEmail, inputPassword, (user, error) => { if (error != null) { AlertShow.Alert(thisView, "Error", "This went wrong: " + error.UserInfo.Description); return; } UserProfileChangeRequest changeRequest = user.User.ProfileChangeRequest(); changeRequest.DisplayName = inputName; changeRequest.CommitChanges(async(profileError) => { if (profileError != null) { AlertShow.Alert(thisView, "Error", "Profile Error: " + profileError); return; } SetLocalUser.Set(new UserClass { Name = user.User.DisplayName, Email = user.User.Email, Uid = user.User.Uid }); object[] userKeys = { "name", "email", "uid" }; object[] userVals = { user.User.DisplayName, user.User.Email, user.User.Uid }; var userDict = NSDictionary.FromObjectsAndKeys(userVals, userKeys); AppData.UsersNode.GetChild(user.User.Uid).SetValue <NSDictionary>(userDict); foreach (ChatListClass any in AppData.currentLST) { if (any.ChatOwner.Uid == AppData.curUser.Uid) { SaveListOnCloud.Save(any); } } await thisView.ReloadData(); AlertShow.Alert(thisView, "Success", "You are now registered on Coder"); done = true; }); }); while (!done) { await Task.Delay(50); } }
public static async Task Read(ChatsViewController thisView) { ReadWriteDisk.ReadUser(); if (AppData.curUser == null) { AppData.curUser = new UserClass { Name = "Coder Dev Team", Email = "*****@*****.**", Uid = "defUid" }; PrepareInitialData.Prepare(); ReadWriteDisk.WriteData(); ReadWriteDisk.WriteUser(); } else { ReadWriteDisk.ReadData(); AppData.currentLST = AppData.offlineLST; } //color of profile button if offline thisView.SetLoginButton("Login", UIColor.Red); // read online chats if (AppData.auth.CurrentUser != null) { //color of profile button if online thisView.SetLoginButton("Hello " + AppData.auth.CurrentUser.DisplayName, UIColor.Cyan); //someone is logged in await ReadOnlineData.Read(); AppData.currentLST = CompareChatLists.Compare(AppData.onlineLST, AppData.offlineLST); ReadWriteDisk.WriteData(); foreach (ChatListClass any in AppData.currentLST) { if (any.ChatOwner.Uid == AppData.curUser.Uid) { SaveListOnCloud.Save(any); } } await ReadInvitations.Read(); //await FetchInvitations.Fetch(); //foreach (ChatListClass any in AppData.invitationsLST) // AppData.currentLST.Add(any); } }
public static async void Logout(ChatsViewController thisView) { NSError error; bool signedOut = AppData.auth.SignOut(out error); if (signedOut) { AlertShow.Alert(thisView, "Loged Out", "You can still work offline"); await thisView.ReloadData(); } else { AlertShow.Alert(thisView, "Error", error.ToString()); } }