PARAG-41 Store login with API

This commit is contained in:
s152483 2019-12-16 13:00:42 +01:00
parent 62b1895a34
commit d7fe21bc80
5 changed files with 142 additions and 13 deletions

View File

@ -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);
}
}
}

View 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');
}
}

View File

@ -2,10 +2,44 @@
namespace App\Models; 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() public function post()
{ {
return $this->hasMany('App\Models\Receipt'); return $this->hasMany('App\Models\Receipt');

View File

@ -40,11 +40,17 @@ return [
'driver' => 'session', 'driver' => 'session',
'provider' => 'users', 'provider' => 'users',
], ],
'api' => [ 'api' => [
'driver' => 'token', 'driver' => 'session',
'provider' => 'users', 'provider' => 'users',
'hash' => false, ],
'store' => [
'driver' => 'session',
'provider' => 'stores',
],
'store-api' => [
'driver' => 'session',
'provider' => 'stores',
], ],
], ],
@ -71,10 +77,10 @@ return [
'model' => App\User::class, 'model' => App\User::class,
], ],
// 'users' => [ 'stores' => [
// 'driver' => 'database', 'driver' => 'eloquent',
// 'table' => 'users', 'model' => App\Models\Store::class,
// ], ],
], ],
/* /*
@ -98,6 +104,11 @@ return [
'table' => 'password_resets', 'table' => 'password_resets',
'expire' => 60, 'expire' => 60,
], ],
'stores' => [
'provider' => 'stores',
'table' => 'password_resets',
'expire' => 60,
],
], ],
]; ];

View File

@ -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) { Route::middleware('auth:api')->get('/user', function (Request $request) {
return $request->user(); return $request->user();
}); });
Route::post('register', 'Auth\RegisterController@create');
Route::apiResource('receiptItem', 'ReceiptItemController'); Route::apiResource('receiptItem', 'ReceiptItemController');
Route::apiResource('receipt', 'ReceiptController'); Route::apiResource('receipt', 'ReceiptController');