login
This commit is contained in:
@ -20,6 +20,7 @@ class AdminThemeController extends AdminController
|
||||
public function actionIndex(): void
|
||||
{
|
||||
$admin_theme_paths = Option::where("key", "admin_theme_paths")->first();
|
||||
|
||||
$dirs = [];
|
||||
if ($admin_theme_paths){
|
||||
$path = json_decode($admin_theme_paths->value);
|
||||
|
@ -14,9 +14,9 @@ $table->columns([
|
||||
]);
|
||||
$table->addAction(function ($row, $url){
|
||||
$path = $row['path'];
|
||||
$active_admin_theme = Option::where("key", "active_admin_theme")->first();
|
||||
$active_admin_theme = \kernel\modules\option\service\OptionService::getItem('active_admin_theme');
|
||||
$btn = "<a class='btn btn-primary' href='$url/activate/?p=$path' style='margin: 3px; width: 150px;' >Активировать</a>";
|
||||
if ($path === $active_admin_theme->value){
|
||||
if ($path === $active_admin_theme){
|
||||
$btn = "Активна";
|
||||
}
|
||||
|
||||
|
@ -49,6 +49,20 @@ class OptionService
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $key
|
||||
* @return false|array|string
|
||||
*/
|
||||
public static function getItem($key): false|array|string
|
||||
{
|
||||
$item = Option::where("key", $key)->first();
|
||||
if ($item){
|
||||
return getConst($item->value);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// public function createOptionArr(): array
|
||||
// {
|
||||
// foreach (Option::all()->toArray() as $option) {
|
||||
|
@ -7,10 +7,13 @@ use Illuminate\Database\Eloquent\Model;
|
||||
* @property string $username
|
||||
* @property string $email
|
||||
* @property string $password_hash
|
||||
* @method static where(int[] $array)
|
||||
* @method static find($id)
|
||||
*/
|
||||
class User extends Model {
|
||||
|
||||
const DEFAULT_USER_ROLE = 1;
|
||||
const ADMIN_USER_ROLE = 9;
|
||||
|
||||
protected $table = 'user';
|
||||
protected $fillable = ['username', 'email', 'password_hash', 'role'];
|
||||
protected array $dates = ['deleted at'];
|
||||
|
@ -33,6 +33,11 @@ class UserService
|
||||
return false;
|
||||
}
|
||||
|
||||
public function getByField(string $field, string $value)
|
||||
{
|
||||
return User::where($field, $value)->first();
|
||||
}
|
||||
|
||||
public static function createUsernameArr(): array
|
||||
{
|
||||
foreach (User::all()->toArray() as $user) {
|
||||
@ -45,4 +50,26 @@ class UserService
|
||||
return [];
|
||||
}
|
||||
|
||||
public static function getAuthUser()
|
||||
{
|
||||
if (isset($_COOKIE['user_id'])){
|
||||
$user = User::where("id", $_COOKIE['user_id'])->first();
|
||||
if ($user){
|
||||
return $user;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static function getAuthUsername(): string
|
||||
{
|
||||
$user = self::getAuthUser();
|
||||
if ($user){
|
||||
return $user->username;
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user