public async Task <IActionResult> PostAccountSignupAsync([FromBody] UserForRegistrationUiModel managedUserVm)
        {
            try
            {
                if (await _inquiryUserProcessor.SearchIfAnyPersonByEmailOrUsernameExistsAsync(managedUserVm.Email, managedUserVm.Username))
                {
                    Log.Error(
                        $"--Method:PostAccountSignupAsync -- Message:USER_SIGNUP_USERNAME_OR_EMAIL_ALREADY_EXIST-- Datetime:{DateTime.Now} " +
                        $"-- UserInfo: Email : {managedUserVm.Email}, Username : {managedUserVm.Username}");
                    return(BadRequest(new { errorMessage = "USERNAME_OR_EMAIL_ALREADY_EXISTS" }));
                }

                var registerResponse = await _createUserProcessor.CreateUserAsync(managedUserVm);

                switch (registerResponse.Message)
                {
                case ("SUCCESS_CREATION"):
                {
                    Log.Information(
                        $"--Method:PostAccountRegisterAsync -- Message:USER_REGISTERED_SUCCESSFULLY -- Datetime:{DateTime.UtcNow} -- UserInfo:{managedUserVm.Username}");
                    return(Created("/signup", new
                        {
                            id = registerResponse.Id,
                            username = registerResponse.Username,
                            email = registerResponse.Email,
                            address = registerResponse.Address,
                            displayname = registerResponse.DisplayName,
                            status = "CORRECT_USER_SIGNUP"
                        }));
                }

                case ("ERROR_USER_ALREADY_EXISTS"):
                {
                    Log.Error(
                        $"--Method:PostAccountRegisterAsync -- Message:ERROR_USER_ALREADY_EXISTS -- Datetime:{DateTime.UtcNow} -- UserInfo:{managedUserVm.Username}");
                    return(BadRequest(new { errorMessage = "USERNAME_OR_EMAIL_ALREADY_EXISTS" }));
                }

                case ("ERROR_USER_NOT_MADE_PERSISTENT"):
                {
                    Log.Error(
                        $"--Method:PostAccountRegisterAsync -- Message:ERROR_USER_NOT_MADE_PERSISTENT -- Datetime:{DateTime.UtcNow} -- UserInfo:{managedUserVm.Username}");
                    return(BadRequest(new { errorMessage = "ERROR_REGISTER_NEW_USER" }));
                }

                case ("UNKNOWN_ERROR"):
                {
                    Log.Error(
                        $"--Method:PostAccountRegisterAsync -- Message:ERROR_REGISTER_NEW_USER -- Datetime:{DateTime.UtcNow} -- UserInfo:{managedUserVm.Username}");
                    return(BadRequest(new { errorMessage = "ERROR_REGISTER_NEW_USER" }));
                }
                }
            }
            catch (Exception e)
            {
                return(BadRequest(new { errorMessage = e.Message }));
            }

            return(Ok());
        }
Esempio n. 2
0
 public virtual void InjectWithInitialAttributes(UserForRegistrationUiModel newUserForRegistration)
 {
     this.Login         = newUserForRegistration.Login;
     this.PasswordHash  = HashHelper.Sha512(newUserForRegistration.Password + newUserForRegistration.Login);
     this.IsActivated   = false;
     this.ResetDate     = DateTime.UtcNow;
     this.CreatedDate   = DateTime.UtcNow;
     this.ModifiedDate  = DateTime.UtcNow;
     this.ResetKey      = Guid.NewGuid();
     this.ActivationKey = Guid.NewGuid();
 }
