Beispiel #1
0
        public async Task <IdentityResult> Register(AccountRegister accountRegister)
        {
            var user = new User
            {
                FirstName = accountRegister.FirstName,
                LastName  = accountRegister.LastName,
                Email     = accountRegister.Email,
                UserName  = accountRegister.UserName
            };

            var result = await _identityManager.Create(user, accountRegister.Password);

            if (!result.Succeeded)
            {
                return(result);
            }

            await _identityManager.SignIn(user.UserName);

            user = await _identityProvider.GetByUserName(user.UserName);

            await SendEmailConfirmation(user.AspNetUserId);

            return(result);
        }
        public async Task <OperationDetails> CreateUserAsync(RegistrationUserDTO userDTO)
        {
            if (!userDTO.IsValid())
            {
                return(userDTO.GetValidateError());
            }
            var dbUser = await dataStore.UserProfiles.GetByNameAsync(userDTO.UserName);

            if (dbUser != null)
            {
                return(new OperationDetails(false, new string[] { "This username used yet." }));
            }
            var applicationUser = userDTO.GetApplicationUser();
            var result          = await userManager.Create(applicationUser, userDTO.Password);

            if (!result.IsSuccess)
            {
                return(new OperationDetails(false, result.ErrorList.Select(x => x.Description)));
            }
            var userProfile = userDTO.GetUserProfile();

            userProfile.IdentityUserId = (await userManager.GetUserByEmailAsync(applicationUser.Email)).Id;
            var createdProfile = await dataStore.UserProfiles.CreateAsync(userProfile);

            if (createdProfile == null)
            {
                var errorUser = await userManager.GetUserByEmailAsync(applicationUser.Username);

                var res = await userManager.DeleteUserAsync(errorUser);

                return(new OperationDetails(false, new string[] { "Some error, try another data." }));
            }
            return(new OperationDetails(true));
        }