예제 #1
0
        protected void Page_Load(Object sender, EventArgs e)
        {
            if (Request.IsAuthenticated)
            {
                Response.Redirect("~/createflyer.aspx", true);
            }

            if (Request.IsGet())
            {
                Request.RedirectToHttpsIfRequired(Response);

                if (Request["errormessage"].HasText())
                {
                    divSummaryError.Visible = true;
                    ltlMessage.Text         = Request["errormessage"];
                }
                else if (SocialHelper.IsLinkedInError())
                {
                    if (String.Compare(Request["error"], "access_denied", true) == 0)
                    {
                        Response.Redirect("~/signup.aspx", true);
                    }

                    divSummaryError.Visible = true;
                    ltlMessage.Text         = String.Format("LinkedIn: {0} (code {1})", Request["error_description"], Request["error"]);
                }
            }

            RootURL = clsUtility.GetRootHost;

            if (CanAuthenticate())
            {
                Authenticate(Request.Form["username"], Request.Form["password"]);
            }
        }
예제 #2
0
        private Boolean IsSocialAuthenticationProvider()
        {
            var result = Request["authenticationProvider"].HasText();

            if (!result)
            {
                result = SocialHelper.IsLinkedInCodeRedirect();

                if (result)
                {
                    var state = SocialHelper.GetLinkedInAuthenticationState();

                    if (state.HasNoText())
                    {
                        Response.Redirect("~/login.aspx", true);
                    }
                    else if (String.Compare(state, Request["state"], false) != 0)
                    {
                        Helper.SetErrorResponse(HttpStatusCode.BadRequest, "Cross Site Request Forgery attempt detected.");
                    }
                }
            }

            return(result);
        }
예제 #3
0
        private void SetInputsInModeMini()
        {
            if (IsPostBack)
            {
                return;
            }

            SocialHelper.RemoveSocialProfileFromSessionIfNeeded();

            var socialUserModel = SocialHelper.GetSocialProfileFormSession() != null?SocialHelper.GetSocialProfileFormSession().UserModel : SocialHelper.BindUserModel();

            if (socialUserModel != null)
            {
                if (socialUserModel.Email.HasText())
                {
                    try
                    {
                        if (SocialHelper.CanAuthenticateAsync())
                        {
                            SocialHelper.SetSocialProfileToSession(SocialHelper.CreateSocialProfileIfNeeded());
                            divEmail.Visible           = false;
                            divConfirmEmail.Visible    = false;
                            divPassword.Visible        = false;
                            divConfirmPassword.Visible = false;
                            divFirstName.Visible       = socialUserModel.FirstName.HasNoText();
                            divLastName.Visible        = socialUserModel.LastName.HasNoText();

                            if (!(inputFirstName.Visible || inputLastName.Visible))
                            {
                                divMiddleName.Visible = false;
                            }
                        }
                        else
                        {
                            divSummaryError.Visible = true;
                            ltlMessage.Text         = "Cannot validate email " + socialUserModel.Email + ". Please complete registration manually. Possible reasons: <br />1) access to email address is not allowed by user<br />2) email from social network profile is not equal to email obtained with given access token.";
                        }
                    }
                    catch (Exception ex)
                    {
                        divSummaryError.Visible = true;
                        ltlMessage.Text         = ex.Message;
                    }
                }

                inputFirstName.Value  = socialUserModel.FirstName;
                inputMiddleName.Value = socialUserModel.MiddleName;
                inputLastName.Value   = socialUserModel.LastName;

                if (socialUserModel.AvatarUrl.HasText())
                {
                    divSocImage.Visible  = true;
                    imageAvatar.ImageUrl = socialUserModel.AvatarUrl;
                }
            }
        }
