Skip to content

Commit 3d311e9

Browse files
committed
fix: ajustes importantes
1 parent 94e3bcc commit 3d311e9

File tree

12 files changed

+93
-12
lines changed

12 files changed

+93
-12
lines changed

README.md

+16-7
Original file line numberDiff line numberDiff line change
@@ -82,12 +82,21 @@ Apenas siga as instruções geradas pelo script no seu terminal.
8282

8383
**Execute o Método B apenas se o A não estiver funcionado corretamente.**
8484

85-
2. **Instale as dependências**
85+
2. **Instale extensões do PHP que podem ajudar**
8686
```bash
87-
composer-install
87+
sudo apt install php-curl php-xml php-mbstring php-zip
88+
```
89+
3. **Instale as dependências**
90+
```bash
91+
composer install
92+
```
93+
94+
4. **Instale a biblioteca do JWT**
95+
```bash
96+
composer require firebase/php-jwt
8897
```
8998

90-
3. **Copie e configure o ambiente**
99+
5. **Copie e configure o ambiente**
91100
```bash
92101
cp env .env
93102
```
@@ -112,22 +121,22 @@ Apenas siga as instruções geradas pelo script no seu terminal.
112121
JWT_SECRET = "minha_vaga_backend"
113122
```
114123

115-
4. **Suba os containers**
124+
6. **Suba os containers**
116125
```bash
117126
docker-compose up -d
118127
```
119128

120-
5. **Acesse o container do PHP**
129+
7. **Acesse o container do PHP**
121130
```bash
122131
docker-compose exec app bash
123132
```
124133

125-
6. **Execute as migrations**
134+
8. **Execute as migrations**
126135
```bash
127136
php spark migrate
128137
```
129138

130-
7. **Execute os seeders (dados iniciais)**
139+
9. **Execute os seeders (dados iniciais)**
131140
- Para avitar erros devidos aos relacionamentos das tabelas, execute exatamente nesta ordem:
132141

133142
```bash

app/Config/Routes.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
$routes->group("api", function ($routes) {
1111
$routes->post("registrar", "RegistroController::index");
1212
$routes->post("login", "LoginController::index");
13-
$routes->post("validar", "LoginController::token");
13+
$routes->post("validar", "LoginController::login");
1414
$routes->get("usuarios", "UserController::index", ['filter' => 'authFilter']);
1515
});
1616

app/Controllers/LoginController.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ public function index()
9999
return $this->respond($response, 200);
100100
}
101101

102-
public function token()
102+
public function login()
103103
{
104104
$users = $this->request->getPost();
105105

app/Filters/AuthFilter.php

+14-2
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,13 @@ public function before(RequestInterface $request, $arguments = null)
3939

4040
if (is_null($token) || empty($token)) {
4141
$response = service('response');
42-
$response->setBody('Access denied');
42+
$response->setJSON([
43+
'cabecalho' => [
44+
'status' => 401,
45+
'mensagem' => 'Acesso negado. Tente novamente'
46+
],
47+
'retorno' => null
48+
]);
4349
$response->setStatusCode(401);
4450
return $response;
4551
}
@@ -48,7 +54,13 @@ public function before(RequestInterface $request, $arguments = null)
4854
$decoded = JWT::decode($token, new Key($key, 'HS256'));
4955
} catch (\Exception $ex) {
5056
$response = service('response');
51-
$response->setBody('Access denied: ' . $ex->getMessage());
57+
$response->setJSON([
58+
'cabecalho' => [
59+
'status' => 401,
60+
'mensagem' => 'Acesso negado: ' . $ex->getMessage()
61+
],
62+
'retorno' => null
63+
]);
5264
$response->setStatusCode(401);
5365
return $response;
5466
}

app/Models/UserModel.php

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<?php
2+
3+
namespace App\Models;
4+
5+
use CodeIgniter\Model;
6+
7+
class UserModel extends Model
8+
{
9+
protected $table = 'users';
10+
protected $primaryKey = 'id';
11+
protected $useAutoIncrement = true;
12+
protected $returnType = 'array';
13+
protected $useSoftDeletes = false;
14+
protected $protectFields = true;
15+
protected $allowedFields = [
16+
'email',
17+
'password'
18+
];
19+
20+
protected bool $allowEmptyInserts = false;
21+
protected bool $updateOnlyChanged = true;
22+
23+
protected array $casts = [];
24+
protected array $castHandlers = [];
25+
26+
// Dates
27+
protected $useTimestamps = false;
28+
protected $dateFormat = 'datetime';
29+
protected $createdField = 'created_at';
30+
protected $updatedField = 'updated_at';
31+
protected $deletedField = 'deleted_at';
32+
33+
// Validation
34+
protected $validationRules = [
35+
'email' => 'required',
36+
'password' => 'required'
37+
];
38+
protected $validationMessages = [
39+
'email' => [
40+
'required' => 'O campo email é obrigatório.',
41+
// 'is_unique' => 'Email deve ser único.'
42+
],
43+
'password' => [
44+
'required' => 'O campo senha é obrigatório.'
45+
]
46+
];
47+
protected $skipValidation = false;
48+
protected $cleanValidationRules = true;
49+
50+
// Callbacks
51+
protected $allowCallbacks = true;
52+
protected $beforeInsert = [];
53+
protected $afterInsert = [];
54+
protected $beforeUpdate = [];
55+
protected $afterUpdate = [];
56+
protected $beforeFind = [];
57+
protected $afterFind = [];
58+
protected $beforeDelete = [];
59+
protected $afterDelete = [];
60+
}

install.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ if ! command -v docker compose &> /dev/null; then
1414
exit 1
1515
fi
1616

17-
sudo chmod -R 777 ../api-codeigniter4
17+
# sudo chmod -R 777 ../api-codeigniter4
1818
sudo apt install php-curl php-xml php-mbstring php-zip
1919

2020
#composer install

writable/.htaccess

100755100644
File mode changed.

writable/cache/index.html

100755100644
File mode changed.

writable/index.html

100755100644
File mode changed.

writable/logs/index.html

100755100644
File mode changed.

writable/session/index.html

100755100644
File mode changed.

writable/uploads/index.html

100755100644
File mode changed.

0 commit comments

Comments
 (0)