public override void AddUserToRole(Telerik.Sitefinity.Security.Model.User user, Telerik.Sitefinity.Security.Model.Role role)
        {
            var link = this.CreateUserLink();

            link.UserId = user.Id;

            link.MembershipManagerInfo = this.UserManagerInfo;

            var scope = this.GetContext();

            Telerik.Sitefinity.Security.Model.Role existingRole = null;

            // Try get existing role - if a user is already added in this role, the role will exist in context of Sitefinity
            // When first time assigning the role this will throw exception - Item you are trying to access, no longer exists.
            try
            {
                existingRole = scope.GetItemById <Telerik.Sitefinity.Security.Model.Role>(role.Id.ToString());
            }
            catch (Exception ex)
            {
            }

            if (existingRole != null)
            {
                link.Role = existingRole;
            }
            else
            {
                link.Role = role;
            }

            scope.Add(link);
        }
        /// <summary>
        /// Authenticate a user by email address.
        /// </summary>
        /// <param name="emailAddress"></param>
        /// <returns></returns>
        private bool AuthenticateUser(string emailAddress)
        {
            // check user exist in the JXT Next database
            Telerik.Sitefinity.Security.Model.User existingUser = SitefinityHelper.GetUserByEmail(emailAddress);
            var memberResponse = _blConnector.GetMemberByEmail(emailAddress);

            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     = emailAddress,
                    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);
                }
            }
            // end of the code for the user check in the JXT Next DB
            var userManager = UserManager.GetManager();

            SecurityManager.AuthenticateUser(userManager.Provider.Name, emailAddress, false, out User user);

            return(user != null);
        }
        public override MembershipCreateStatus RegisterUser(RegistrationViewModel viewModel)
        {
            var userManager = UserManager.GetManager(this.MembershipProviderName);

            Telerik.Sitefinity.Security.Model.User user;
            MembershipCreateStatus status;

            using (new ElevatedModeRegion(userManager))
            {
                if (this.TryCreateUser(userManager, viewModel, out user, out status))
                {
                    userManager.SaveChanges();

                    this.CreateUserProfiles(user, viewModel.Profile);

                    this.AssignRolesToUser(user);

                    this.ConfirmRegistration(userManager, user);
                    //this.ExecuteUserProfileSuccessfullUpdateActions();
                }

                if (status == MembershipCreateStatus.DuplicateUserName)
                {
                    IEnumerable <IJobListingMapper> jobListingMappers = new List <IJobListingMapper> {
                        new JXTNext_JobListingMapper()
                    };
                    IEnumerable <IMemberMapper> memberMappers = new List <IMemberMapper> {
                        new JXTNext_MemberMapper()
                    };
                    IRequestSession requestSession = new SFEventRequestSession {
                        UserEmail = viewModel.Email
                    };

                    IBusinessLogicsConnector blConnector = new JXTNextBusinessLogicsConnector(jobListingMappers, memberMappers, requestSession);
                    var res = blConnector.GetMemberByEmail(viewModel.Email);
                    if (res.Member == null)
                    {
                        Telerik.Sitefinity.Security.Model.User existingUser = JXTNext.Sitefinity.Common.Helpers.SitefinityHelper.GetUserByEmail(viewModel.Email);
                        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
                        };

                        blConnector.MemberRegister(memberReg, out string errorMessage);
                    }
                }
            }

            return(status);
        }
        public static string GetAvatar(this Telerik.Sitefinity.Security.Model.User user, string defaultImageUrl = "")
        {
            Image image;

            UserProfilesHelper.GetAvatarImageUrl(user.Id, out image);

            if (image != null)
            {
                return(image.Url);
            }
            else
            {
                return((String.IsNullOrEmpty(defaultImageUrl)) ? "/SFRes/images/Telerik.Sitefinity.Resources/Images.DefaultPhoto.png" : defaultImageUrl);
            }
        }
        public void ProfileCreated(ProfileCreated eventinfo)
        {
            UserManager userManager = UserManager.GetManager();

            Telerik.Sitefinity.Security.Model.User user = userManager.GetUser(eventinfo.UserId);

            UserProfileManager userProfileManager = UserProfileManager.GetManager();
            SitefinityProfile  profile            = userProfileManager.GetUserProfile(user, eventinfo.ProfileType) as SitefinityProfile;

            // user.ExternalProviderName is null means registrating through normal registration
            // Otherwise registring through External provider like LinkedIn, Facebook, etc...
            // In case external provider, we will recieve the password as null but JXTNext Member database table requires
            // password should not be empty, so generating some random password of 8 characters length.
            JXTNext_MemberRegister memberReg = new JXTNext_MemberRegister
            {
                Email     = user.Email,
                FirstName = profile.FirstName,
                LastName  = profile.LastName,
                Password  = user.ExternalProviderName.IsNullOrEmpty() ? user.Password : GeneralHelper.GeneratePassword(8)
            };

            IEnumerable <IJobListingMapper> jobListingMappers = new List <IJobListingMapper> {
                new JXTNext_JobListingMapper()
            };
            IEnumerable <IMemberMapper> memberMappers = new List <IMemberMapper> {
                new JXTNext_MemberMapper()
            };
            IRequestSession requestSession = new SFEventRequestSession {
                UserEmail = user.Email
            };

            IBusinessLogicsConnector connector = new JXTNextBusinessLogicsConnector(jobListingMappers, memberMappers, requestSession);
            bool registerSuccess = connector.MemberRegister(memberReg, out string errorMessage);

            if (!registerSuccess)
            {
                //eventinfo.IsApproved = false;
            }
        }
示例#6
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);
        }
示例#7
0
 public override void Delete(Telerik.Sitefinity.Security.Model.User item)
 {
 }