예제 #4
0
        private void AuthenticateThroughSocialProvider()
        {
            try
            {
                var socialAuthenticationModel = SocialHelper.BindAuthenticationModel();

                if (SocialHelper.CanAuthenticateAsync())
                {
                    var user = Membership.GetUser(socialAuthenticationModel.UserName);

                    if (user != null)
                    {
                        var redirectionUrl = RootURL + "createflyer.aspx";

                        if (Request["returnurl"].HasText())
                        {
                            redirectionUrl = new Uri(RootURL.ToUri(), Request["returnurl"]).ToString();
                        }

                        HandleSocialAuthenticationResponse(socialAuthenticationModel, true, false, redirectionUrl, null);
                    }
                    else
                    {
                        HandleSocialAuthenticationResponse(socialAuthenticationModel, false, true, null, null);
                    }
                }
                else
                {
                    HandleSocialAuthenticationResponse(socialAuthenticationModel, false, true, null, null);
                }
            }
            catch (ThreadAbortException)
            {
            }
            catch (Exception ex)
            {
                var message = "Unable to verify your social account. Please try relogin to social network or continue registration manually. Error: " + ex.Message;

                HandleSocialAuthenticationResponse(null, false, false, null, message);
            }
        }
예제 #5
0
        private void HandleSocialAuthenticationResponse(SocialAuthenticationModel authenticationModel, Boolean isAuthenticated, Boolean canContinueRegistration, String redirectionUrl, String message)
        {
            if (SocialHelper.IsLinkedInCodeRedirect())
            {
                HandleLinkedInAuthenticationResponse(authenticationModel, isAuthenticated, canContinueRegistration, redirectionUrl, message);
            }
            else
            {
                if (isAuthenticated)
                {
                    FormsAuthentication.SetAuthCookie(authenticationModel.UserName, CreatePersistentCookie());
                }

                var result = new
                {
                    Result = isAuthenticated,
                    CanContinueRegistration = canContinueRegistration,
                    RedirectionUrl          = redirectionUrl,
                    Message = message
                };

                Helper.RespondWithJsonObject(result, Response);
            }
        }
예제 #6
0
        private ProfileCommon SaveProfile()
        {
            var result     = Profile;
            var email      = inputEmail.Value.Trim();
            var firstName  = inputFirstName.Value.Trim();
            var middleName = inputMiddleName.Value.Trim();
            var lastName   = inputLastName.Value.Trim();
            var avatarUrl  = String.Empty;

            if (GetCurrentMode() == ModesEnum.Mini)
            {
                var socialProfile = SocialHelper.CreateSocialProfileIfNeeded();

                if (socialProfile != null)
                {
                    var userModel = socialProfile.UserModel;

                    if (email.HasNoText() && userModel.Email.HasText())
                    {
                        email = userModel.Email;
                    }
                    if (firstName.HasNoText() && userModel.FirstName.HasText())
                    {
                        firstName = userModel.FirstName;
                    }
                    if (middleName.HasNoText() && userModel.MiddleName.HasText())
                    {
                        middleName = userModel.MiddleName;
                    }
                    if (lastName.HasNoText() && userModel.LastName.HasText())
                    {
                        lastName = userModel.LastName;
                    }
                    if (userModel.AvatarUrl.HasText())
                    {
                        avatarUrl = userModel.AvatarUrl;
                    }
                }
            }

            if (email.Length > 0)
            {
                result = Profile.GetProfile(email);
            }
            else
            {
                result = Profile.GetProfile(User.Identity.Name);
            }

            result.Association = Request.Form["association"];
            result.Brokerage.BrokerageState      = ddlBrokerageState.SelectedValue.Trim();
            result.BusinessAddress.BusinessState = ddlBusinessState.SelectedValue.Trim();
            result.Preferences.Newsletter        = ddlNewsletter.SelectedValue.Trim();
            result.Title = ddlTitle.SelectedValue.Trim();
            result.Brokerage.BrokerageAddress1      = inputBrokerageAddress1.Value.Trim();
            result.Brokerage.BrokerageAddress2      = inputBrokerageAddress2.Value.Trim();
            result.Brokerage.BrokerageCity          = inputBrokerageCity.Value.Trim();
            result.Brokerage.BrokerageName          = inputBrokerageName.Value.Trim();
            result.Brokerage.BrokerageZipcode       = inputBrokerageZipCode.Value.Trim();
            result.BusinessAddress.BusinessAddress1 = inputBusinessAddress1.Value.Trim();
            result.BusinessAddress.BusinessAddress2 = inputBusinessAddress2.Value.Trim();
            result.BusinessAddress.BusinessCity     = inputBusinessCity.Value.Trim();
            result.BusinessAddress.BusinessZipcode  = inputBusinessZipCode.Value.Trim();
            result.Contact.EmailSecondary           = inputSecondaryEmail.Value.Trim();
            result.Contact.Fax              = inputBusinessFax.Value.Trim();
            result.FirstName                = firstName;
            result.LastName                 = lastName;
            result.MiddleInitial            = middleName;
            result.Contact.PhoneBusiness    = inputBusinessPhone.Value.Trim();
            result.Contact.PhoneBusinessExt = inputBusinessPhoneExt.Value.Trim();
            result.Contact.PhoneCell        = inputCellPhone.Value.Trim();
            result.Contact.PhoneHome        = inputHomePhone.Value.Trim();
            result.ReferredBy               = ddlReferredSource.SelectedValue + "|" + inputReferredBy.Value.Trim();
            result.TeamName                 = inputTeamName.Value.Trim();
            result.Website  = inputWebsite.Value.Trim();
            result.DRE      = inputBre.Value.Trim();
            result.ImageURL = avatarUrl;

            result.Save();

            if (result.ImageURL.HasText())
            {
                SaveAvatar(result.ImageURL, result);
            }

            return(result);
        }
