PARAG-41 Store login with API
This commit is contained in:
parent
62b1895a34
commit
d7fe21bc80
@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Auth;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
|
||||
class StoreLoginController extends Controller
|
||||
{
|
||||
public function __construct(){
|
||||
$this->middleware('guest:store');
|
||||
}
|
||||
|
||||
public function showLoginForm(){
|
||||
return view('auth.store-login');
|
||||
}
|
||||
|
||||
public function login(Request $request){
|
||||
$this->validate($request, [
|
||||
'email' => 'required',
|
||||
'password' => 'required',
|
||||
]);
|
||||
|
||||
if(Auth::guard('store')->attempt([
|
||||
'email' => $request->email,
|
||||
'password' => $request->password], $request->remember))
|
||||
{
|
||||
return redirect()->intended(route('store.dashboard'));
|
||||
}
|
||||
|
||||
return redirect()->back();
|
||||
}
|
||||
|
||||
public function loginAPI(Request $request){
|
||||
$this->validate($request, [
|
||||
'email' => 'required',
|
||||
'password' => 'required',
|
||||
]);
|
||||
|
||||
if(Auth::guard('store')->attempt([
|
||||
'email' => $request->email,
|
||||
'password' => $request->password]))
|
||||
{
|
||||
return response()->json(["message " => "Accepted."], 200);
|
||||
}
|
||||
else{
|
||||
return response()->json(["message " => "Record not found."], 404);
|
||||
}
|
||||
}
|
||||
}
|
28
paragonik-backend/app/Http/Controllers/StoreController.php
Normal file
28
paragonik-backend/app/Http/Controllers/StoreController.php
Normal file
@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class StoreController extends Controller
|
||||
{
|
||||
/**
|
||||
* Create a new controller instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->middleware('auth:store');
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the application dashboard.
|
||||
*
|
||||
* @return \Illuminate\Contracts\Support\Renderable
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
return view('store');
|
||||
}
|
||||
}
|
@ -2,10 +2,44 @@
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Notifications\Notifiable;
|
||||
use Illuminate\Contracts\Auth\MustVerifyEmail;
|
||||
use Illuminate\Foundation\Auth\User as Authenticatable;
|
||||
|
||||
class Store extends Model
|
||||
class Store extends Authenticatable
|
||||
{
|
||||
use Notifiable;
|
||||
|
||||
protected $guard = 'store';
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $fillable = [
|
||||
'name', 'email', 'password',
|
||||
];
|
||||
|
||||
/**
|
||||
* The attributes that should be hidden for arrays.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $hidden = [
|
||||
'password', 'remember_token',
|
||||
];
|
||||
|
||||
/**
|
||||
* The attributes that should be cast to native types.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $casts = [
|
||||
'email_verified_at' => 'datetime',
|
||||
];
|
||||
|
||||
|
||||
public function post()
|
||||
{
|
||||
return $this->hasMany('App\Models\Receipt');
|
||||
|
@ -40,11 +40,17 @@ return [
|
||||
'driver' => 'session',
|
||||
'provider' => 'users',
|
||||
],
|
||||
|
||||
'api' => [
|
||||
'driver' => 'token',
|
||||
'driver' => 'session',
|
||||
'provider' => 'users',
|
||||
'hash' => false,
|
||||
],
|
||||
'store' => [
|
||||
'driver' => 'session',
|
||||
'provider' => 'stores',
|
||||
],
|
||||
'store-api' => [
|
||||
'driver' => 'session',
|
||||
'provider' => 'stores',
|
||||
],
|
||||
],
|
||||
|
||||
@ -71,10 +77,10 @@ return [
|
||||
'model' => App\User::class,
|
||||
],
|
||||
|
||||
// 'users' => [
|
||||
// 'driver' => 'database',
|
||||
// 'table' => 'users',
|
||||
// ],
|
||||
'stores' => [
|
||||
'driver' => 'eloquent',
|
||||
'model' => App\Models\Store::class,
|
||||
],
|
||||
],
|
||||
|
||||
/*
|
||||
@ -98,6 +104,11 @@ return [
|
||||
'table' => 'password_resets',
|
||||
'expire' => 60,
|
||||
],
|
||||
'stores' => [
|
||||
'provider' => 'stores',
|
||||
'table' => 'password_resets',
|
||||
'expire' => 60,
|
||||
],
|
||||
],
|
||||
|
||||
];
|
||||
|
@ -13,15 +13,19 @@ use Illuminate\Http\Request;
|
||||
|
|
||||
*/
|
||||
|
||||
#Route::apiResource('/receipt', 'ReceiptController');
|
||||
Route::prefix('user')->group(function(){
|
||||
Route::post('login', 'Auth\LoginController@loginAPI');
|
||||
Route::post('register', 'Auth\RegisterController@createAPI');
|
||||
});
|
||||
|
||||
Route::post('register', 'Auth\RegisterController@create');
|
||||
Route::prefix('store')->group(function(){
|
||||
Route::post('login', 'Auth\StoreLoginController@loginAPI');
|
||||
Route::post('register', 'Auth\StoreRegisterController@createAPI');
|
||||
});
|
||||
|
||||
Route::middleware('auth:api')->get('/user', function (Request $request) {
|
||||
return $request->user();
|
||||
});
|
||||
|
||||
Route::post('register', 'Auth\RegisterController@create');
|
||||
|
||||
Route::apiResource('receiptItem', 'ReceiptItemController');
|
||||
Route::apiResource('receipt', 'ReceiptController');
|
Loading…
Reference in New Issue
Block a user