Esempio n. 1
0
        /// <summary>
        /// On SignUp activity completion, this will attempt to sign up user to the database.
        /// </summary>
        /// <param name="sender">The object that invoked the event</param>
        /// <param name="e">The event arguments</param>
        async void signUpDialog_mOnSignUpComplete(Object sender, OnSignUpEventArgs e)
        {
            // Retrieves data from SignUp activity
            userNameSignUp     = e.UserName;
            userPasswordSignUp = e.Password;

            /// Checks if username is taken. If taken, user is notified. Otherwise a new profile object is created.
            /// User is then taken to EditProfileActivity.
            if (await TryToSignUp(userNameSignUp, userPasswordSignUp))
            {
                //Create a default profile to start
                username   = credentials.username;
                user_token = credentials.token;
                string  userGender = null;
                string  userBio    = null;
                Profile myProfile  = new Profile(credentials.username, userGender, userBio, credentials.token);

                //Send the temporary profile to the server
                if (await Poster.PostObject(myProfile, serverURL + profile_ext))
                {
                    // pass profile object to EditProfileActivity, so the user can fill in their information
                    Intent intent            = new Intent(this, typeof(EditProfileActivity));
                    var    serializedProfile = JsonConvert.SerializeObject(myProfile);
                    intent.PutExtra("UserProfile", serializedProfile);
                    StartActivity(intent);
                }
            }
            else
            {
                Toast.MakeText(this, "Signup Unsuccessful ", ToastLength.Short).Show();
            }
        }
Esempio n. 2
0
 /// <summary>
 /// Block the currently viewed user
 /// </summary>
 /// <param name="sender">The object that invoked the event</param>
 /// <param name="e">The event arguments</param>
 async void MBlock_Click(object sender, EventArgs e)
 {
     //Try to block the user
     if (await Poster.PostObject(new { username = MainActivity.credentials.username, block_username = profile.username, token = MainActivity.credentials.token },
                                 URLs.serverURL + URLs.blacklist_user))
     {
         Toast.MakeText(this, "Successfully blocked user!", ToastLength.Short).Show();
     }
     else
     {
         Toast.MakeText(this, "Unable to block user", ToastLength.Short).Show();
     }
 }
Esempio n. 3
0
        /// <summary>
        ///  Retrieves data from Sign in activity and attempts to sign in user
        ///  to the database. If user has no profile it will start EditProfile Activity
        ///  If user has a profile, HomeActivity will be started
        /// </summary>
        /// <param name="sender">The object that invoked the event</param>
        /// <param name="e">The event arguments</param>
        public async void signInDialog_mOnSignInComplete(Object sender, OnSignInEventArgs e)
        {
            // Retrieves data from SignIn Activity
            userNameSignIn     = e.Username;
            userPasswordSignIn = e.Password;

            // Attempts to log in.
            //If user has no profile, they are notified and EditProfileActivity is started
            // and users profile object is passed.
            // Else statement occurs if user has a profile. HomeActivity is started and profile object is passed.
            if (await TryToLogin(userNameSignIn, userPasswordSignIn))
            {
                var userProfile = await Getter <Profile> .GetObject(serverURL + profile_ext + "/" + userNameSignIn);

                if (userProfile == default(Profile))
                {
                    Toast.MakeText(this, "You don't have a profile to show", ToastLength.Short).Show();
                    string  userGender = null;
                    string  userBio    = null;
                    Profile myProfile  = new Profile(credentials.username, userGender, userBio, credentials.token);

                    if (await Poster.PostObject(myProfile, serverURL + profile_ext))
                    {
                        // pass profile object to EditProfileActivity
                        Intent intent            = new Intent(this, typeof(EditProfileActivity));
                        var    serializedProfile = JsonConvert.SerializeObject(myProfile);
                        intent.PutExtra("UserProfile", serializedProfile);
                        StartActivity(intent);
                    }
                }
                else
                {
                    //Set the variables associated with the user session
                    username          = credentials.username;
                    user_token        = credentials.token;
                    userProfile.token = credentials.token;

                    //Open the main menu and pass the profile object
                    Intent intent            = new Intent(this, typeof(HomeActivity));
                    var    serializedProfile = JsonConvert.SerializeObject(userProfile);
                    intent.PutExtra("UserProfile", serializedProfile);
                    StartActivity(intent);
                }
            }
            else
            {
                Toast.MakeText(this, "Login Unsuccessful ", ToastLength.Short).Show();
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Do the sign up procedure
        /// </summary>
        /// <param name="username"> the user's username, gotten from the gui</param>
        /// <param name="password"> the user's password, gotten from the gui</param>
        /// <returns> whether or not the user was successfully signed up</returns>
        private async Task <Boolean> TryToSignUp(string username, string password)
        {
            credentials = new Credentials(username);

            try
            {
                //Try to register the user with the system
                if (await credentials.doSignUp(password, serverURL + login_ext))
                {
                    //If registration was successful, send a request to create a new entry in the table with GCM ids
                    return(await Poster.PostObject(new { token = credentials.token, username = username, gcm_regid = gcm_token }, serverURL + gcm_regid_ext));
                }
                else
                {
                    return(false);
                }
            }
            catch
            {
                return(false);
            }
        }