Merge branch 'master' of https://github.com/csullcap/PIS-proyect
This commit is contained in:
commit
55d754e957
@ -14,17 +14,19 @@ class UserController extends Controller
|
||||
public function register(Request $request)
|
||||
{
|
||||
$request->validate([
|
||||
'email' => 'required|email|unique:users'
|
||||
'email' => 'required|email|unique:users',
|
||||
'rol'=> 'required|numeric|min:1|max:2'
|
||||
]);
|
||||
$userAuth = auth()->user()->roles[0]->name;
|
||||
if ($userAuth === "Admin") {
|
||||
if ($userAuth == "Admin") {
|
||||
$user = new User();
|
||||
$user->name = "null";
|
||||
$user->lastname = "null";
|
||||
$user->email = $request->email;
|
||||
$user->password = "null";
|
||||
$user->estado = true;
|
||||
$user->save();
|
||||
$user->roles()->attach(2);
|
||||
$user->roles()->attach($request->rol);
|
||||
return response()->json([
|
||||
'message' => 'Correo registrado exitosamente',
|
||||
'userAuth' => $user,
|
||||
@ -32,7 +34,7 @@ public function register(Request $request)
|
||||
} else {
|
||||
return response()->json([
|
||||
"status" => 0,
|
||||
"message" => "Correo no registrado",
|
||||
"message" => "No eres administrador: Correo no registrado",
|
||||
], 404);
|
||||
}
|
||||
}
|
||||
@ -78,6 +80,15 @@ public function userProfile()
|
||||
]);
|
||||
}
|
||||
|
||||
public function listUser(){
|
||||
$users = User::all();
|
||||
return response([
|
||||
"status" => 1,
|
||||
"msg" => "!Lista de usuarios",
|
||||
"data" => $users,
|
||||
]);
|
||||
}
|
||||
|
||||
public function logout()
|
||||
{
|
||||
auth()->user()->tokens()->delete();
|
||||
|
@ -5,7 +5,7 @@
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class role extends Model
|
||||
class Role extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
@ -43,7 +43,7 @@ public function providers()
|
||||
|
||||
public function roles()
|
||||
{
|
||||
return $this->belongsToMany(role::class, 'role_user', 'id_user', 'id_rol');
|
||||
return $this->belongsToMany(Role::class, 'role_user', 'id_user', 'id_rol');
|
||||
}
|
||||
|
||||
public function isAdmin()
|
||||
|
@ -17,7 +17,7 @@ class RoleFactory extends Factory
|
||||
public function definition()
|
||||
{
|
||||
return [
|
||||
'name' => $this->faker->name(),
|
||||
'name' => $this->faker->name(),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
@ -19,6 +19,7 @@ public function up()
|
||||
$table->string('lastname');
|
||||
$table->string('email')->unique();
|
||||
$table->string('password');
|
||||
$table->boolean('estado');
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -16,10 +16,10 @@ class DatabaseSeeder extends Seeder
|
||||
public function run()
|
||||
{
|
||||
//roles
|
||||
\App\Models\role::factory()->create([
|
||||
\App\Models\Role::factory()->create([
|
||||
"name"=>"Admin"
|
||||
]);
|
||||
\App\Models\role::factory()->create([
|
||||
\App\Models\Role::factory()->create([
|
||||
"name"=>"User"
|
||||
]);
|
||||
|
||||
@ -29,6 +29,7 @@ public function run()
|
||||
"lastname"=>"Apoyo",
|
||||
"email"=>"admin@unsa.edu.pe",
|
||||
"password"=>Hash::make("123456"),
|
||||
"estado"=>true,
|
||||
]);
|
||||
\App\Models\User::find(1)->roles()->attach(1);
|
||||
|
||||
@ -37,6 +38,7 @@ public function run()
|
||||
"lastname"=>"Arroyo",
|
||||
"email"=>"aarroyoh@unsa.edu.pe",
|
||||
"password"=>Hash::make("luisangel"),
|
||||
"estado"=>true,
|
||||
]);
|
||||
\App\Models\User::find(2)->roles()->attach(1);
|
||||
|
||||
@ -45,6 +47,7 @@ public function run()
|
||||
"lastname"=>"Araoz",
|
||||
"email"=>"faraoz@unsa.edu.pe",
|
||||
"password"=>Hash::make("123456"),
|
||||
"estado"=>true,
|
||||
]);
|
||||
\App\Models\User::find(3)->roles()->attach(1);
|
||||
|
||||
@ -53,6 +56,7 @@ public function run()
|
||||
"lastname"=>"Acuña",
|
||||
"email"=>"jacuna@unsa.edu.pe",
|
||||
"password"=>Hash::make("123456"),
|
||||
"estado"=>true,
|
||||
]);
|
||||
\App\Models\User::find(4)->roles()->attach(1);
|
||||
|
||||
@ -61,6 +65,7 @@ public function run()
|
||||
"lastname"=>"Gonzales",
|
||||
"email"=>"cgonzalesmo@unsa.edu.pe",
|
||||
"password"=>Hash::make("123456"),
|
||||
"estado"=>true,
|
||||
]);
|
||||
\App\Models\User::find(5)->roles()->attach(1);
|
||||
|
||||
@ -70,6 +75,7 @@ public function run()
|
||||
"lastname"=>"Sullca",
|
||||
"email"=>"csullcap@unsa.edu.pe",
|
||||
"password"=>Hash::make("123456"),
|
||||
"estado"=>true,
|
||||
]);
|
||||
\App\Models\User::find(6)->roles()->attach(1);
|
||||
|
||||
@ -78,6 +84,7 @@ public function run()
|
||||
"lastname"=>"Guillen",
|
||||
"email"=>"bguillenn@unsa.edu.pe",
|
||||
"password"=>Hash::make("123456"),
|
||||
"estado"=>true,
|
||||
]);
|
||||
\App\Models\User::find(7)->roles()->attach(1);
|
||||
|
||||
|
@ -41,6 +41,7 @@
|
||||
Route::middleware("auth:sanctum")->group(function () {
|
||||
//rutas auth
|
||||
Route::get('user-profile', [UserController::class, 'userProfile']);
|
||||
Route::get('user', [UserController::class, 'listUser']);
|
||||
Route::get('logout', [UserController::class, 'logout']);
|
||||
Route::post('register', [UserController::class, 'register']);
|
||||
|
||||
@ -116,6 +117,6 @@
|
||||
Route::get('narrativa', [NarrativasController::class, 'listNarrativas']);
|
||||
});
|
||||
|
||||
Route::middleware('auth:sanctum')->get('/user', function (Request $request) {
|
||||
/*Route::middleware('auth:sanctum')->get('/user', function (Request $request) {
|
||||
return $request->user();
|
||||
});
|
||||
});*/
|
||||
|
Loading…
Reference in New Issue
Block a user