diff --git a/MyObsidianVault/Pasted image 20241123100630.png b/MyObsidianVault/Pasted image 20241123100630.png new file mode 100644 index 0000000..23eb2e9 Binary files /dev/null and b/MyObsidianVault/Pasted image 20241123100630.png differ diff --git a/MyObsidianVault/Pasted image 20241123100706.png b/MyObsidianVault/Pasted image 20241123100706.png new file mode 100644 index 0000000..3d2085b Binary files /dev/null and b/MyObsidianVault/Pasted image 20241123100706.png differ diff --git a/MyObsidianVault/Pasted image 20241123100734.png b/MyObsidianVault/Pasted image 20241123100734.png new file mode 100644 index 0000000..92b2489 Binary files /dev/null and b/MyObsidianVault/Pasted image 20241123100734.png differ diff --git a/MyObsidianVault/Pasted image 20241123100756.png b/MyObsidianVault/Pasted image 20241123100756.png new file mode 100644 index 0000000..ad6eb69 Binary files /dev/null and b/MyObsidianVault/Pasted image 20241123100756.png differ diff --git a/MyObsidianVault/Pasted image 20241123100834.png b/MyObsidianVault/Pasted image 20241123100834.png new file mode 100644 index 0000000..bc123c3 Binary files /dev/null and b/MyObsidianVault/Pasted image 20241123100834.png differ diff --git a/MyObsidianVault/Pasted image 20241123100851.png b/MyObsidianVault/Pasted image 20241123100851.png new file mode 100644 index 0000000..5bcfbae Binary files /dev/null and b/MyObsidianVault/Pasted image 20241123100851.png differ diff --git a/MyObsidianVault/Pasted image 20241123100913.png b/MyObsidianVault/Pasted image 20241123100913.png new file mode 100644 index 0000000..fcf0279 Binary files /dev/null and b/MyObsidianVault/Pasted image 20241123100913.png differ diff --git a/MyObsidianVault/Pasted image 20241123101019.png b/MyObsidianVault/Pasted image 20241123101019.png new file mode 100644 index 0000000..192ac68 Binary files /dev/null and b/MyObsidianVault/Pasted image 20241123101019.png differ diff --git a/MyObsidianVault/WebDev/2 CodeIgniter/15.) Shield Auth+Project Controller.md b/MyObsidianVault/WebDev/2 CodeIgniter/15.) Shield Auth+Project Controller.md new file mode 100644 index 0000000..7ca7a88 --- /dev/null +++ b/MyObsidianVault/WebDev/2 CodeIgniter/15.) Shield Auth+Project Controller.md @@ -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; +``` \ No newline at end of file diff --git a/MyObsidianVault/WebDev/2 CodeIgniter/16.) API Routes Setup.md b/MyObsidianVault/WebDev/2 CodeIgniter/16.) API Routes Setup.md new file mode 100644 index 0000000..63c666c --- /dev/null +++ b/MyObsidianVault/WebDev/2 CodeIgniter/16.) API Routes Setup.md @@ -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"); +}); +``` \ No newline at end of file diff --git a/MyObsidianVault/WebDev/2 CodeIgniter/17.) Register API.md b/MyObsidianVault/WebDev/2 CodeIgniter/17.) Register API.md new file mode 100644 index 0000000..d4a3062 --- /dev/null +++ b/MyObsidianVault/WebDev/2 CodeIgniter/17.) Register API.md @@ -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. \ No newline at end of file