예제 #7
0
        private void Save()
        {
            try
            {
                ValidateOnSave();

                var email    = inputEmail.Value.Trim();
                var password = inputPassword.Value;

                if (GetCurrentMode() == ModesEnum.Mini)
                {
                    var socialProfile = SocialHelper.CreateSocialProfileIfNeeded();

                    if (email.HasNoText())
                    {
                        email = socialProfile.UserModel.Email;
                    }

                    if (password.HasNoText())
                    {
                        password = GeneratePassword();
                    }
                }

                var user    = Membership.CreateUser(email, password, email);
                var profile = SaveProfile();

                InsertSubscriber(profile);

                if (Membership.ValidateUser(user.UserName, user.GetPassword()))
                {
                    try
                    {
                        SendEmail(user, profile);
                    }
                    catch
                    {
                    }

                    if (Request.QueryString["ReturnUrl"] != null)
                    {
                        FormsAuthentication.RedirectFromLoginPage(user.Email, false);
                    }
                    else
                    {
                        FormsAuthentication.SetAuthCookie(user.Email, false);
                        Response.Redirect("~/createflyer.aspx");
                    }
                }
            }
            catch (MembershipCreateUserException ex)
            {
                divSummaryError.Visible = true;

                switch (ex.StatusCode)
                {
                case MembershipCreateStatus.DuplicateEmail:
                    ltlMessage.Text = "You have supplied a duplicate email address.";
                    break;

                case MembershipCreateStatus.DuplicateUserName:
                    ltlMessage.Text = "You have supplied a duplicate username.";
                    break;

                case MembershipCreateStatus.InvalidEmail:
                    ltlMessage.Text = "You have not supplied a proper email address.";
                    break;

                default:
                    ltlMessage.Text = "Error: " + ex.Message;
                    break;
                }
            }
            catch (Exception ex)
            {
                divSummaryError.Visible = true;
                ltlMessage.Text         = String.Format("Unhandled error: {0}", ex.Message);
            }
        }