Esempio n. 3
0
        public Task <UserUiModel> CreateUserAsync(Guid accountIdToCreateThisUser,
                                                  UserForRegistrationUiModel newUserForRegistration)
        {
            var response =
                new UserUiModel()
            {
                Message = "START_CREATION"
            };

            if (newUserForRegistration == null)
            {
                response.Message = "ERROR_INVALID_USER_MODEL";
                return(Task.Run(() => response));
            }

            try
            {
                var userToBeCreated = new User();
                userToBeCreated.InjectWithInitialAttributes(newUserForRegistration);
                userToBeCreated.InjectWithAuditCreation(accountIdToCreateThisUser);

                var roleToBeInjected = _roleRepository.FindBy(newUserForRegistration.UserRoleId);

                if (roleToBeInjected == null)
                {
                    throw new RoleDoesNotExistException(newUserForRegistration.UserRoleId);
                }

                var userRoleToBeInjected = new UserRole();

                userRoleToBeInjected.InjectWithRole(roleToBeInjected);
                userRoleToBeInjected.InjectWithAuditCreation(accountIdToCreateThisUser);
                var customerToBeInjected = new Customer()
                {
                    Firstname = newUserForRegistration.Firstname,
                    Lastname  = newUserForRegistration.Lastname,
                    Phone     = newUserForRegistration.Phone,
                    Notes     = newUserForRegistration.Notes,
                    Address   = new Address()
                    {
                        StreetOne = newUserForRegistration.AddressStreetOne,
                        StreetTwo = newUserForRegistration.AddressStreetTwo,
                        PostCode  = newUserForRegistration.AddressPostCode,
                        City      = newUserForRegistration.AddressCity,
                        Region    = newUserForRegistration.AddressRegion,
                    },
                    Email = newUserForRegistration.Login,
                };

                customerToBeInjected.InjectWithAuditCreation(accountIdToCreateThisUser);

                userToBeCreated.InjectWithCustomer(customerToBeInjected);
                userToBeCreated.InjectWithUserRole(userRoleToBeInjected);

                ThrowExcIfUserCannotBeCreated(userToBeCreated);
                ThrowExcIfThisUserAlreadyExist(userToBeCreated);

                Log.Debug(
                    $"Create User: {newUserForRegistration.Login}" +
                    "--CreateUser--  @NotComplete@ [CreateUserProcessor]. " +
                    "Message: Just Before MakeItPersistence");

                MakeUserPersistent(userToBeCreated);

                Log.Debug(
                    $"Create User: {newUserForRegistration.Login}" +
                    "--CreateUser--  @NotComplete@ [CreateUserProcessor]. " +
                    "Message: Just After MakeItPersistence");
                response         = ThrowExcIfUserWasNotBeMadePersistent(userToBeCreated);
                response.Message = "SUCCESS_CREATION";
            }
            catch (RoleDoesNotExistException r)
            {
                response.Message = "ERROR_INVALID_ROLE_NAME";
                Log.Error(
                    $"Create User: {newUserForRegistration.Login}" +
                    $"Error Message:{response.Message}" +
                    "--CreateUser--  @NotComplete@ [CreateUserProcessor]");
            }
            catch (InvalidUserException e)
            {
                response.Message = "ERROR_INVALID_USER_MODEL";
                Log.Error(
                    $"Create User: {newUserForRegistration.Login}" +
                    $"Error Message:{response.Message}" +
                    "--CreateUser--  @NotComplete@ [CreateUserProcessor]. " +
                    $"Broken rules: {e.BrokenRules}");
            }
            catch (UserEmailOrLoginAlreadyExistsException ex)
            {
                response.Message = "ERROR_USER_ALREADY_EXISTS";
                Log.Error(
                    $"Create User: {newUserForRegistration.Login}" +
                    $"Error Message:{response.Message}" +
                    "--CreateUser--  @fail@ [CreateUserProcessor]. " +
                    $"@inner-fault:{ex?.Message} and {ex?.InnerException}");
            }
            catch (UserDoesNotExistAfterMadePersistentException exx)
            {
                response.Message = "ERROR_USER_NOT_MADE_PERSISTENT";
                Log.Error(
                    $"Create User: {newUserForRegistration.Login}" +
                    $"Error Message:{response.Message}" +
                    "--CreateUser--  @fail@ [CreateUserProcessor]." +
                    $" @inner-fault:{exx?.Message} and {exx?.InnerException}");
            }
            catch (Exception exxx)
            {
                response.Message = "UNKNOWN_ERROR";
                Log.Error(
                    $"Create User: {newUserForRegistration.Login}" +
                    $"Error Message:{response.Message}" +
                    $"--CreateUser--  @fail@ [CreateUserProcessor]. " +
                    $"@inner-fault:{exxx.Message} and {exxx.InnerException}");
            }

            return(Task.Run(() => response));
        }
