Ejemplo n.º 1
0
        public async Task <SignupResponseDto> Signup([FromBody] SignupRequestDto model)
        {
            var errors = await _userService.ValidateUserData(new UserDataValidateModel
            {
                UserId    = null,
                Username  = model.Username,
                Email     = model.Email,
                FirstName = model.FirstName,
                LastName  = model.LastName
            }) as List <String>;

            if (model.Password != model.PasswordConfirm)
            {
                errors.Add("The passwords are don't match");
            }
            if (!Regex.IsMatch(model.Password, "((?=.*\\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[@#$%!?,._-]).{6,30})"))
            {
                errors.Add("Invalid password format.");
            }

            if (errors.Count == 0)
            {
                var isCreated = await _userService.CreateNew(model);

                if (isCreated)
                {
                    Response.StatusCode = StatusCodes.Status201Created;
                }
                else
                {
                    Response.StatusCode = StatusCodes.Status400BadRequest;
                    errors.Add("Unknown error. Try later.");
                }

                return(new SignupResponseDto
                {
                    Status = isCreated,
                    Messages = errors
                });
            }

            Response.StatusCode = StatusCodes.Status400BadRequest;
            return(new SignupResponseDto
            {
                Status = false,
                Messages = errors
            });
        }
Ejemplo n.º 2
0
        public async Task <Boolean> CreateNew(SignupRequestDto model)
        {
            using (var uow = _tellerDatabaseUnitOfWorkFactory.CreateBasicUnitOfWork())
            {
                var user = new User
                {
                    Username   = model.Username.Trim().ToLower(),
                    Password   = EncryptPassword(model.Password),
                    Email      = model.Email.Trim().ToLower(),
                    IsActivate = true,
                    IsBlocked  = false,
                    Role       = UserRole.User,
                    FirstName  = model.FirstName.Trim(),
                    LastName   = model.LastName.Trim()
                };

                var savedUser = await uow.GetRepository <IUserRepository>().SaveOrUpdate(user);

                uow.Commit();

                return(savedUser != null);
            }
        }