예제 #8
0
        private void ValidateOnSave()
        {
            if (GetCurrentMode() == ModesEnum.Main || (GetCurrentMode() == ModesEnum.Mini && SocialHelper.CreateSocialProfileIfNeeded() == null))
            {
                if (inputEmail.Value.HasNoText())
                {
                    Helper.SetErrorResponse(HttpStatusCode.BadRequest, "Email is required.");
                }
                else if (String.Compare(inputEmail.Value, inputEmailConfirm.Value, true) != 0)
                {
                    Helper.SetErrorResponse(HttpStatusCode.BadRequest, "Emails do not match.");
                }
                else if (String.Compare(inputEmail.Value, inputEmailConfirm.Value, true) != 0)
                {
                    Helper.SetErrorResponse(HttpStatusCode.BadRequest, "Emails do not match.");
                }
                else if (inputPassword.Value.HasNoText())
                {
                    Helper.SetErrorResponse(HttpStatusCode.BadRequest, "Password is required.");
                }
                else if (inputConfirmPassword.Value.HasNoText())
                {
                    Helper.SetErrorResponse(HttpStatusCode.BadRequest, "Confirm Password is required.");
                }
                else if (String.Compare(inputPassword.Value, inputConfirmPassword.Value, false) != 0)
                {
                    Helper.SetErrorResponse(HttpStatusCode.BadRequest, "Passwords do not match.");
                }
                else if (inputFirstName.Value.HasNoText())
                {
                    Helper.SetErrorResponse(HttpStatusCode.BadRequest, "First Name is required.");
                }
                else if (inputLastName.Value.HasNoText())
                {
                    Helper.SetErrorResponse(HttpStatusCode.BadRequest, "Last Name is required.");
                }
            }
            else if (GetCurrentMode() == ModesEnum.Mini && SocialHelper.CreateSocialProfileIfNeeded() != null)
            {
                var socialProfile = SocialHelper.CreateSocialProfileIfNeeded();
                var userModel     = socialProfile.UserModel;

                if (userModel.FirstName.HasNoText() && inputFirstName.Value.HasNoText())
                {
                    Helper.SetErrorResponse(HttpStatusCode.BadRequest, "First Name is required.");
                }
                else if (userModel.LastName.HasNoText() && inputLastName.Value.HasNoText())
                {
                    Helper.SetErrorResponse(HttpStatusCode.BadRequest, "Last Name is required.");
                }
            }

            if (ddlTitle.SelectedValue.HasNoText())
            {
                Helper.SetErrorResponse(HttpStatusCode.BadRequest, "Select Title.");
            }
            else if (ddlTitle.Items.FindByValue(ddlTitle.SelectedValue) == null)
            {
                Helper.SetErrorResponse(HttpStatusCode.BadRequest, "Provide valid Title.");
            }
            else if (inputBusinessAddress1.Value.HasNoText())
            {
                Helper.SetErrorResponse(HttpStatusCode.BadRequest, "Business Address 1 is required.");
            }
            else if (inputBusinessCity.Value.HasNoText())
            {
                Helper.SetErrorResponse(HttpStatusCode.BadRequest, "Business City is required.");
            }
            else if (ddlBusinessState.SelectedValue.HasNoText())
            {
                Helper.SetErrorResponse(HttpStatusCode.BadRequest, "Select your Business State.");
            }
            else if (ddlBusinessState.Items.FindByValue(ddlBusinessState.SelectedValue) == null)
            {
                Helper.SetErrorResponse(HttpStatusCode.BadRequest, "Provide valid Business State.");
            }
            else if (inputBusinessZipCode.Value.HasNoText())
            {
                Helper.SetErrorResponse(HttpStatusCode.BadRequest, "Business Zip Code is required.");
            }
            else if (inputBusinessPhone.Value.HasNoText())
            {
                Helper.SetErrorResponse(HttpStatusCode.BadRequest, "Business Phone is required.");
            }
            else if (inputBrokerageName.Value.HasNoText())
            {
                Helper.SetErrorResponse(HttpStatusCode.BadRequest, "Brokerage Name is required.");
            }
            else if (inputBrokerageAddress1.Value.HasNoText())
            {
                Helper.SetErrorResponse(HttpStatusCode.BadRequest, "Brokerage Address 1 is required.");
            }
            else if (inputBrokerageCity.Value.HasNoText())
            {
                Helper.SetErrorResponse(HttpStatusCode.BadRequest, "Brokerage City is required.");
            }
            else if (ddlBusinessState.SelectedValue.HasNoText())
            {
                Helper.SetErrorResponse(HttpStatusCode.BadRequest, "Select Brokerage State.");
            }
            else if (ddlBusinessState.Items.FindByValue(ddlBusinessState.SelectedValue) == null)
            {
                Helper.SetErrorResponse(HttpStatusCode.BadRequest, "Provide valid Brokerage State.");
            }
            else if (inputBrokerageZipCode.Value.HasNoText())
            {
                Helper.SetErrorResponse(HttpStatusCode.BadRequest, "Zip Code is required.");
            }
            else if (!cbTerm.Checked)
            {
                Helper.SetErrorResponse(HttpStatusCode.BadRequest, "Accept Terms and Conditions.");
            }
        }
예제 #9
0
 private Boolean CanAuthenticate()
 {
     return(Request.IsPost() || SocialHelper.IsLinkedInCodeRedirect());
 }