/// <summary>
        /// Create user from the LinkedIn profile data.
        /// </summary>
        /// <param name="accessToken"></param>
        /// <returns></returns>
        private bool CreateUserFromLinkedInProfileData(string accessToken)
        {
            // get the email address from the profile
            var emailAddress = LinkedInHelper.GetProfileEmailAddress(accessToken);

            if (string.IsNullOrEmpty(emailAddress))
            {
                Log.Write("LinkedIn: Email address not present in the response.");

                return(false);
            }

            // if an account already exist then authenticate
            var existingUser = SitefinityHelper.GetUserByEmail(emailAddress);

            if (existingUser != null)
            {
                if (!AuthenticateUser(emailAddress))
                {
                    Log.Write("LinkedIn: Unable to authenticate user using the email address.");

                    return(false);
                }

                return(true);
            }

            // at this point create a new account

            var profile = LinkedInHelper.GetProfile(accessToken);

            var membershipCreateStatus = SitefinityHelper.CreateUser(
                emailAddress,
                System.Web.Security.Membership.GeneratePassword(12, 2),
                profile.FirstName,
                profile.LastName,
                emailAddress,
                null,
                null,
                null,
                true,
                true
                );

            if (membershipCreateStatus != MembershipCreateStatus.Success)
            {
                Log.Write("LinkedIn: Unable to create user account.");

                return(false);
            }

            if (!AuthenticateUser(emailAddress))
            {
                Log.Write("LinkedIn: Unable to authenticate user using the email address after registration.");

                return(false);
            }

            return(true);
        }
Exemple #2
0
        public string GetOverrideEmail(ref JobApplicationStatus status, ref ApplicantInfo applicantInfo, bool isSocialMedia = false)
        {
            string ovverideEmail = null;

            if (SitefinityHelper.IsUserLoggedIn()) // User already logged in
            {
                var currUser = SitefinityHelper.GetUserById(ClaimsManager.GetCurrentIdentity().UserId);
                if (currUser != null)
                {
                    Log.Write("User is already logged In " + currUser.Email, ConfigurationPolicy.ErrorLog);
                    return(currUser.Email);
                }
            }

            // User not looged in
            if (!string.IsNullOrEmpty(applicantInfo.Email))
            {
                Telerik.Sitefinity.Security.Model.User existingUser = SitefinityHelper.GetUserByEmail(applicantInfo.Email);

                if (existingUser != null)
                {
                    #region Entered Email exists in Sitefinity User list
                    Log.Write("User is already exists in portal " + existingUser.Email, ConfigurationPolicy.ErrorLog);
                    ovverideEmail = existingUser.Email;
                    // check user exists in the JXT next DB
                    var memberResponse = _blConnector.GetMemberByEmail(applicantInfo.Email);
                    if (memberResponse.Member == null)
                    {
                        UserProfileManager userProfileManager = UserProfileManager.GetManager();
                        UserProfile        profile            = userProfileManager.GetUserProfile(existingUser.Id, typeof(SitefinityProfile).FullName);
                        var fName = Telerik.Sitefinity.Model.DataExtensions.GetValue(profile, "FirstName");
                        var lName = Telerik.Sitefinity.Model.DataExtensions.GetValue(profile, "LastName");
                        JXTNext_MemberRegister memberReg = new JXTNext_MemberRegister
                        {
                            Email     = existingUser.Email,
                            FirstName = fName.ToString(),
                            LastName  = lName.ToString(),
                            Password  = existingUser.Password
                        };

                        if (_blConnector.MemberRegister(memberReg, out string errorMessage))
                        {
                            Log.Write("User created JXT next DB" + existingUser.Email, ConfigurationPolicy.ErrorLog);
                        }
                    }
                    return(ovverideEmail);

                    #endregion
                }
                else
                {
                    #region Entered email does not exists in sitefinity User list
                    var membershipCreateStatus = SitefinityHelper.CreateUser(applicantInfo.Email, applicantInfo.Password, applicantInfo.FirstName, applicantInfo.LastName, applicantInfo.Email, applicantInfo.PhoneNumber,
                                                                             null, null, true, true);
                    applicantInfo.IsNewUser = true;
                    if (membershipCreateStatus != MembershipCreateStatus.Success)
                    {
                        Log.Write("User is created in portal " + existingUser.Email, ConfigurationPolicy.ErrorLog);
                        status = JobApplicationStatus.NotAbleToCreateUser;
                        return(ovverideEmail);
                    }
                    else
                    {
                        //instantiate the Sitefinity user manager
                        //if you have multiple providers you have to pass the provider name as parameter in GetManager("ProviderName") in your case it will be the asp.net membership provider user
                        UserManager userManager = UserManager.GetManager();
                        if (userManager.ValidateUser(applicantInfo.Email, applicantInfo.Password))
                        {
                            //if you need to get the user instance use the out parameter
                            Telerik.Sitefinity.Security.Model.User userToAuthenticate = null;
                            SecurityManager.AuthenticateUser(userManager.Provider.Name, applicantInfo.Email, applicantInfo.Password, false, out userToAuthenticate);
                            if (userToAuthenticate == null)
                            {
                                status = JobApplicationStatus.NotAbleToLoginCreatedUser;
                                return(ovverideEmail);
                            }
                            else
                            {
                                ovverideEmail = userToAuthenticate.Email;
                            }
                        }
                    }
                    #endregion
                }
            }

            return(ovverideEmail);
        }