Пример #1
0
        public async Task <TaskData <UserRegistrationModel, UserRegistrationContext> > Execute(TaskData <UserRegistrationModel, UserRegistrationContext> taskData)
        {
            taskData.Context.RegistrationEmailAddress = taskData.Data.UserRegistrationDetails.EmailAddress;

            if (taskData.Data.UserRegistrationDetails.Password != taskData.Data.UserRegistrationDetails.ConfirmPassword)
            {
                taskData.Context.UpdatedAt = DateTime.UtcNow;
                taskData.Context.UserWithEmailAddressAlreadyExists = true;
                taskData.Context.VerificationEmailSent             = false;
                return(taskData);
            }

            var registerUserResult = await _authDbService.RegisterUser(new RegisterUser
            {
                EmailAddress    = taskData.Data.UserRegistrationDetails.EmailAddress,
                Password        = taskData.Data.UserRegistrationDetails.Password,
                ConfirmPassword = taskData.Data.UserRegistrationDetails.ConfirmPassword
            });

            if (registerUserResult.UserCreated)
            {
                try
                {
                    await _emailTemplates.BuildAndSendValidateEmail(
                        registerUserResult.EmailAddress,
                        registerUserResult.UserId.ToString(),
                        registerUserResult.ValidationToken.ToString());

                    taskData.Context.UpdatedAt             = DateTime.UtcNow;
                    taskData.Context.VerificationEmailSent = true;
                    return(taskData);
                }
                catch
                {
                    taskData.Context.UpdatedAt             = DateTime.UtcNow;
                    taskData.Context.VerificationEmailSent = false;
                    return(taskData);
                }
            }
            else
            {
                taskData.Context.UpdatedAt = DateTime.UtcNow;
                taskData.Context.UserWithEmailAddressAlreadyExists = true;
                taskData.Context.VerificationEmailSent             = false;
                return(taskData);
            }
        }
Пример #2
0
        public async Task <IActionResult> Register([FromBody] RegisterUser registerUser)
        {
            if (registerUser.Password != registerUser.ConfirmPassword)
            {
                return(BadRequest(new { message = "Passwords do not match." }));
            }

            var registerUserResult = await _authDbService.RegisterUser(registerUser);

            if (registerUserResult.UserCreated)
            {
                await _emailTemplates.BuildAndSendValidateEmail(
                    registerUserResult.EmailAddress,
                    registerUserResult.UserId.ToString(),
                    registerUserResult.ValidationToken.ToString());

                return(Ok());
            }
            else
            {
                return(BadRequest(new { message = registerUserResult.Reason }));
            }
        }