-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from XIMDEX/develop
Develop
- Loading branch information
Showing
134 changed files
with
15,352 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
root = true | ||
|
||
[*] | ||
charset = utf-8 | ||
end_of_line = lf | ||
indent_size = 4 | ||
indent_style = space | ||
insert_final_newline = true | ||
trim_trailing_whitespace = true | ||
|
||
[*.md] | ||
trim_trailing_whitespace = false | ||
|
||
[*.{yml,yaml}] | ||
indent_size = 2 | ||
|
||
[docker-compose.yml] | ||
indent_size = 4 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
APP_NAME=Laravel | ||
APP_ENV=local | ||
APP_KEY= | ||
APP_DEBUG=true | ||
APP_TIMEZONE=UTC | ||
APP_URL=http://localhost | ||
|
||
APP_LOCALE=en | ||
APP_FALLBACK_LOCALE=en | ||
APP_FAKER_LOCALE=en_US | ||
|
||
APP_MAINTENANCE_DRIVER=file | ||
APP_MAINTENANCE_STORE=database | ||
|
||
BCRYPT_ROUNDS=12 | ||
|
||
LOG_CHANNEL=stack | ||
LOG_STACK=single | ||
LOG_DEPRECATIONS_CHANNEL=null | ||
LOG_LEVEL=debug | ||
|
||
DB_CONNECTION=sqlite | ||
# DB_HOST=127.0.0.1 | ||
# DB_PORT=3306 | ||
# DB_DATABASE=laravel | ||
# DB_USERNAME=root | ||
# DB_PASSWORD= | ||
|
||
SESSION_DRIVER=database | ||
SESSION_LIFETIME=120 | ||
SESSION_ENCRYPT=false | ||
SESSION_PATH=/ | ||
SESSION_DOMAIN=null | ||
|
||
BROADCAST_CONNECTION=log | ||
FILESYSTEM_DISK=local | ||
QUEUE_CONNECTION=database | ||
|
||
CACHE_STORE=database | ||
CACHE_PREFIX= | ||
|
||
MEMCACHED_HOST=127.0.0.1 | ||
|
||
REDIS_CLIENT=phpredis | ||
REDIS_HOST=127.0.0.1 | ||
REDIS_PASSWORD=null | ||
REDIS_PORT=6379 | ||
|
||
MAIL_MAILER=log | ||
MAIL_HOST=127.0.0.1 | ||
MAIL_PORT=2525 | ||
MAIL_USERNAME=null | ||
MAIL_PASSWORD=null | ||
MAIL_ENCRYPTION=null | ||
MAIL_FROM_ADDRESS="[email protected]" | ||
MAIL_FROM_NAME="${APP_NAME}" | ||
|
||
AWS_ACCESS_KEY_ID= | ||
AWS_SECRET_ACCESS_KEY= | ||
AWS_DEFAULT_REGION=us-east-1 | ||
AWS_BUCKET= | ||
AWS_USE_PATH_STYLE_ENDPOINT=false | ||
|
||
VITE_APP_NAME="${APP_NAME}" | ||
|
||
PASSPORT_PERSONAL_ACCESS_CLIENT_ID="" | ||
PASSPORT_SECRET="" | ||
PASSPORT_TOKEN_NAME="" | ||
|
||
XDIR_FRONTEND_URL="" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
* text=auto eol=lf | ||
|
||
*.blade.php diff=html | ||
*.css diff=css | ||
*.html diff=html | ||
*.md diff=markdown | ||
*.php diff=php | ||
|
||
/.github export-ignore | ||
CHANGELOG.md export-ignore | ||
.styleci.yml export-ignore |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/.phpunit.cache | ||
/node_modules | ||
/public/build | ||
/public/hot | ||
/public/storage | ||
/storage/*.key | ||
/vendor | ||
.env | ||
.env.backup | ||
.env.production | ||
.phpunit.result.cache | ||
Homestead.json | ||
Homestead.yaml | ||
auth.json | ||
npm-debug.log | ||
yarn-error.log | ||
/.fleet | ||
/.idea | ||
/.vscode |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,102 @@ | ||
```bash | ||
X X DDDD I RRRR | ||
X X D D I R R | ||
X D D I RRRR | ||
X X D D I R R | ||
X X DDDD I R RR | ||
``` | ||
|
||
# xdir-back-v2 | ||
Backend de administración y registro de Usuarios y Roles | ||
|
||
# Configuración inicial de xdir-back-v2 | ||
|
||
Este documento proporciona una guía paso a paso para configurar el entorno de desarrollo del backend de administración y registro de Usuarios y Roles, `xdir-back-v2`. Sigue cuidadosamente las instrucciones para asegurar una correcta configuración del proyecto. | ||
PHP8.2 | ||
|
||
## Requisitos previos | ||
|
||
Antes de comenzar, asegúrate de tener instalado Git y Composer en tu sistema. Estas herramientas son esenciales para clonar el repositorio y gestionar las dependencias de PHP del proyecto. | ||
|
||
## Clonar el repositorio | ||
|
||
Para obtener el código fuente del proyecto, ejecuta el siguiente comando en tu terminal: | ||
```bash | ||
git clone [email protected]:XIMDEX/xdir-back-v2.git | ||
``` | ||
|
||
Este comando clona el repositorio en una nueva carpeta llamada xdir-back-v2 en tu directorio actual. | ||
Luego es necesario hacer un cd xdir-back-v2 para acceder al directorio. | ||
|
||
## Cambiar a la rama de desarrollo | ||
Para trabajar con la versión de desarrollo más reciente, cambia a la rama develop: | ||
```bash | ||
git checkout develop | ||
``` | ||
|
||
## Instalar las dependecias | ||
```bash | ||
composer install | ||
``` | ||
Este comando lee el archivo composer.json, descarga las dependencias requeridas y las instala en el directorio vendor. | ||
|
||
## ENV | ||
|
||
Copia el archivo .env.example para crear tu .env | ||
```bash | ||
cp .env.example .env | ||
``` | ||
Y configurar las variables de entorno, sobretodo las de database. | ||
Para que todos estos nuevos datos sean cargados es necesario ejecutar el siguiente comando: | ||
```bash | ||
php artisan optimize | ||
``` | ||
Y tras ello podemos verificar las rutas para ver que todo esta correcto: | ||
```bash | ||
php artisan route:list | ||
``` | ||
## Migrate | ||
Es necesario hacer el migrate: | ||
```bash | ||
php artisan migrate | ||
``` | ||
Ahora probar la ruta de /register, podemos usar los siguientes datos: | ||
```bash | ||
{ | ||
"email": "[email protected]", | ||
"password": "test123456", | ||
"name": "test", | ||
"surname": "text para surname", | ||
"birthdate": "2020-10-10" | ||
} | ||
``` | ||
En la respuesta tendremos el token que nos servira para no tener que registar un mail real(Recuerda tener la app en modo debug, en el env, para obtener esta respuesta) | ||
## Keys | ||
```bash | ||
php artisan key:generate | ||
``` | ||
Tambien hay que generar las keys para passport | ||
```bash | ||
php artisan passport:keys | ||
``` | ||
Y asegurarnos de que tengan los permisos correctamente | ||
```bash | ||
sudo chown www-data:www-data storage/oauth-public.key storage/oauth-private.key | ||
``` | ||
Nos quedaria general la clave | ||
```bash | ||
php artisan passport:client --personal. | ||
``` | ||
Al final recibiras dos variables que habra que guardar en el .env junto al nombre que se le haya asignado | ||
```bash | ||
PASSPORT_PERSONAL_ACCESS_CLIENT_ID="tu_id_de_cliente" | ||
PASSPORT_SECRET="tu_secreto_cliente" | ||
PASSPORT_TOKEN_NAME="nombre_del_cliente" | ||
``` | ||
Y acabamos con un php artisan optimize | ||
|
||
## Verificación de Email y Login | ||
|
||
Verificar el email: Para simular la verificación de email, accede a la ruta /email/verify/{token}, donde {token} es el token de verificación que obtuviste previamente. | ||
|
||
Probar el login: Una vez verificado el email, puedes proceder a probar el login mediante la ruta /login utilizando herramientas como Postman o cURL, proporcionando las credenciales de usuario (email y contraseña). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?php | ||
|
||
namespace App\Builders; | ||
|
||
use App\Builders\interfaces\PayloadBuilderInterface; | ||
use Exception; | ||
|
||
class PayloadBuilder implements PayloadBuilderInterface | ||
{ | ||
protected $data; | ||
protected $action; | ||
|
||
public function setData(array $data): PayloadBuilderInterface | ||
{ | ||
$this->data = $data; | ||
return $this; | ||
} | ||
|
||
public function setAction(string $action): PayloadBuilderInterface | ||
{ | ||
$this->action = $action; | ||
return $this; | ||
} | ||
|
||
/** | ||
* Returns a JSON-encoded string representation of the payload data and action. | ||
* | ||
* @return string The JSON-encoded payload. | ||
* @throws Exception If there is an error encoding the payload. | ||
*/ | ||
public function build(): array | ||
{ | ||
$payload = ([ | ||
'data' => $this->data, | ||
'action' => $this->action, | ||
]); | ||
|
||
if (json_last_error() !== JSON_ERROR_NONE) { | ||
throw new Exception('JSON encode error: ' . json_last_error_msg()); | ||
} | ||
|
||
return $payload; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?php | ||
|
||
namespace App\Builders\interfaces; | ||
interface PayloadBuilderInterface | ||
{ | ||
public function setData(array $data): PayloadBuilderInterface; | ||
public function setAction(string $action): PayloadBuilderInterface; | ||
public function build(): array; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?php | ||
|
||
namespace App\Claims; | ||
|
||
use App\Models\Tool; | ||
use App\Models\User; | ||
use CorBosman\Passport\AccessToken; | ||
|
||
//Improve this function in the future, removing User and Tool dependency | ||
|
||
class CustomClaim | ||
{ | ||
public function handle(AccessToken $token, $next) | ||
{ | ||
$user = User::with(['roles.tools'])->find($token->getUserIdentifier()); | ||
|
||
$rolesBitwiseMap = [ | ||
'viewer' => '11100000', | ||
'creator' => '11110000', | ||
'editor' => '11111100', | ||
'admin' => '11111110', | ||
'superadmin' => '11111111', | ||
]; | ||
$toolsPermissions = []; | ||
|
||
foreach ($user->roles as $role) { | ||
$permission = $rolesBitwiseMap[strtolower($role->name)] ?? null; | ||
if ($permission) { | ||
$toolId = $role->pivot->tool_id; | ||
$tool = Tool::find($toolId); | ||
if ($tool) { | ||
$toolHash = $tool->hash; | ||
$orgPermission = $permission . '#' . $role->pivot->organization_id; | ||
$toolsPermissions[$toolHash][] = $orgPermission; // Use $toolHash as the key | ||
} | ||
} | ||
} | ||
|
||
$token->addClaim('p', $toolsPermissions); | ||
return $next($token); | ||
} | ||
} |
Oops, something went wrong.