-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
usurios admin y vistas de edicion (#29)
* solucion de rutas breeze * script para compliar tailwind * modularizando mediante componentes laravel * fechas de creacion en cursos - datos de prueba * componente creado con el comando 'php artisan make:componet NombreComponente' permite integrar componete con BD o mas funciones * sombreado interactivo segun pestaña seleccionada - no funciona bien! * integro el componete se los cursos mas recientes * README * + paquete para autenticacion por Laravel Socialite * progreso de autenticacion por github * actualizo BD con campos para autenticacion de usuarios - solo github, apliable para google y otros * configuraciones para autenticacion - modelo y controlador * boton de login con github mediante componente en login y register * componente navbar redirecciona a nuevo register * para index devuele los cursos mas recientes primero * los cursos que sean creados menores a 30 dias muestrann el tag Nuevo * el recuento de cursos, usuarios y cursosVendidos creado por componente e implementado en la vista Conócenos * correccion de errores en inicio de secion * se solicita confirmar el email para poder ser registrado en la BD * Evito el modo oscuro en laravel desde tailwind * modo claro/oscuro backgroud en conócenos * nuevos tema de color para compativilizar el modo claro/oscuro * validacion de usuario y otros estilos * solucion de interfaz de recuperar contraseña * acceso para registrados * avatares para conocenos * login y register usando guest -> para usuarios no logueados * modo claro/oscuro * solucion el commit 'destruccion del proyecto' * logo * la verificacion de email tiene un mejor aspecto * añado propiedad is_admin a users para restricciones de contenido * usurios admin y vistas de edicion
- Loading branch information
Showing
5 changed files
with
187 additions
and
5 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,111 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers; | ||
|
||
use App\Models\User; | ||
use Auth; | ||
use Illuminate\Http\Request; | ||
|
||
class UserController extends Controller | ||
{ | ||
/** | ||
* Display a listing of the resource. | ||
*/ | ||
public function index() | ||
{ | ||
// | ||
} | ||
|
||
/** | ||
* Show the form for creating a new resource. | ||
*/ | ||
public function create() | ||
{ | ||
// | ||
} | ||
|
||
/** | ||
* Store a newly created resource in storage. | ||
*/ | ||
public function store(Request $request) | ||
{ | ||
// | ||
} | ||
|
||
/** | ||
* Display the specified resource. | ||
*/ | ||
public function show(string $id) | ||
{ | ||
// | ||
} | ||
|
||
/** | ||
* Show the form for editing the specified resource. | ||
*/ | ||
public function edit(string $id) | ||
{ | ||
// | ||
} | ||
|
||
/** | ||
* Update the specified resource in storage. | ||
*/ | ||
public function update(Request $request, string $id) | ||
{ | ||
// | ||
} | ||
|
||
/** | ||
* Remove the specified resource from storage. | ||
*/ | ||
public function destroy(string $id) | ||
{ | ||
// | ||
} | ||
|
||
|
||
//funciones que reciben un correo y actualiza un usuario a admin | ||
public function quitarAdmin(Request $request) | ||
{ | ||
$user = User::where('email', $request->email)->first(); | ||
$user->is_admin = false; | ||
$user->save(); | ||
return redirect('/profile'); | ||
} | ||
public function añadirAdmin(Request $request) | ||
{ | ||
$user = User::where('email', $request->email)->first(); | ||
$user->is_admin = true; | ||
$user->save(); | ||
return redirect('/profile'); | ||
} | ||
//switch admin | ||
public function switchAdmin(Request $request) | ||
{ | ||
// Obtiene el usuario autenticado | ||
$authenticatedUser = Auth::user(); | ||
|
||
// Busca el usuario por su correo electrónico en la base de datos | ||
$user = User::where('email', $request->email)->first(); | ||
|
||
if ($user) { | ||
// Verifica que el usuario autenticado no sea el mismo que se está modificando | ||
if ($user->id !== $authenticatedUser->id) { | ||
// Realiza la conmutación del estado 'is_admin' | ||
$user->is_admin = !$user->is_admin; | ||
|
||
// Guarda los cambios en la base de datos | ||
$user->save(); | ||
|
||
return redirect('/profile')->with('success', 'Cambios guardados exitosamente'); | ||
} else { | ||
return redirect('/profile')->with('error', 'No puedes quitarte a ti mismo el rol de administrador'); | ||
} | ||
} else { | ||
// El usuario no se encontró en la base de datos | ||
return redirect('/profile')->with('error', 'Usuario no encontrado'); | ||
} | ||
} | ||
|
||
} |
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
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,24 @@ | ||
<?php | ||
|
||
namespace App\Http\Middleware; | ||
|
||
use Closure; | ||
use Illuminate\Http\Request; | ||
use Symfony\Component\HttpFoundation\Response; | ||
|
||
class AdminMiddleware | ||
{ | ||
/** | ||
* Handle an incoming request. | ||
* | ||
* @param \Closure(\Illuminate\Http\Request): (\Symfony\Component\HttpFoundation\Response) $next | ||
*/ | ||
public function handle(Request $request, Closure $next): Response | ||
{ | ||
if (auth()->check() && auth()->user()->is_admin){ | ||
return $next($request); | ||
} else{ | ||
return redirect('/dashboard'); | ||
} | ||
} | ||
} |
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
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