2015-11-03 05:13:32 +01:00
|
|
|
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
|
|
|
|
use Laravel\Lumen\Routing\Controller as BaseController;
|
|
|
|
|
2015-11-04 02:56:03 +01:00
|
|
|
use Illuminate\Http\Request;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
|
|
|
|
|
|
|
|
|
|
class Controller extends BaseController {
|
2016-02-13 21:59:51 +01:00
|
|
|
protected static function currIsAdmin() {
|
2015-12-12 18:26:25 +01:00
|
|
|
$role = session('role');
|
|
|
|
if ($role == 'admin') {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-02-13 21:59:51 +01:00
|
|
|
protected static function isLoggedIn() {
|
2015-12-12 18:26:25 +01:00
|
|
|
$username = session('username');
|
|
|
|
if (!isset($username)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2016-02-12 17:20:33 +01:00
|
|
|
|
|
|
|
protected static function checkRequiredArgs($required_args=[]) {
|
|
|
|
array_push($required_args, NULL);
|
|
|
|
|
|
|
|
if (count(array_unique($required_args)) < count($required_args)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return true;
|
|
|
|
}
|
2016-02-13 21:59:51 +01:00
|
|
|
}
|
2016-02-12 17:20:33 +01:00
|
|
|
|
2016-02-13 21:59:51 +01:00
|
|
|
protected static function ensureAdmin() {
|
|
|
|
if (!self::currIsAdmin()) {
|
|
|
|
abort(401, 'User not admin.');
|
|
|
|
}
|
|
|
|
return true;
|
2016-02-12 17:20:33 +01:00
|
|
|
}
|
2015-11-03 05:13:32 +01:00
|
|
|
}
|