Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Translated the project to english #8

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 17 additions & 17 deletions src/plugin/admin/api/Auth.php
Original file line number Diff line number Diff line change
@@ -7,13 +7,13 @@
use function admin;

/**
* 对外提供的鉴权接口
* Authentication interface provided externally
*/
class Auth
{
/**
* 判断权限
* 如果没有权限则抛出异常
* judgment authority
* Throw exception if no permission
*
* @param string $controller
* @param string $action
@@ -30,7 +30,7 @@ public static function access(string $controller, string $action)
}

/**
* 判断是否有权限
* Determine whether there is permission
*
* @param string $controller
* @param string $action
@@ -41,40 +41,40 @@ public static function access(string $controller, string $action)
*/
public static function canAccess(string $controller, string $action, int &$code = 0, string &$msg = '')
{
// 获取控制器鉴权信息
// Get controller authentication information
$class = new \ReflectionClass($controller);
$properties = $class->getDefaultProperties();
$noNeedLogin = $properties['noNeedLogin'] ?? [];
$noNeedAuth = $properties['noNeedAuth'] ?? [];

// 不需要登录
// No login required
if (in_array($action, $noNeedLogin)) {
return true;
}

// 获取登录信息
// Get login information
$admin = admin();
if (!$admin) {
$msg = '请登录';
// 401是未登录固定的返回码
$msg = 'please sign in';
// 401is not logged in fixed return code
$code = 401;
return false;
}

// 不需要鉴权
// No authentication required
if (in_array($action, $noNeedAuth)) {
return true;
}

// 当前管理员无角色
// Current administrator has no role
$roles = $admin['roles'];
if (!$roles) {
$msg = '无权限';
$msg = 'No permission';
$code = 2;
return false;
}

// 角色没有规则
// Role has no rules
$rules = AdminRole::whereIn('id', $roles)->pluck('rules');
$rule_ids = [];
foreach ($rules as $rule_string) {
@@ -84,23 +84,23 @@ public static function canAccess(string $controller, string $action, int &$code
$rule_ids = array_merge($rule_ids, explode(',', $rule_string));
}
if (!$rule_ids) {
$msg = '无权限';
$msg = 'No permission';
$code = 2;
return false;
}

// 超级管理员
// Super Admin
if (in_array('*', $rule_ids)){
return true;
}

// 没有当前控制器的规则
// No rules for current controller
$rule = AdminRule::where(function ($query) use ($controller, $action) {
$query->where('name', "$controller@$action")->orWhere('name', $controller);
})->whereIn('id', $rule_ids)->first();

if (!$rule) {
$msg = '无权限';
$msg = 'No permission';
$code = 2;
return false;
}
22 changes: 11 additions & 11 deletions src/plugin/admin/api/Install.php
Original file line number Diff line number Diff line change
@@ -5,33 +5,33 @@
class Install
{
/**
* 安装
* Install
*
* @param $version
* @return void
*/
public static function install($version)
{
// 导入菜单
// Import menu
Menu::import(static::getMenus());
}

/**
* 卸载
* Uninstall
*
* @param $version
* @return void
*/
public static function uninstall($version)
{
// 删除菜单
// Delete menu
foreach (static::getMenus() as $menu) {
Menu::delete($menu['name']);
}
}

/**
* 更新
* renew
*
* @param $from_version
* @param $to_version
@@ -40,29 +40,29 @@ public static function uninstall($version)
*/
public static function update($from_version, $to_version, $context = null)
{
// 删除不用的菜单
// Delete unused menus
if (isset($context['previous_menus'])) {
static::removeUnnecessaryMenus($context['previous_menus']);
}
// 导入新菜单
// Import new menu
Menu::import(static::getMenus());
}

/**
* 更新前数据收集等
* Data collection before update etc
*
* @param $from_version
* @param $to_version
* @return array|array[]
*/
public static function beforeUpdate($from_version, $to_version)
{
// 在更新之前获得老菜单,通过context传递给 update
// Get the old menu before updating, passed the context to update
return ['previous_menus' => static::getMenus()];
}

/**
* 获取菜单
* Get menu
*
* @return array|mixed
*/
@@ -77,7 +77,7 @@ public static function getMenus()
}

/**
* 删除不需要的菜单
* Remove unwanted menus
*
* @param $previous_menus
* @return void
16 changes: 8 additions & 8 deletions src/plugin/admin/api/Menu.php
Original file line number Diff line number Diff line change
@@ -7,13 +7,13 @@
use function admin;

/**
* 对外提供的菜单接口
* Externally provided menu interface
*/
class Menu
{

/**
* 根据名字获得菜单
* Get menu by name
*
* @param $name
* @return array
@@ -25,7 +25,7 @@ public static function get($name)
}

/**
* 根据id获得菜单
* Get menu by id
*
* @param $id
* @return array
@@ -36,7 +36,7 @@ public static function find($id)
}

/**
* 添加菜单
* Add menu
*
* @param array $menu
* @return int
@@ -55,7 +55,7 @@ public static function add(array $menu)
}

/**
* 导入菜单
* Import menu
*
* @param array $menu_tree
* @return void
@@ -83,7 +83,7 @@ public static function import(array $menu_tree)
}

/**
* 删除菜单
* Delete menu
*
* @param $name
* @return void
@@ -94,7 +94,7 @@ public static function delete($name)
if (!$item) {
return;
}
// 子规则一起删除
// Sub-rules are deleted together
$delete_ids = $children_ids = [$item['id']];
while($children_ids) {
$children_ids = AdminRule::whereIn('pid', $children_ids)->pluck('id')->toArray();
@@ -105,7 +105,7 @@ public static function delete($name)


/**
* 获取菜单中某个(些)字段的值
* Get the value of a field(s) in the menu
*
* @param $menus
* @param $column
2 changes: 1 addition & 1 deletion src/plugin/admin/api/Middleware.php
Original file line number Diff line number Diff line change
@@ -8,7 +8,7 @@
use Webman\MiddlewareInterface;

/**
* 对外提供的中间件
* Externally provided middleware
*/
class Middleware implements MiddlewareInterface
{
4 changes: 2 additions & 2 deletions src/plugin/admin/app/Util.php
Original file line number Diff line number Diff line change
@@ -31,7 +31,7 @@ static public function passwordVerify($password, $hash)
static public function checkTableName($table)
{
if (!preg_match('/^[a-zA-Z_0-9]+$/', $table)) {
throw new BusinessException('表名不合法');
throw new BusinessException('The table name is invalid');
}
return true;
}
@@ -71,7 +71,7 @@ public static function getCommentFirstLine($comment)
public static function methodControlMap()
{
return [
//method=>[控件]
//method=>[Controls]
'integer' => ['InputNumber'],
'string' => ['Input'],
'text' => ['InputTextArea'],
8 changes: 4 additions & 4 deletions src/plugin/admin/app/controller/Base.php
Original file line number Diff line number Diff line change
@@ -7,25 +7,25 @@
use support\Request;

/**
* 基础控制器
* Basic Controller
*/
class Base
{

/**
* 无需登录的方法及鉴权
* Method and authentication without login
* @var array
*/
protected $noNeedLogin = [];

/**
* 需要登录无需鉴权的方法
* Requires login without authentication method
* @var array
*/
protected $noNeedAuth = [];

/**
* 返回格式化json数据
* return formatted json data
*
* @param int $code
* @param string $msg
Loading