Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft: React migration #1295

Draft
wants to merge 32 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
3b63ac4
adding new blocklist test
dgershman Dec 6, 2024
46c76b5
refactored session delete
dgershman Dec 6, 2024
6b5ee29
fix lint
dgershman Dec 6, 2024
c036cb3
updating to have hover state
dgershman Dec 7, 2024
e8ac543
completed settings page
dgershman Dec 7, 2024
0ae3c55
wip logins
dgershman Dec 14, 2024
db636b7
working auth tests
dgershman Dec 18, 2024
20a6289
sanctum refactor
dgershman Dec 18, 2024
c1780aa
beginning of new login page
dgershman Dec 21, 2024
763ba99
login kinda working
dgershman Dec 22, 2024
5b16232
auth really working now
dgershman Dec 22, 2024
6d6a5c4
a little skinning
dgershman Dec 23, 2024
8512f33
wip
dgershman Dec 23, 2024
12d87e2
fixing users page
dgershman Dec 24, 2024
ee1eb51
allow for setting session time
dgershman Dec 28, 2024
e647413
remove extra whitespace issue
dgershman Dec 28, 2024
5dfcf42
working but not all nav
dgershman Dec 28, 2024
f5dbdb4
working menus
dgershman Dec 28, 2024
7dc539c
closer to working, but still an issue with session persistence
dgershman Jan 1, 2025
237d940
fixed session
dgershman Jan 1, 2025
aefffe1
minor cleanup
dgershman Jan 1, 2025
561f164
moving openapi json out of auth
dgershman Jan 1, 2025
30e0a7c
updates
dgershman Jan 1, 2025
9c48dee
cleaning up docs and seeders for users
dgershman Jan 1, 2025
2ec9e52
call handling dialogs opening
dgershman Jan 1, 2025
d90ea49
fix lint issue
dgershman Jan 3, 2025
692472d
tests passing
dgershman Jan 3, 2025
51c2756
baseline for call handling dialog
dgershman Jan 5, 2025
00931b2
adding more fields
dgershman Jan 5, 2025
e076a77
progress
dgershman Jan 5, 2025
4ac4eb6
some cleanup + auth for swagger
dgershman Jan 5, 2025
f4a1b27
handle session timeout
dgershman Jan 8, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Listen for Xdebug",
"type": "php",
"request": "launch",
"port": 9003
},
{
"name": "Launch currently open script",
"type": "php",
"request": "launch",
"program": "${file}",
"cwd": "${fileDirname}",
"port": 0,
"runtimeArgs": [
"-dxdebug.start_with_request=yes"
],
"env": {
"XDEBUG_MODE": "debug,develop",
"XDEBUG_CONFIG": "client_port=${port}"
}
},
{
"name": "Launch Built-in web server",
"type": "php",
"request": "launch",
"runtimeArgs": [
"-dxdebug.mode=debug",
"-dxdebug.start_with_request=yes",
"-S",
"localhost:0"
],
"program": "",
"cwd": "${workspaceRoot}",
"port": 9003,
"serverReadyAction": {
"pattern": "Development Server \\(http://localhost:([0-9]+)\\) started",
"uriFormat": "http://localhost:%s",
"action": "openExternally"
}
}
]
}
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"makefile.makefilePath": "./src/Makefile"
}
9 changes: 5 additions & 4 deletions CONTRIBUTE.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
### Getting it up and running.

1. Clone this repository.
2. Run `make deploy`.
3. Run `make watch`.
4. Run `make run`.
5. Browse to http://localhost:3100/yap in your web browser.
2. Run `npm install`.
3. Run `composer install`
3. Run `make bundle`.
4. Run `make serve`.
5. Browse to http://localhost:8080/yap in your web browser.

### Testing

Expand Down
7 changes: 7 additions & 0 deletions src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,10 @@ deploy: bundle-deps bundle
.PHONY: swagger
swagger:
php artisan l5-swagger:generate

.PHONY: seed
seed:
ENVIRONMENT=test php artisan db:seed

mix:
npm run watch
76 changes: 76 additions & 0 deletions src/app/Auth/CustomUserProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<?php

namespace App\Auth;

use Illuminate\Contracts\Auth\UserProvider;
use Illuminate\Contracts\Auth\Authenticatable;
use App\Models\User;
use App\Services\AuthenticationService;

