diff --git a/app/Events/CheckUserPassword.php b/app/Events/CheckUserPassword.php
new file mode 100644
index 00000000..7003772e
--- /dev/null
+++ b/app/Events/CheckUserPassword.php
@@ -0,0 +1,24 @@
+rawPasswd = $raw_passwd;
+ $this->user = $user;
+ }
+
+}
diff --git a/app/Events/PlayerInstantiated.php b/app/Events/PlayerInstantiated.php
new file mode 100644
index 00000000..8aaa2fa7
--- /dev/null
+++ b/app/Events/PlayerInstantiated.php
@@ -0,0 +1,7 @@
+uid = $uid;
+ }
+
+}
diff --git a/app/Events/UserLoggedIn.php b/app/Events/UserLoggedIn.php
new file mode 100644
index 00000000..f738dedf
--- /dev/null
+++ b/app/Events/UserLoggedIn.php
@@ -0,0 +1,23 @@
+user = $user;
+ }
+
+}
diff --git a/app/Events/UserTryToLogin.php b/app/Events/UserTryToLogin.php
new file mode 100644
index 00000000..b6bd015a
--- /dev/null
+++ b/app/Events/UserTryToLogin.php
@@ -0,0 +1,26 @@
+identification = $identification;
+ $this->auth_type = $auth_type;
+ }
+
+}
diff --git a/app/Http/Controllers/AdminController.php b/app/Http/Controllers/AdminController.php
index d0ee6838..41f6b961 100644
--- a/app/Http/Controllers/AdminController.php
+++ b/app/Http/Controllers/AdminController.php
@@ -70,6 +70,7 @@ class AdminController extends Controller
$id = $request->get('id');
if ($plugins->getPlugins()->has($id)) {
+ $plugin = $plugins->getPlugin($id);
switch ($request->get('action')) {
case 'enable':
$plugins->enable($id);
@@ -87,6 +88,15 @@ class AdminController extends Controller
}
break;
+ case 'config':
+ if ($plugin->isEnabled() && $plugin->hasConfigView()) {
+ return View::file($plugin->getViewPath('config'));
+ } else {
+ abort(404);
+ }
+
+ break;
+
default:
# code...
break;
diff --git a/app/Http/Controllers/AuthController.php b/app/Http/Controllers/AuthController.php
index aeae2505..4da80062 100644
--- a/app/Http/Controllers/AuthController.php
+++ b/app/Http/Controllers/AuthController.php
@@ -30,6 +30,8 @@ class AuthController extends Controller
$auth_type = (validate($request->input('identification'), 'email')) ? "email" : "username";
+ event(new \App\Events\UserTryToLogin($identification, $auth_type));
+
// instantiate user
$user = new User(null, [$auth_type => $identification]);
@@ -52,6 +54,8 @@ class AuthController extends Controller
setcookie('uid', $user->uid, time()+$time, '/');
setcookie('token', $user->getToken(), time()+$time, '/');
+ event(new \App\Events\UserLoggedIn($user));
+
return json(trans('auth.login.success'), 0, [
'token' => $user->getToken()
]);
diff --git a/app/Models/User.php b/app/Models/User.php
index b25e24f3..a4b2306b 100644
--- a/app/Models/User.php
+++ b/app/Models/User.php
@@ -50,6 +50,8 @@ class User
*/
public function __construct($uid, Array $info = [])
{
+ event(new \App\Events\UserInstantiated($uid));
+
// Construct user with uid|email|player_name
if ($uid !== null) {
$this->uid = $uid;
@@ -83,7 +85,13 @@ class User
public function checkPasswd($raw_passwd)
{
- return ($this->cipher->encrypt($raw_passwd, config('secure.salt')) == $this->password);
+ $responses = event(new \App\Events\CheckUserPassword($raw_passwd, $this));
+
+ if (isset($responses[0])) {
+ return (bool) $responses[0];
+ } else {
+ return ($this->cipher->encrypt($raw_passwd, config('secure.salt')) == $this->password);
+ }
}
public function changePasswd($new_passwd)
diff --git a/app/Services/OptionRepository.php b/app/Services/OptionRepository.php
index 86b5e27b..5f3d8ac2 100644
--- a/app/Services/OptionRepository.php
+++ b/app/Services/OptionRepository.php
@@ -49,9 +49,10 @@ class OptionRepository implements ArrayAccess, ConfigContract
*
* @param string $key
* @param mixed $default
+ * @param bool $bool convert '0', '1' to bool value
* @return mixed
*/
- public function get($key, $default = null)
+ public function get($key, $default = null, $bool = true)
{
if (!$this->has($key) && Arr::has(config('options'), $key)) {
$this->set($key, config("options.$key"));
@@ -59,19 +60,25 @@ class OptionRepository implements ArrayAccess, ConfigContract
$value = Arr::get($this->items, $key, $default);
+ if (!$bool) return $value;
+
switch (strtolower($value)) {
case 'true':
case '1':
return true;
+
case 'false':
case '0':
return false;
+
case 'null':
case '(null)':
return;
- }
- return $value;
+ default:
+ return $value;
+ break;
+ }
}
/**
@@ -152,6 +159,19 @@ class OptionRepository implements ArrayAccess, ConfigContract
return $this->items;
}
+ public function only(Array $array)
+ {
+ $result = [];
+
+ foreach ($this->items as $key => $value) {
+ if (in_array($key, $array)) {
+ $result[$key] = $value;
+ }
+ }
+
+ return $result;
+ }
+
/**
* Determine if the given option option exists.
*
diff --git a/app/Services/Plugin.php b/app/Services/Plugin.php
index 5338da86..7e5ce819 100644
--- a/app/Services/Plugin.php
+++ b/app/Services/Plugin.php
@@ -121,6 +121,15 @@ class Plugin implements Arrayable
return $this->installed;
}
+ public function getViewPath($name) {
+ return $this->path."/views/$name.tpl";
+ }
+
+ public function hasConfigView()
+ {
+ return file_exists($this->getViewPath('config'));
+ }
+
/**
* @param string $version
* @return Plugin
diff --git a/resources/views/admin/plugins.tpl b/resources/views/admin/plugins.tpl
index 0302f9c0..aa50e12e 100644
--- a/resources/views/admin/plugins.tpl
+++ b/resources/views/admin/plugins.tpl
@@ -60,7 +60,12 @@
启用插件
@endif
+ @if ($plugin->isEnabled() && $plugin->hasConfigView())
插件配置
+ @else
+ 插件配置
+ @endif
+
删除插件