Exemple #1
0
        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);
            }
        }
Exemple #2
0
        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);
            }
        }
Exemple #3
0
        public static void Invite(UIViewController thisView, ChatListClass toChat, string inviteeEmail)
        {
            UserClass inviteeUser  = null;
            UserClass inviterUser  = AppData.curUser;
            String    thisChatName = toChat.ChatName;

            AppData.UsersNode.ObserveSingleEvent(DataEventType.Value, (snapshot) =>
            {
                NSEnumerator children = snapshot.Children;
                var childSnapShot     = children.NextObject() as DataSnapshot;

                while (childSnapShot != null)
                {
                    NSDictionary childDict = childSnapShot.GetValue <NSDictionary>();

                    if (childDict.ValueForKey((NSString)"email").ToString() == inviteeEmail)
                    {
                        // user exist
                        inviteeUser = new UserClass
                        {
                            Name  = childDict.ValueForKey((NSString)"name").ToString(),
                            Email = childDict.ValueForKey((NSString)"email").ToString(),
                            Uid   = childDict.ValueForKey((NSString)"uid").ToString()
                        };
                        break;
                    }
                    childSnapShot = children.NextObject() as DataSnapshot;
                }


                if (inviteeUser == null)
                {
                    AlertShow.Alert(thisView, "No Such User", "User is not registered with us");
                    return;
                }

                String invitationTitle = inviterUser.Uid + "|" + thisChatName;

                object[] ownerKeys = { "ownerUid", "ownerEmail", "ownerName" };
                object[] ownerVals = { inviterUser.Uid, inviterUser.Email, inviterUser.Name };
                var ownerDict      = NSDictionary.FromObjectsAndKeys(ownerVals, ownerKeys);

                object[] inviteeKeys = { "chatName", "owner" };
                object[] inviteeVals = { thisChatName, ownerDict };
                var inviteeDict      = NSDictionary.FromObjectsAndKeys(inviteeVals, inviteeKeys);

                DatabaseReference inviteeNode = AppData.UsersNode.GetChild(inviteeUser.Uid);
                inviteeNode.GetChild("myInvitations")
                .GetChild(invitationTitle)
                .SetValue <NSDictionary>(inviteeDict);

                AlertShow.Alert(thisView, "Invitation Sent", "You have successfully invited " + inviteeUser.Name + " to this chat");
            });
        }
Exemple #4
0
        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());
            }
        }