Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
10 changes: 7 additions & 3 deletions app/Http/Controllers/SashaAuthController.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,18 @@ public function handleCallback(Request $request)
]);

$userResponse = Http::withToken($accessToken)->get(config('services.sasha.main_url') . '/api/me')->json();

// if (!$userResponse->successful()) {
// return redirect('/error')->withErrors('No se pudo autenticar con SASHA.');
// }
$sashaUser = $userResponse['data'];

$user = User::updateOrCreate([
'id' => $sashaUser['uuid'],
'uuid' => $sashaUser['uuid'],
], [
'id' => $sashaUser['uuid'],
'name' => $sashaUser["name"],
'last_name' => $sashaUser["last_name"],
'uuid' => $sashaUser['uuid'],
'email' => $sashaUser['email'],
'grade' => $sashaUser['grade'],
'fingerprint' => $sashaUser['fingerprint'],
Expand All @@ -101,6 +105,6 @@ public function handleCallback(Request $request)

Log::info(Auth::user());

return redirect('/');
return redirect(route($sashaUser["type"] . '.home'));
}
}
25 changes: 25 additions & 0 deletions app/Http/Middleware/CoordinatorCheck.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

namespace App\Http\Middleware;

use Closure;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Gate;
use Symfony\Component\HttpFoundation\Response;

class CoordinatorCheck
{
/**
* Handle an incoming request.
*
* @param \Closure(\Illuminate\Http\Request): (\Symfony\Component\HttpFoundation\Response) $next
*/
public function handle(Request $request, Closure $next): Response
{
if (! Gate::allows('student')) {
return abort(403);
}

return $next($request);
}
}
25 changes: 25 additions & 0 deletions app/Http/Middleware/DeveloperCheck.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

namespace App\Http\Middleware;

use Closure;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Gate;
use Symfony\Component\HttpFoundation\Response;

class DeveloperCheck
{
/**
* Handle an incoming request.
*
* @param \Closure(\Illuminate\Http\Request): (\Symfony\Component\HttpFoundation\Response) $next
*/
public function handle(Request $request, Closure $next): Response
{
if (! Gate::allows('developer')) {
return abort(403);
}

return $next($request);
}
}
25 changes: 25 additions & 0 deletions app/Http/Middleware/StudentCheck.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

namespace App\Http\Middleware;

use Closure;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Gate;
use Symfony\Component\HttpFoundation\Response;

class StudentCheck
{
/**
* Handle an incoming request.
*
* @param \Closure(\Illuminate\Http\Request): (\Symfony\Component\HttpFoundation\Response) $next
*/
public function handle(Request $request, Closure $next): Response
{
if (! Gate::allows('student')) {
return abort(403);
}

return $next($request);
}
}
24 changes: 24 additions & 0 deletions app/Http/Middleware/TeacherCheck.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

namespace App\Http\Middleware;

use Closure;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Gate;
use Symfony\Component\HttpFoundation\Response;

class TeacherCheck
{
/**
* Handle an incoming request.
*
* @param \Closure(\Illuminate\Http\Request): (\Symfony\Component\HttpFoundation\Response) $next
*/
public function handle(Request $request, Closure $next): Response
{
if (Gate::allows('teacher') || Gate::allows('coordinator')) {
return $next($request);
}
return abort(403);
}
}
24 changes: 24 additions & 0 deletions app/Livewire/Students/Chat.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

namespace App\Livewire\Students;

use Livewire\Attributes\Layout;
use Livewire\Component;

#[Layout('templates.students')]
class Chat extends Component
{
public $chatId = 1;
public function render()
{
return view('students.chat');
}

public function toggleChat(int $id)
{
if ($this->chatId === $id) {
return $this->chatId = null;
}
return $this->chatId = $id;
}
}
17 changes: 17 additions & 0 deletions app/Livewire/Students/Main.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

namespace App\Livewire\Students;

use Livewire\Attributes\Layout;
use Livewire\Component;



#[Layout('templates.students')]
class Main extends Component
{
public function render()
{
return view('students.main');
}
}
16 changes: 16 additions & 0 deletions app/Livewire/Teacher/Main.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

namespace App\Livewire\Teacher;