Esempio n. 4
0
        public Task <UserUiModel> CreateUserAsync(UserForRegistrationUiModel newUserForRegistration)
        {
            var response =
                new UserUiModel()
            {
                Message = "START_CREATION"
            };

            if (newUserForRegistration == null)
            {
                response.Message = "ERROR_INVALID_USER_MODEL";
                return(Task.Run(() => response));
            }

            try
            {
                var userToBeCreated = new User();
                userToBeCreated.InjectWithInitialAttributes(newUserForRegistration.Displayname,
                                                            newUserForRegistration.Username, newUserForRegistration.Email, newUserForRegistration.Password, newUserForRegistration.Address);

                ThrowExcIfUserCannotBeCreated(userToBeCreated);
                ThrowExcIfThisUserAlreadyExist(userToBeCreated);

                Log.Debug(
                    $"Create User: {newUserForRegistration.Username}" +
                    "--CreateUser--  @NotComplete@ [CreateUserProcessor]. " +
                    "Message: Just Before MakeItPersistence");

                MakeUserPersistent(userToBeCreated);

                Log.Debug(
                    $"Create User: {newUserForRegistration.Username}" +
                    "--CreateUser--  @NotComplete@ [CreateUserProcessor]. " +
                    "Message: Just After MakeItPersistence");

                response         = ThrowExcIfUserWasNotBeMadePersistent(userToBeCreated);
                response.Message = "SUCCESS_CREATION";
            }
            catch (InvalidUserException e)
            {
                response.Message = "ERROR_INVALID_USER_MODEL";
                Log.Error(
                    $"Create User: {newUserForRegistration.Username}" +
                    $"Error Message:{response.Message}" +
                    "--CreateUser--  @NotComplete@ [CreateUserProcessor]. " +
                    $"Broken rules: {e.BrokenRules}");
            }
            catch (UserEmailOrLoginAlreadyExistsException ex)
            {
                response.Message = "ERROR_USER_ALREADY_EXISTS";
                Log.Error(
                    $"Create User: {newUserForRegistration.Username}" +
                    $"Error Message:{response.Message}" +
                    "--CreateUser--  @fail@ [CreateUserProcessor]. " +
                    $"@inner-fault:{ex?.Message} and {ex?.InnerException}");
            }
            catch (UserDoesNotExistAfterMadePersistentException exx)
            {
                response.Message = "ERROR_USER_NOT_MADE_PERSISTENT";
                Log.Error(
                    $"Create User: {newUserForRegistration.Username}" +
                    $"Error Message:{response.Message}" +
                    "--CreateUser--  @fail@ [CreateUserProcessor]." +
                    $" @inner-fault:{exx?.Message} and {exx?.InnerException}");
            }
            catch (Exception exxx)
            {
                response.Message = "UNKNOWN_ERROR";
                Log.Error(
                    $"Create User: {newUserForRegistration.Username}" +
                    $"Error Message:{response.Message}" +
                    $"--CreateUser--  @fail@ [CreateUserProcessor]. " +
                    $"@inner-fault:{exxx.Message} and {exxx.InnerException}");
            }

            return(Task.Run(() => response));
        }
Esempio n. 5
0
        public async Task <IActionResult> PostAccountRegisterAsync([FromBody] UserForRegistrationUiModel managedUserVm)
        {
            try
            {
                var userAudit = await _inquiryUserProcessor.GetUserByLoginAsync(GetEmailFromClaims());

                if (userAudit == null)
                {
                    return(BadRequest());
                }

                if (await _inquiryPersonProcessor.SearchIfAnyPersonByEmailOrLoginExistsAsync(managedUserVm.Login))
                {
                    Log.Error(
                        $"--Method:PostAccountRegisterAsync -- Message:USER_REGISTERED_LOGIN_OR_EMAIL_ALREADY_EXIST-- Datetime:{DateTime.Now} " +
                        $"-- UserInfo:{managedUserVm.Login}, ");
                    return(BadRequest(new { errorMessage = "USERNAME_OR_EMAIL_ALREADY_EXISTS" }));
                }

                var registerResponse = await _createUserProcessor.CreateUserAsync(userAudit.Id, managedUserVm);

                switch (registerResponse.Message)
                {
                case ("SUCCESS_CREATION"):
                {
                    Log.Information(
                        $"--Method:PostAccountRegisterAsync -- Message:USER_REGISTERED_SUCCESSFULLY -- Datetime:{DateTime.UtcNow} -- UserInfo:{managedUserVm.Login}");
                    return(Created("/register", new
                        {
                            id = registerResponse.Id,
                            username = managedUserVm.Login,
                            email = managedUserVm.Login,
                            isActivated = false,
                            status = "user created - An activation code was created - Needs Activation"
                        }));
                }

                case ("ERROR_USER_ALREADY_EXISTS"):
                {
                    Log.Error(
                        $"--Method:PostAccountRegisterAsync -- Message:ERROR_USER_ALREADY_EXISTS -- Datetime:{DateTime.UtcNow} -- UserInfo:{managedUserVm.Login}");
                    return(BadRequest(new { errorMessage = "USERNAME_OR_EMAIL_ALREADY_EXISTS" }));
                }

                case ("ERROR_USER_NOT_MADE_PERSISTENT"):
                {
                    Log.Error(
                        $"--Method:PostAccountRegisterAsync -- Message:ERROR_USER_NOT_MADE_PERSISTENT -- Datetime:{DateTime.UtcNow} -- UserInfo:{managedUserVm.Login}");
                    return(BadRequest(new { errorMessage = "ERROR_REGISTER_NEW_USER" }));
                }

                case ("UNKNOWN_ERROR"):
                {
                    Log.Error(
                        $"--Method:PostAccountRegisterAsync -- Message:ERROR_REGISTER_NEW_USER -- Datetime:{DateTime.UtcNow} -- UserInfo:{managedUserVm.Login}");
                    return(BadRequest(new { errorMessage = "ERROR_REGISTER_NEW_USER" }));
                }
                }
            }
            catch (Exception e)
            {
                return(BadRequest(new { errorMessage = e.Message }));
            }

            return(Ok());
        }