...
BIN
MyObsidianVault/Pasted image 20241123100630.png
Normal file
|
After Width: | Height: | Size: 73 KiB |
BIN
MyObsidianVault/Pasted image 20241123100706.png
Normal file
|
After Width: | Height: | Size: 68 KiB |
BIN
MyObsidianVault/Pasted image 20241123100734.png
Normal file
|
After Width: | Height: | Size: 50 KiB |
BIN
MyObsidianVault/Pasted image 20241123100756.png
Normal file
|
After Width: | Height: | Size: 45 KiB |
BIN
MyObsidianVault/Pasted image 20241123100834.png
Normal file
|
After Width: | Height: | Size: 92 KiB |
BIN
MyObsidianVault/Pasted image 20241123100851.png
Normal file
|
After Width: | Height: | Size: 51 KiB |
BIN
MyObsidianVault/Pasted image 20241123100913.png
Normal file
|
After Width: | Height: | Size: 61 KiB |
BIN
MyObsidianVault/Pasted image 20241123101019.png
Normal file
|
After Width: | Height: | Size: 345 KiB |
|
|
@ -0,0 +1,35 @@
|
|||
```bash
|
||||
php spark make:controller Api/Auth --suffix --restful
|
||||
php spark make:controller Api/Project --suffix --restful
|
||||
```
|
||||
|
||||
![[Pasted image 20241123100630.png]]
|
||||
![[Pasted image 20241123100706.png]]
|
||||
![[Pasted image 20241123100734.png]]
|
||||
![[Pasted image 20241123100756.png]]
|
||||
|
||||
|
||||
--- PROJECT CONTROLLER
|
||||
![[Pasted image 20241123100834.png]]
|
||||
![[Pasted image 20241123100851.png]]
|
||||
![[Pasted image 20241123100913.png]]
|
||||
ADD SHIELD USERMODEL
|
||||
|
||||
![[Pasted image 20241123101019.png]]
|
||||
|
||||
|
||||
|
||||
```bash
|
||||
php spark make:model Project --suffix
|
||||
```
|
||||
|
||||
|
||||
extend allowedFields, e.g.
|
||||
```php
|
||||
$allowedFields = ["user_id","name"]
|
||||
```
|
||||
|
||||
Add Project Model to ProjectController
|
||||
```php
|
||||
use App\Models\ProjectModel;
|
||||
```
|
||||
|
|
@ -0,0 +1,22 @@
|
|||
https://www.youtube.com/watch?v=_ZRHt-fWJpc&list=PLT9miexWCpPW6Z_OXNv2d78cqCrZaPrVG&index=29
|
||||
|
||||
app/Config/Routes.php
|
||||
|
||||
Remember: Shield added =>
|
||||
```php
|
||||
service('auth')->routes($routes)
|
||||
```
|
||||
|
||||
```php
|
||||
// API routes (put below service('auth'))
|
||||
$routes->group("api", ["namespace" => "App\Controller\Api"], function($routes) {
|
||||
$routes->post("register", "AuthController::register");
|
||||
$routes->post("login", "AuthController::login");
|
||||
$routes->get("profile", "AuthController::profile");
|
||||
$routes->get("logout", "AuthController::logout");
|
||||
|
||||
$routes->post("add-project", "ProjectController::addProject");
|
||||
$routes->get("list-projects", "ProjectController::listProjects");
|
||||
$routes->delete("delete-project/(:num)", "ProjectController::deleteProject/$1");
|
||||
});
|
||||
```
|
||||
46
MyObsidianVault/WebDev/2 CodeIgniter/17.) Register API.md
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
|
||||
AuthController:
|
||||
|
||||
```php
|
||||
|
||||
use CodeIgniter\Restful\ResourceController;
|
||||
use CodeIgniter\Shield\Models\UserModel;
|
||||
use CodeIgniter\Shield\Entities\User;
|
||||
|
||||
class AuthController extends ResourceController
|
||||
{
|
||||
//Post
|
||||
public function register()
|
||||
{
|
||||
$rules = [
|
||||
"username" => "required|is_unique[users.username]",
|
||||
"email" => "required|valid_email|is_unique[auth_identities.secret]",
|
||||
"password" => "required"
|
||||
];
|
||||
|
||||
if (!$this->validate($rules)) {
|
||||
$response = [
|
||||
"status" => false,
|
||||
"message" => $this->validator->getErrors(),
|
||||
"data" => []
|
||||
];
|
||||
} else {
|
||||
$userObject = new UserModel(); // coming from Shield
|
||||
$userEntityObject = new User([
|
||||
"username" => $this->request->getVar("username"),
|
||||
"email" => $this->request->getVar("email"),
|
||||
"password" => $this->request->getVar("password")
|
||||
]);
|
||||
$userObject->save($userEntityObject);
|
||||
$response = [
|
||||
"status" => true,
|
||||
"message" => "User saved successfully",
|
||||
"data" => []
|
||||
]
|
||||
}
|
||||
return $this->respondCreated($response);
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
Note: shield stores users in auth_identies. Email address should be stored in field secret.
|
||||