Correcion loginController
This commit is contained in:
parent
e639083512
commit
e62d40a220
@ -2,14 +2,9 @@
|
|||||||
|
|
||||||
namespace App\Http\Controllers\api;
|
namespace App\Http\Controllers\api;
|
||||||
|
|
||||||
use App\Http\Controllers\Controller;;
|
use App\Http\Controllers\Controller;
|
||||||
|
|
||||||
use Laravel\Socialite\Facades\Socialite;
|
use Laravel\Socialite\Facades\Socialite;
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
use GuzzleHttp\Exception\ClientException;
|
|
||||||
use Illuminate\Support\Facades\Auth;
|
|
||||||
use Illuminate\Http\Request;
|
|
||||||
|
|
||||||
|
|
||||||
class LoginController extends Controller
|
class LoginController extends Controller
|
||||||
{
|
{
|
||||||
|
@ -7,15 +7,17 @@
|
|||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
use App\Models\Estandar;
|
use App\Models\Estandar;
|
||||||
use Illuminate\Support\Facades\Hash;
|
use Illuminate\Support\Facades\Hash;
|
||||||
|
use Illuminate\Support\Facades\Auth;
|
||||||
|
|
||||||
class UserController extends Controller
|
class UserController extends Controller
|
||||||
{
|
{
|
||||||
public function register(Request $request){
|
public function register(Request $request)
|
||||||
|
{
|
||||||
$request->validate([
|
$request->validate([
|
||||||
'email'=>'required|email|unique:users'
|
'email' => 'required|email|unique:users'
|
||||||
]);
|
]);
|
||||||
$userAuth = auth()->user()->roles[0]->name;
|
$userAuth = auth()->user()->roles[0]->name;
|
||||||
if($userAuth==="Admin"){
|
if ($userAuth === "Admin") {
|
||||||
$user = new User();
|
$user = new User();
|
||||||
$user->name = "null";
|
$user->name = "null";
|
||||||
$user->lastname = "null";
|
$user->lastname = "null";
|
||||||
@ -24,30 +26,29 @@ public function register(Request $request){
|
|||||||
$user->save();
|
$user->save();
|
||||||
$user->roles()->attach(2);
|
$user->roles()->attach(2);
|
||||||
return response()->json([
|
return response()->json([
|
||||||
'message'=>'Correo registrado exitosamente',
|
'message' => 'Correo registrado exitosamente',
|
||||||
'userAuth'=>$user,
|
'userAuth' => $user,
|
||||||
]);
|
]);
|
||||||
}
|
} else {
|
||||||
else{
|
|
||||||
return response()->json([
|
return response()->json([
|
||||||
"status" => 0,
|
"status" => 0,
|
||||||
"message" => "Correo no registrado",
|
"message" => "Correo no registrado",
|
||||||
], 404);
|
], 404);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function login(Request $request){
|
public function login(Request $request)
|
||||||
|
{
|
||||||
|
|
||||||
$request->validate([
|
$request->validate([
|
||||||
"email" => "required|email",
|
"email" => "required|email",
|
||||||
"password" => "required"
|
"password" => "required"
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$user = User::where("email","=", $request->email)->first();
|
$user = User::where("email", "=", $request->email)->first();
|
||||||
|
|
||||||
if(isset($user->id) ){
|
if (isset($user->id)) {
|
||||||
if(Hash::check($request->password, $user->password)){
|
if (Hash::check($request->password, $user->password)) {
|
||||||
$token = $user->createToken("auth_token")->plainTextToken;
|
$token = $user->createToken("auth_token")->plainTextToken;
|
||||||
return response()->json([
|
return response()->json([
|
||||||
"message" => "Usuario logueado",
|
"message" => "Usuario logueado",
|
||||||
@ -55,13 +56,12 @@ public function login(Request $request){
|
|||||||
"nombre" => $user->name,
|
"nombre" => $user->name,
|
||||||
"apellido" => $user->lastname,
|
"apellido" => $user->lastname,
|
||||||
]);
|
]);
|
||||||
}else{
|
} else {
|
||||||
return response()->json([
|
return response()->json([
|
||||||
"message" => "La password es incorrecta",
|
"message" => "La password es incorrecta",
|
||||||
], 404);
|
], 404);
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
}else{
|
|
||||||
return response()->json([
|
return response()->json([
|
||||||
"status" => 0,
|
"status" => 0,
|
||||||
"message" => "Usuario no registrado",
|
"message" => "Usuario no registrado",
|
||||||
@ -69,7 +69,8 @@ public function login(Request $request){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function userProfile(){
|
public function userProfile()
|
||||||
|
{
|
||||||
return response()->json([
|
return response()->json([
|
||||||
"status" => 0,
|
"status" => 0,
|
||||||
"message" => "Perfil de usuario",
|
"message" => "Perfil de usuario",
|
||||||
@ -77,12 +78,11 @@ public function userProfile(){
|
|||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function logout(){
|
public function logout()
|
||||||
|
{
|
||||||
auth()->user()->tokens()->delete();
|
auth()->user()->tokens()->delete();
|
||||||
return response()->json([
|
return response()->json([
|
||||||
"status" => 1,
|
"message" => "Sesion cerrada"
|
||||||
"message" => "Cierre de Sesión",
|
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
26
composer.lock
generated
26
composer.lock
generated
@ -478,23 +478,23 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "doctrine/inflector",
|
"name": "doctrine/inflector",
|
||||||
"version": "2.0.5",
|
"version": "2.0.6",
|
||||||
"source": {
|
"source": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://github.com/doctrine/inflector.git",
|
"url": "https://github.com/doctrine/inflector.git",
|
||||||
"reference": "ade2b3bbfb776f27f0558e26eed43b5d9fe1b392"
|
"reference": "d9d313a36c872fd6ee06d9a6cbcf713eaa40f024"
|
||||||
},
|
},
|
||||||
"dist": {
|
"dist": {
|
||||||
"type": "zip",
|
"type": "zip",
|
||||||
"url": "https://api.github.com/repos/doctrine/inflector/zipball/ade2b3bbfb776f27f0558e26eed43b5d9fe1b392",
|
"url": "https://api.github.com/repos/doctrine/inflector/zipball/d9d313a36c872fd6ee06d9a6cbcf713eaa40f024",
|
||||||
"reference": "ade2b3bbfb776f27f0558e26eed43b5d9fe1b392",
|
"reference": "d9d313a36c872fd6ee06d9a6cbcf713eaa40f024",
|
||||||
"shasum": ""
|
"shasum": ""
|
||||||
},
|
},
|
||||||
"require": {
|
"require": {
|
||||||
"php": "^7.2 || ^8.0"
|
"php": "^7.2 || ^8.0"
|
||||||
},
|
},
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
"doctrine/coding-standard": "^9",
|
"doctrine/coding-standard": "^10",
|
||||||
"phpstan/phpstan": "^1.8",
|
"phpstan/phpstan": "^1.8",
|
||||||
"phpstan/phpstan-phpunit": "^1.1",
|
"phpstan/phpstan-phpunit": "^1.1",
|
||||||
"phpstan/phpstan-strict-rules": "^1.3",
|
"phpstan/phpstan-strict-rules": "^1.3",
|
||||||
@ -549,7 +549,7 @@
|
|||||||
],
|
],
|
||||||
"support": {
|
"support": {
|
||||||
"issues": "https://github.com/doctrine/inflector/issues",
|
"issues": "https://github.com/doctrine/inflector/issues",
|
||||||
"source": "https://github.com/doctrine/inflector/tree/2.0.5"
|
"source": "https://github.com/doctrine/inflector/tree/2.0.6"
|
||||||
},
|
},
|
||||||
"funding": [
|
"funding": [
|
||||||
{
|
{
|
||||||
@ -565,7 +565,7 @@
|
|||||||
"type": "tidelift"
|
"type": "tidelift"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"time": "2022-09-07T09:01:28+00:00"
|
"time": "2022-10-20T09:10:12+00:00"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "doctrine/lexer",
|
"name": "doctrine/lexer",
|
||||||
@ -1317,16 +1317,16 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "laravel/framework",
|
"name": "laravel/framework",
|
||||||
"version": "v9.36.3",
|
"version": "v9.36.4",
|
||||||
"source": {
|
"source": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://github.com/laravel/framework.git",
|
"url": "https://github.com/laravel/framework.git",
|
||||||
"reference": "80ba0561b3682b96743e1c152fde0698bbdb2412"
|
"reference": "15ce569fd93124e8e2257c24e3ed85b9ef9951d6"
|
||||||
},
|
},
|
||||||
"dist": {
|
"dist": {
|
||||||
"type": "zip",
|
"type": "zip",
|
||||||
"url": "https://api.github.com/repos/laravel/framework/zipball/80ba0561b3682b96743e1c152fde0698bbdb2412",
|
"url": "https://api.github.com/repos/laravel/framework/zipball/15ce569fd93124e8e2257c24e3ed85b9ef9951d6",
|
||||||
"reference": "80ba0561b3682b96743e1c152fde0698bbdb2412",
|
"reference": "15ce569fd93124e8e2257c24e3ed85b9ef9951d6",
|
||||||
"shasum": ""
|
"shasum": ""
|
||||||
},
|
},
|
||||||
"require": {
|
"require": {
|
||||||
@ -1338,7 +1338,7 @@
|
|||||||
"fruitcake/php-cors": "^1.2",
|
"fruitcake/php-cors": "^1.2",
|
||||||
"laravel/serializable-closure": "^1.2.2",
|
"laravel/serializable-closure": "^1.2.2",
|
||||||
"league/commonmark": "^2.2",
|
"league/commonmark": "^2.2",
|
||||||
"league/flysystem": "^3.0.16",
|
"league/flysystem": "^3.8.0",
|
||||||
"monolog/monolog": "^2.0",
|
"monolog/monolog": "^2.0",
|
||||||
"nesbot/carbon": "^2.62.1",
|
"nesbot/carbon": "^2.62.1",
|
||||||
"nunomaduro/termwind": "^1.13",
|
"nunomaduro/termwind": "^1.13",
|
||||||
@ -1499,7 +1499,7 @@
|
|||||||
"issues": "https://github.com/laravel/framework/issues",
|
"issues": "https://github.com/laravel/framework/issues",
|
||||||
"source": "https://github.com/laravel/framework"
|
"source": "https://github.com/laravel/framework"
|
||||||
},
|
},
|
||||||
"time": "2022-10-19T13:23:53+00:00"
|
"time": "2022-10-20T16:11:03+00:00"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "laravel/sanctum",
|
"name": "laravel/sanctum",
|
||||||
|
Loading…
Reference in New Issue
Block a user