use Illuminate\Support\Facades\Gate;
use Livewire\Attributes\Layout;
use Livewire\Component;

#[Layout('templates.teachers')]
class Main extends Component
{
public function render()
{
return view('teachers.main');
}
}
22 changes: 22 additions & 0 deletions app/Livewire/Website/Home.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

namespace App\Livewire\Website;

use Livewire\Attributes\Layout;
use Livewire\Component;

#[Layout('templates.general')]
class Home extends Component
{
public $showModal = false;

public function render()
{
return view('landig-page');
}

public function toggleModal()
{
$this->showModal = !$this->showModal;
}
}
2 changes: 1 addition & 1 deletion app/Models/Newness.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ class Newness extends Model

public function user(): BelongsTo
{
return $this->belongsTo(User::class);
return $this->belongsTo(User::class, 'user_uuid');
}
}
9 changes: 3 additions & 6 deletions app/Models/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

// use Illuminate\Contracts\Auth\MustVerifyEmail;

use Illuminate\Database\Eloquent\Concerns\HasUuids;
use App\Enums\UserRol;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Foundation\Auth\User as Authenticatable;
Expand All @@ -15,15 +15,14 @@
class User extends Authenticatable
{
/** @use HasFactory<\Database\Factories\UserFactory> */
use HasFactory, Notifiable, TwoFactorAuthenticatable, HasUuids;
use HasFactory, Notifiable, TwoFactorAuthenticatable;

/**
* The attributes that are mass assignable.
*
* @var list<string>
*/
protected $fillable = [
'id',
'name',
'last_name',
'email',
Expand All @@ -38,9 +37,6 @@ class User extends Authenticatable
'rol'
];

public $incrementing = false;
protected $keyType = 'string';

/**
* The attributes that should be hidden for serialization.
*
Expand All @@ -61,6 +57,7 @@ protected function casts(): array
return [
'email_verified_at' => 'datetime',
'password' => 'hashed',
'rol' => UserRol::class,
];
}

Expand Down
21 changes: 20 additions & 1 deletion app/Providers/AppServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

namespace App\Providers;

use App\Enums\UserRol;
use App\Models\User;
use Illuminate\Support\Facades\Gate;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\ServiceProvider;

class AppServiceProvider extends ServiceProvider
Expand All @@ -19,6 +23,21 @@ public function register(): void
*/
public function boot(): void
{
//

Gate::define('student', function (User $user) {
return $user->rol == UserRol::Student;
});

Gate::define('teacher', function (User $user) {
return $user->rol == UserRol::Teacher;
});

Gate::define('coordinator', function (User $user) {
return $user->rol == UserRol::Coordinator;
});

Gate::define('developer', function (User $user) {
return $user->rol == UserRol::Developer;
});
}
}
15 changes: 12 additions & 3 deletions bootstrap/app.php
Original file line number Diff line number Diff line change
@@ -1,17 +1,26 @@
<?php

use App\Http\Middleware\CoordinatorCheck;
use App\Http\Middleware\DeveloperCheck;
use App\Http\Middleware\StudentCheck;
use App\Http\Middleware\TeacherCheck;
use Illuminate\Foundation\Application;
use Illuminate\Foundation\Configuration\Exceptions;
use Illuminate\Foundation\Configuration\Middleware;

return Application::configure(basePath: dirname(__DIR__))
->withRouting(
web: __DIR__.'/../routes/web.php',
commands: __DIR__.'/../routes/console.php',
web: __DIR__ . '/../routes/web.php',
commands: __DIR__ . '/../routes/console.php',
health: '/up',
)
->withMiddleware(function (Middleware $middleware) {
//
$middleware->alias([
'student' => StudentCheck::class,
'teacher' => TeacherCheck::class,
'coordinator' => CoordinatorCheck::class,
'developer' => DeveloperCheck::class
]);
})
->withExceptions(function (Exceptions $exceptions) {
//
Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
"mockery/mockery": "^1.6",
"nunomaduro/collision": "^8.6",
"pestphp/pest": "^3.8",
"pestphp/pest-plugin-laravel": "^3.2"
"pestphp/pest-plugin-laravel": "^3.2",
"phiki/phiki": "^2.0"
},
"autoload": {
"psr-4": {
Expand Down
Loading
Loading