コード例 #1
0
ファイル: UsersController.cs プロジェクト: pselpa/seu-vizinho
        public IActionResult UpdateUser(Guid id, [FromBody] CreateUserRequest request)
        {
            StringValues userId;

            if (!Request.Headers.TryGetValue("UserId", out userId))
            {
                return(Unauthorized());
            }

            var user = _usersService.GetById(Guid.Parse(userId));

            if (user == null)
            {
                return(Unauthorized());
            }
            if (user.CPF != request.CPF)
            {
                return(Unauthorized());
            }

            var modifiedUser = _usersService.GetById(id);

            if (modifiedUser == null)
            {
                return(NotFound());
            }

            modifiedUser.Name              = request.Name;
            modifiedUser.CPF               = request.CPF;
            modifiedUser.Email             = request.Email;
            modifiedUser.Phone             = request.Phone;
            modifiedUser.State             = request.State;
            modifiedUser.City              = request.City;
            modifiedUser.District          = request.District;
            modifiedUser.ZipCode           = request.ZipCode;
            modifiedUser.HouseNumber       = request.HouseNumber;
            modifiedUser.AddressComplement = request.AddressComplement;
            modifiedUser.Profile           = request.Profile;
            modifiedUser.Password          = request.Password;

            _usersService.Modify(modifiedUser);
            return(NoContent());
        }
コード例 #2
0
        public IActionResult SingUp(CreateUserRequest request)
        {
            var cur = new CreateUserRequest();

            if (!cur.ValidatePassword(request.Password).isValid)
            {
                return(BadRequest(cur.ValidatePassword(request.Password).errors));
            }
            if (request.Profile == Profile.CBF && request.RolePassword != "admin123")
            {
                return(Unauthorized("Senha de Cargo Invalida"));
            }
            var password = Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(request.Password));
            var response = _usersService.Create(request.Name, request.Profile, request.Email, password);

            if (!response.IsValid)
            {
                return(BadRequest(response.Errors));
            }

            return(Ok("User Created!"));
        }
コード例 #3
0
        public IActionResult Create(CreateUserRequest request)
        {
            var userService = new UserService();
            var user        = new User();

            if (request.RolePassword == Settings.EmployeePass)
            {
                user = userService.Create(request.Username, request.Password, "employee");
            }
            else if (request.RolePassword == Settings.ManagerPass)
            {
                user = userService.Create(request.Username, request.Password, "manager");
            }
            else
            {
                return(NotFound(new { message = "Usuário ou senha inválidos" }));
            }
            var userAndToken = UserRepository.GetUserByName(request.Username);

            // Retorna os dados
            return(Ok("User Created!"));
        }
コード例 #4
0
ファイル: UsersController.cs プロジェクト: pselpa/seu-vizinho
        //IActionResult é mais genérico e conseguimos retornar tanto o Unauthorized, quanto o Ok.
        public IActionResult Create(CreateUserRequest request)
        {
            if (request.Profile == UserProfile.Admin)
            {
                StringValues userId;
                if (!Request.Headers.TryGetValue("UserId", out userId))
                {
                    return(Unauthorized());
                }

                var user = _usersService.GetById(Guid.Parse(userId));

                if (user == null)
                {
                    return(Unauthorized());
                }

                if (user.Profile != UserProfile.Admin)
                {
                    return(Unauthorized());
                }

                var response = _usersService.Create(
                    request.Name,
                    request.CPF,
                    request.Email,
                    request.Phone,
                    request.State,
                    request.City,
                    request.District,
                    request.ZipCode,
                    request.HouseNumber,
                    request.AddressComplement,
                    request.Profile,
                    request.Password
                    );

                if (!response.IsValid)
                {
                    return(BadRequest(response.Errors));
                }

                return(NoContent());
            }
            else
            {
                var response = _usersService.Create(
                    request.Name,
                    request.CPF,
                    request.Email,
                    request.Phone,
                    request.State,
                    request.City,
                    request.District,
                    request.ZipCode,
                    request.HouseNumber,
                    request.AddressComplement,
                    request.Profile,
                    request.Password
                    );

                if (!response.IsValid)
                {
                    return(BadRequest(response.Errors));
                }

                return(NoContent());
            }
        }