Beispiel #1
0
        public IUser CreateUser(OpenAuthCreateUserParams createUserParams)
        {
            string emailAddress = string.Empty;

            if (createUserParams.UserName.IsEmailAddress())
            {
                emailAddress = createUserParams.UserName;
            }
            else
            {
                foreach (var key in createUserParams.ExtraData.Keys)
                {
                    switch (key.ToLower())
                    {
                    case "mail":
                    case "email":
                    case "e-mail":
                    case "email-address":
                        emailAddress = createUserParams.ExtraData[key];
                        break;
                    }
                }
            }

            createUserParams.UserName = _usernameService.Normalize(createUserParams.UserName);
            var creatingContext = new CreatingOpenAuthUserContext(
                createUserParams.UserName, emailAddress,
                createUserParams.ProviderName, createUserParams.ProviderUserId, createUserParams.ExtraData);

            _openAuthUserEventHandlers.Invoke(o => o.Creating(creatingContext), Logger);

            // check UserName
            if (String.IsNullOrEmpty(createUserParams.UserName))
            {
                return(null);
            }
            else
            {
                // The default IMemebershipService from Orchard.Users fires the following user events:
                // Creating, Created, and Approved (see the last parameter of the CreateUserParams)
                var createdUser = _membershipService.CreateUser(new CreateUserParams(
                                                                    _usernameService.Calculate(createUserParams.UserName), // this tries to make a unique username by adding a number to its end
                                                                    _passwordGeneratorService.Generate(),
                                                                    creatingContext.EmailAddress,
                                                                    @T("Auto Registered User").Text,
                                                                    _passwordGeneratorService.Generate() /* Noone can guess this */,
                                                                    true,
                                                                    false
                                                                    ));

                // _membershipService.CreateUser may fail and return null
                if (createdUser != null)
                {
                    var createdContext = new CreatedOpenAuthUserContext(createdUser,
                                                                        createUserParams.ProviderName, createUserParams.ProviderUserId, createUserParams.ExtraData);
                    _openAuthUserEventHandlers.Invoke(o => o.Created(createdContext), Logger);
                }
                return(createdUser);
            }
        }
        public IUser CreateUser(OpenAuthCreateUserParams createUserParams)
        {
            string emailAddress = string.Empty;

            if (createUserParams.UserName.IsEmailAddress())
            {
                emailAddress = createUserParams.UserName;
            }

            var creatingContext = new CreatingOpenAuthUserContext(createUserParams.UserName, emailAddress, createUserParams.ProviderName, createUserParams.ProviderUserId, createUserParams.ExtraData);

            _openAuthUserEventHandlers.Invoke(o => o.Creating(creatingContext), Logger);

            var createdUser = _membershipService.CreateUser(new CreateUserParams(
                                                                _usernameService.Calculate(createUserParams.UserName),
                                                                _passwordGeneratorService.Generate(),
                                                                creatingContext.EmailAddress,
                                                                @T("Auto Registered User").Text,
                                                                _passwordGeneratorService.Generate() /* Noone can guess this */,
                                                                true
                                                                ));

            var createdContext = new CreatedOpenAuthUserContext(createdUser, createUserParams.ProviderName, createUserParams.ProviderUserId, createUserParams.ExtraData);

            _openAuthUserEventHandlers.Invoke(o => o.Created(createdContext), Logger);

            return(createdUser);
        }
        private IUser CreateUser(UserDetailOutput userDetail, Guid token)
        {
            var personDetail = this.organizationUnitClient.Value.PersonDetail(new PersonDetailInput
            {
                ID       = userDetail.ID_Person.Value,
                ID_Login = token
            });

            string uniqueUserName = usernameService.Calculate(userDetail.UserName);

            var newUser = this.membershipService.CreateUser(new CreateUserParams(
                                                                uniqueUserName,
                                                                passwordGeneratorService.Generate(),
                                                                personDetail.Email,
                                                                T("Auto Registered User").Text,
                                                                passwordGeneratorService.Generate(),
                                                                true));

            var userPart = newUser.As <SkautIsUserPart>();

            userPart.SkautIsUserId = userDetail.ID.Value;
            userPart.PersonId      = personDetail.ID.Value;

            return(newUser);
        }