Beispiel #1
0
        public void FacebookLogin(string code)
        {
            UserDetails facebookUser = GetFacebookUserData(code);
            UserDetails user         = new UserDetails();

            // Check the existance of an identical local account
            PickrWebService api    = new PickrWebService();
            JObject         json   = api.CheckUserExistence(facebookUser.Email);
            bool            exists = (bool)json["Value"];

            if (exists)
            {
                json = api.GetUser(facebookUser.Email);
                JSONParser parser = new JSONParser();
                user = parser.ParseUser(json);

                // Update profile with facebook data
                json = api.UpdateUser(user.Email, facebookUser.FirstName, facebookUser.Surname, DateTime.MinValue, "", "", facebookUser.Picture, "", "", "");
                bool updated = parser.ParseUpdateTable(json);
                //UpdateUser(user.Email, facebookUser.FirstName, facebookUser.Surname, DateTime.MinValue, "", "", facebookUser.Picture, "", "");

                LocalLogin(user.Email, user.Password);
            }

            else
            {
                HttpContext.Current.Session["FacebookUser"] = facebookUser;
                Response.Redirect("/Account/RegisterFacebook");
            }
        }
        public bool UpdateProfile(string firstname, string surname, DateTime birth, string gender, string mobile, string picture, string address, string mode, string car, bool?smoking, bool?music, bool?pets, int?talking)
        {
            PickrWebService api    = new PickrWebService();
            JSONParser      parser = new JSONParser();
            UserDetails     u      = (UserDetails)HttpContext.Current.Session["User"];

            JObject json = api.UpdateUser(u.Email, firstname, surname, birth, gender, mobile, picture, address, mode, car);


            bool updated = false;

            updated = parser.ParseUpdateTable(json);


            if (smoking != null && music != null && pets != null && talking != null)
            {
                JObject jsonPrefs    = api.SetUserPreferences(u.Email, (bool)smoking, (bool)music, (bool)pets, (int)talking);
                bool    prefsUpdated = false;
                prefsUpdated = parser.ParseUpdateTable(jsonPrefs);
                updated      = updated && prefsUpdated;
            }



            if (updated)
            {
                json = api.GetUser(u.Email);
                u    = parser.ParseUser(json);

                // Update session user
                HttpContext.Current.Session["User"] = u;
                Response.Redirect("Manage?updated=true");
            }

            else if (!updated)
            {
                ErrorMessage.Text = "Profile could not be updated.";
            }

            return(updated);
        }
Beispiel #3
0
        public void LocalLogin(string Email, string Password)
        {
            if (!String.IsNullOrEmpty(Email) && !String.IsNullOrEmpty(Password))
            {
                PickrWebService api    = new PickrWebService();
                JSONParser      parser = new JSONParser();
                UserDetails     user   = new UserDetails();

                JObject json = api.UserAuthentication(Email, Password);

                bool valid = parser.ParseUserAuthentication(json);

                // If the user exists then give acces

                if (valid)
                {
                    json = api.GetUser(Email);
                    user = parser.ParseUser(json);

                    //if (IsValid)
                    //{
                    ApplicationUserManager   manager;
                    ApplicationSignInManager signinManager;
                    SignInStatus             result;

                    try
                    {
                        // Validate the user password
                        manager       = Context.GetOwinContext().GetUserManager <ApplicationUserManager>();
                        signinManager = Context.GetOwinContext().GetUserManager <ApplicationSignInManager>();

                        // This doen't count login failures towards account lockout
                        // To enable password failures to trigger lockout, change to shouldLockout: true
                        result = signinManager.PasswordSignIn(Email, Password, RememberMe.Checked, shouldLockout: false);
                        if (result == SignInStatus.Failure)
                        {
                            //Register in the Sign in manager local database if user doesn't exist
                            var registerResult = manager.Create(new ApplicationUser()
                            {
                                UserName = Email, Email = Email
                            }, Password);
                            if (registerResult.Succeeded)
                            {
                                result = signinManager.PasswordSignIn(Email, Password, RememberMe.Checked, shouldLockout: false);
                            }
                        }

                        switch (result)
                        {
                        case SignInStatus.Success:

                            Response.Cookies["SoonNotification"].Value = "0";
                            HttpContext.Current.Session["User"]        = user;

                            //IdentityHelper.RedirectToReturnUrl(Request.QueryString["ReturnUrl"], Response);
                            if (user.Mode.Equals("driver"))
                            {
                                Response.Redirect("/DriverHome");
                            }
                            else
                            {
                                Response.Redirect("/PassengerHome");
                            }
                            break;

                        case SignInStatus.LockedOut:
                            Response.Redirect("/Account/Lockout");
                            break;

                        case SignInStatus.RequiresVerification:
                            Response.Redirect(String.Format("/Account/TwoFactorAuthenticationSignIn?ReturnUrl={0}&RememberMe={1}",
                                                            Request.QueryString["ReturnUrl"],
                                                            RememberMe.Checked),
                                              true);
                            break;

                        case SignInStatus.Failure:
                        default:
                            FailureText.Text     = "Invalid login attempt";
                            ErrorMessage.Visible = true;
                            break;
                        }
                    }
                    catch (DataException e)
                    {
                        FailureText.Text     = "Error while logging in, please try again";
                        ErrorMessage.Visible = true;
                    }


                    //}
                }

                else
                {
                    FailureText.Text     = "Invalid email or password";
                    ErrorMessage.Visible = true;
                }
            }
        }