示例#1
0
 protected override void OnStart()
 {
     var user = new ParseUser () {
         Username = userName,
         Email = userName
     };
     user.SetPassword (password);
     user.SignUpInBackground (new TabSignUpCallback (user, SignUpCallback));
 }
示例#2
0
 void RefreshLoop(ParseUser user)
 {
     if (user.Has ("emailVerified")) {
         SetResult (Result.Ok);
         informativeText.Text = "Setting up...";
         LandingActivity.LaunchApp (this, user, null);
         return;
     } else {
         registeredUser.RefreshInBackground (new TabRefreshCallback ((o, e) => {
             RefreshLoop (user);
         }));
     }
 }
 public void UnlinkUserAsync(ParseUser user, NSAction callback)
 {
     var d = new NSActionDispatcher (callback);
     UnlinkUserAsync (user, d, NSActionDispatcher.Selector);
 }
 public void LinkUserAsync(ParseUser user, string twitterId, string screenName, string authToken, string authTokenSecret, NSAction callback)
 {
     var d = new NSActionDispatcher (callback);
     LinkUserAsync (user, twitterId, screenName, authToken, authTokenSecret, d, NSActionDispatcher.Selector);
 }
 public static void LinkUserAsync(ParseUser user, string facebookId, string accessToken, NSDate expirationDate, NSAction callback)
 {
     var d = new NSActionDispatcher (callback);
     LinkUserAsync (user, facebookId, accessToken, expirationDate, d, NSActionDispatcher.Selector);
 }
 public static void LinkUserAsync(ParseUser user, NSArray permissions, NSAction callback)
 {
     var d = new NSActionDispatcher (callback);
     LinkUserAsync (user, permissions, d, NSActionDispatcher.Selector);
 }
 public static bool ExtendAccessTokenIfNeeded(ParseUser user, NSAction callback)
 {
     var d = new NSActionDispatcher (callback);
     return ExtendAccessTokenIfNeeded (user, d, NSActionDispatcher.Selector);
 }
示例#8
0
        internal void LaunchApp(Activity ctx, ParseUser withUser, Action uiCallback)
        {
            // Fetch the person corresponding to the user
            Task.Factory.StartNew (() => {
                var query = new ParseQuery ("Person");
                query.SetCachePolicy (ParseQuery.CachePolicy.CacheElseNetwork);
                query.WhereEqualTo ("parseUser", withUser);
                query.Include ("parseUser");
                ParseObject self = null;
                try {
                    self = query.First;
                } catch (ParseException ex) {
                    // We may have a stall result from a previous registration
                    if (query.HasCachedResult) {
                        query.ClearCachedResult ();
                        try {
                            self = query.First;
                        } catch {
                            Android.Util.Log.Error ("Landing", "Error when trying to retrieve user 2. Normal if empty. {0}", ex.ToString ());
                        }
                    }
                    Android.Util.Log.Error ("Landing", "Error when trying to retrieve user. Normal if empty. {0}", ex.ToString ());
                }
                // First time ever, fill the info
                if (self == null) {
                    TabPerson person = null;
                    // Check if our TabPerson wasn't created indirectly by another user
                    query = new ParseQuery ("Person");
                    query.WhereEqualTo ("emails", TabPerson.MD5Hash (withUser.Email));
                    try {
                        person = TabPerson.FromParse (query.First);
                        person.AssociatedUser = withUser;
                    } catch {
                        // We use the main address email we got by parseUser
                        // and we will fill the rest lazily later from profile
                        // idem for the display name
                        person = new TabPerson {
                            AssociatedUser = withUser,
                            Emails = new string[] { withUser.Email }
                        };
                    }
                    return person;
                } else {
                    TabPerson.CurrentPerson = TabPerson.FromParse (self);
                    return null;
                }
            }).ContinueWith (t => {
                ctx.RunOnUiThread (() => {
                    // If the user was created, we setup a CursorLoader to query the information we need
                    if (t.Result != null) {
                        var person = t.Result;
                        person.DisplayName = profile.DisplayName;
                        person.Emails = profile.Emails.Union (person.Emails);
                        person.ToParse ().SaveEventually ();
                        TabPerson.CurrentPerson = person;
                    }

                    if (uiCallback != null)
                        uiCallback ();
                    ctx.Finish ();
                    ctx.StartActivity (typeof (MainActivity));
                });
            });
        }
示例#9
0
        public void LinkUserAsync(ParseUser user, string twitterId, string screenName, string authToken, string authTokenSecret, NSAction callback)
        {
            var d = new NSActionDispatcher(callback);

            LinkUserAsync(user, twitterId, screenName, authToken, authTokenSecret, d, NSActionDispatcher.Selector);
        }
示例#10
0
        public static bool ExtendAccessTokenIfNeeded(ParseUser user, NSAction callback)
        {
            var d = new NSActionDispatcher(callback);

            return(ExtendAccessTokenIfNeeded(user, d, NSActionDispatcher.Selector));
        }
示例#11
0
        public static void ExtendAccessTokenForUser(ParseUser user, NSAction callback)
        {
            var d = new NSActionDispatcher(callback);

            ExtendAccessTokenForUser(user, d, NSActionDispatcher.Selector);
        }