class CustomUserProvider implements UserProvider
{
protected AuthenticationService $authService;

public function __construct(AuthenticationService $authService)
{
$this->authService = $authService;
}

/**
* Retrieve a user by their unique identifier (e.g., ID).
*/
public function retrieveById($identifier)
{
return User::find($identifier);
}

/**
* Retrieve a user by their unique identifier and "remember me" token.
*/
public function retrieveByToken($identifier, $token)
{
$user = $this->retrieveById($identifier);

if ($user && $user->getRememberToken() === $token) {
return $user;
}

return null;
}

/**
* Update the "remember me" token for the user.
*/
public function updateRememberToken(Authenticatable $user, $token)
{
$user->setRememberToken($token);
$user->save();
}

/**
* Retrieve a user by their credentials.
*/
public function retrieveByCredentials(array $credentials)
{
$username = $credentials['username'] ?? null;
$password = $credentials['password'] ?? null;

// Use your custom AuthenticationService logic to authenticate the user
$user = $this->authService->authenticateApi($username, $password);

return $user;
}

/**
* Validate a user against the given credentials.
*/
public function validateCredentials(Authenticatable $user, array $credentials)
{
$plainPassword = $credentials['password'];

$hashedPassword = hash('sha256', $plainPassword);

// Compare with the stored password
return hash_equals($user->getAuthPassword(), $hashedPassword);
}
}
24 changes: 12 additions & 12 deletions src/app/Http/Controllers/AdminController.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,16 +89,16 @@ public function installer(Request $request)
return view('admin/installer');
}

public function login(Request $request): RedirectResponse
{
$username = $request->post('username');
$password = $request->post('password');

$auth = $this->authn->authenticate($username, $password);
if ($auth) {
return redirect("admin/home");
} else {
return redirect("admin/auth/invalid");
}
}
// public function login(Request $request): RedirectResponse
// {
// $username = $request->post('username');
// $password = $request->post('password');
//
// $auth = $this->authn->authenticate($username, $password);
// if ($auth) {
// return redirect("admin/home");
// } else {
// return redirect("admin/auth/invalid");
// }
// }
}
2 changes: 1 addition & 1 deletion src/app/Http/Controllers/AdminV2Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class AdminV2Controller extends Controller
public function index(Request $request)
{
return view('admin')
->with('baseUrl', sprintf("%s/adminv2", $request->getBaseUrl()))
->with('baseUrl', "adminv2")
->with('rootUrl', $request->getBaseUrl());
}
}
101 changes: 101 additions & 0 deletions src/app/Http/Controllers/Api/V1/Admin/AuthController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
<?php
namespace App\Http\Controllers\Api\V1\Admin;

use App\Http\Controllers\Controller;
use App\Services\AuthenticationService;
use App\Services\AuthorizationService;
use App\Services\SettingsService;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Log;

/**
* @OA\SecurityScheme(
* securityScheme="BearerAuth",
* type="http",
* scheme="bearer",
* bearerFormat="JWT"
* )
*/
class AuthController extends Controller
{
protected AuthorizationService $authz;
protected AuthenticationService $authn;

public function __construct(
AuthorizationService $authz,
AuthenticationService $authn,
) {
$this->authz = $authz;
$this->authn = $authn;
}

/**
* @OA\Post(
* path="/api/v1/login",
* tags={"Auth"},
* summary="Login to get a Bearer Token",
* @OA\RequestBody(
* required=true,
* @OA\JsonContent(
* required={"username","password"},
* @OA\Property(property="username", type="string", format="username", example="username"),
* @OA\Property(property="password", type="string", format="password", example="password")
* )
* ),
* @OA\Response(
* response=200,
* description="Successful operation",
* @OA\JsonContent(
* @OA\Property(property="token", type="string", example="Bearer your_token_here")
* )
* ),
* @OA\Response(
* response=401,
* description="Invalid credentials"
* )
* )
*/
public function login(Request $request)
{
$request->validate([
'username' => 'required|string',
'password' => 'required|string',
]);

$credentials = $request->only('username', 'password');

if (!Auth::attempt($credentials)) {
return response()->json(['message' => 'Invalid credentials'], 401);
}

$request->session()->regenerate();
$user = Auth::user();

return response()->json([
'status' => 'success',
'token' => $user->createToken('API Token')->plainTextToken,
'user' => $user,
]);
}

public function index(Request $request): JsonResponse
{
return response()->json($request->user());
}

public function logout(Request $request)
{
$this->authn->logout();
$request->user()->tokens()->delete();

return response()->json(['message' => 'Logged out successfully']);
}

public function rights()
{
$rights = $this->authz->getServiceBodyRights();
return $rights ?? response()->json(['error' => 'Unauthorized'], 403);
}
}
34 changes: 34 additions & 0 deletions src/app/Http/Controllers/Api/V1/Admin/CacheController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

namespace App\Http\Controllers\Api\V1\Admin;

use App\Http\Controllers\Controller;
use App\Models\Cache;
use App\Models\CacheRecordsConferenceParticipants;

class CacheController extends Controller
{
/**
* @OA\Post(
* path="/api/v1/cache",
* operationId="Cache",
* tags={"Cache"},
* summary="Clear Cache",
* description="Clear Cache",
* @OA\Response(
* response=200,
* description="Data Returned",
* @OA\JsonContent()
* ),
* @OA\Response(response=400, description="Bad request"),
* @OA\Response(response=404, description="Resource Not Found"),
* )
*/
public function store()
{
Cache::truncate();
CacheRecordsConferenceParticipants::truncate();

return response()->json(["status"=>"ok"]);
}
}
Loading