I hope this helps
here i assume you have a "users" table with user data. your api username is same as the "users" table username field.
Controller function
public function login()
{
$password_api = VSE::user('password',$username);
$password = Input::get('password');
if ( $password == $password_api ):
if (Auth::attempt(['username' => $username, 'password' => $password])) {
// Authentication passed...
}
else{
// Authentication failed...
}
endif;
}
IF YOU DO NOT HAVE "users" TABLE.
i think the simple way is to create a session value when password matches and create a middleware/filter for that auth.
controller function
public function login()
{
$password_api = VSE::user('password',$username);
$password = Input::get('password');
if ( $password == $password_api ):
Session::put('api_auth','1')
endif;
}
to check if user is logged in
if(Session::get('api_auth')==1):
//logged in
endif;
Middleware creation
refer http://laravel.com/docs/5.0/middleware for more info
<?php
namespace App\Http\Middleware;
use Closure;
use Session;
class apiAuth
{
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
if (Session::get('api_auth') == 1) {
return $next($request);
}
if ($request->ajax()) {
return response('Unauthorized.', 401);
} else {
//no authentication';
return redirect()->route('login.page')->with('error','you need to login to view the page you requested');
}
}
}