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);
        }
Example #2
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);
            }
        }
        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);
        }
Example #4
0
        public async Task <UserResponseDto> SaveUser(UserRequestDto userRequest)
        {
            var password       = _passwordGeneratorService.Generate(8);
            var hashedPassword = _hashingService.HashPassword(password);
            var user           = _mapper.Map <User>((hashedPassword, userRequest));

            var savedUser = await _userRepository.SaveUser(user);

            var userResponse = _mapper.Map <UserResponseDto>(savedUser);

            try
            {
                _smtpService.SendEmail(password, userResponse);
            }
            catch
            {
                await _userRepository.DeleteUser(userResponse.Id);

                throw;
            }

            return(userResponse);
        }
        public void PasswordGeneratorService_Generate_ShouldEqualToLength()
        {
            var generatedPassword = _sut.Generate(_length);

            Assert.Equal(_length, generatedPassword.Count());
        }
Example #6
0
 public IActionResult Generate([FromQuery] int lenght = 12)
 {
     return(Ok(_passwordGeneratorService.Generate(lenght)));
 }