Esempio n. 1
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. 2
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 ();
		}