示例#12
0
        public static void LinkUserAsync(ParseUser user, string facebookId, string accessToken, NSDate expirationDate, NSAction callback)
        {
            var d = new NSActionDispatcher(callback);

            LinkUserAsync(user, facebookId, accessToken, expirationDate, d, NSActionDispatcher.Selector);
        }
示例#13
0
        public static void LinkUserAsync(ParseUser user, NSArray permissions, NSAction callback)
        {
            var d = new NSActionDispatcher(callback);

            LinkUserAsync(user, permissions, d, NSActionDispatcher.Selector);
        }
示例#14
0
        void SignUpCallback(ParseUser user, ParseException e)
        {
            if (isDead) {
                user.DeleteInBackground ();
                return;
            }

            progress.Visibility = ViewStates.Invisible;

            if (user != null && e == null) {
                informativeText.Text = "Verification email sent. Waiting for confirmation...";
                RefreshLoop (user);
            } else {
                SetResult (Result.Canceled);
                actionButton.Text = "< Go Back";
                informativeText.Text = "Error: the username likely exists already";
            }
        }
示例#15
0
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate (bundle);

            Parse.Initialize (this, ParseCredentials.ApplicationID, ParseCredentials.ClientKey);
            DensityExtensions.Initialize (this);

            // Set our view from the "main" layout resource
            SetContentView (Resource.Layout.Main);
            var signInBtn = FindViewById<Button> (Resource.Id.SignInButton);
            var signUpBtn = FindViewById<Button> (Resource.Id.SignUpButton);
            var userEntry = FindViewById<EditText> (Resource.Id.EmailEntry);
            var passwordEntry = FindViewById<EditText> (Resource.Id.PasswordEntry);

            /* If the user is already logged in, we show a blank landing page
             * (as there is a bit of delay when acquiring the TabPerson
             * so this activity content is still shown).
             */
            if (ParseUser.CurrentUser != null) {
                signInBtn.Visibility = signUpBtn.Visibility = userEntry.Visibility = passwordEntry.Visibility = ViewStates.Invisible;
                ParseUser.CurrentUser.RefreshInBackground (null);
                LaunchApp (this, ParseUser.CurrentUser, null);
            }

            profile = UserProfile.Instantiate (this);

            SignupTimer timer = null;
            userEntry.AfterTextChanged += (sender, e) => {
                var login = userEntry.Text;
                if (string.IsNullOrEmpty (login))
                    return;
                if (timer != null)
                    timer.Cancel ();
                timer = new SignupTimer (1000, 1000, () => {
                    var usernameChecker = CheckLoginDisponibility (login);
                    usernameChecker.ContinueWith (t => {
                        if (userEntry.Text == login)
                            signUpBtn.Enabled = t.Result;
                    }, TaskContinuationOptions.ExecuteSynchronously);
                });
                timer.Start ();
            };
            var initialEmail = profile.PrimayAddress ?? (profile.Emails == null ? null : profile.Emails.FirstOrDefault ()) ?? null;
            if (!string.IsNullOrEmpty (initialEmail))
                userEntry.Text = initialEmail;
            if (!string.IsNullOrEmpty (userEntry.Text))
                passwordEntry.RequestFocus ();

            ProgressDialog spinDialog = new ProgressDialog (this) { Indeterminate = true };
            spinDialog.SetCancelable (false);

            Action<ParseUser, ParseException> callback = (user, err) => {
                if (user == null || err != null) {
                    Android.Util.Log.Debug ("Login",
                                            "User not recognized: {0}",
                                            (err != null) ? err.Message : string.Empty);
                    spinDialog.Dismiss ();
                    var builder = new AlertDialog.Builder (this);
                    builder.SetMessage (Resource.String.login_error);
                    builder.SetPositiveButton ("OK", (a, b) => passwordEntry.Text = string.Empty);
                    builder.Create ().Show ();

                    return;
                }

                Android.Util.Log.Debug ("Login", "User {0} successfully logged. New? {1}", user.Username, user.IsNew);

                LaunchApp (this, user, spinDialog.Dismiss);
            };

            signInBtn.Click += (sender, e) => {
                spinDialog.SetMessage ("Signing in...");
                spinDialog.Show ();
                ParseUser.LogInInBackground (userEntry.Text,
                                             passwordEntry.Text,
                                             new TabLoginCallback (callback));
            };
            signUpBtn.Click += (sender, e) => {
                spinDialog.SetMessage ("Signing up...");
                spinDialog.Show ();
                var user = new ParseUser () {
                    Username = userEntry.Text,
                    Email = userEntry.Text
                };
                user.SetPassword (passwordEntry.Text);
                user.SignUpInBackground (new TabSignUpCallback (user, callback));
            };
        }
示例#16
0
 public override void Done(ParseUser p0, ParseException p1)
 {
     action (p0, p1);
 }
示例#17
0
        public void UnlinkUserAsync(ParseUser user, NSAction callback)
        {
            var d = new NSActionDispatcher(callback);

            UnlinkUserAsync(user, d, NSActionDispatcher.Selector);
        }
示例#18
0
 public TabSignUpCallback(ParseUser user, Action<ParseUser, ParseException> action)
 {
     this.user = user;
     this.action = action;
 }
示例#19
0
 public static void ExtendAccessTokenForUser(ParseUser user, NSAction callback)
 {
     var d = new NSActionDispatcher (callback);
     ExtendAccessTokenForUser (user, d, NSActionDispatcher.Selector);
 }