working on data adaptation
This commit is contained in:
parent
55414072e7
commit
d6e810da4a
24
app/Events/CheckUserPassword.php
Normal file
24
app/Events/CheckUserPassword.php
Normal file
@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace App\Events;
|
||||
|
||||
use App\Models\User;
|
||||
|
||||
class CheckUserPassword extends Event
|
||||
{
|
||||
public $rawPasswd;
|
||||
|
||||
public $user;
|
||||
|
||||
/**
|
||||
* Create a new event instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($raw_passwd, User $user)
|
||||
{
|
||||
$this->rawPasswd = $raw_passwd;
|
||||
$this->user = $user;
|
||||
}
|
||||
|
||||
}
|
7
app/Events/PlayerInstantiated.php
Normal file
7
app/Events/PlayerInstantiated.php
Normal file
@ -0,0 +1,7 @@
|
||||
<?php
|
||||
/**
|
||||
* @Author: printempw
|
||||
* @Date: 2016-10-17 14:12:54
|
||||
* @Last Modified by: printempw
|
||||
* @Last Modified time: 2016-10-17 14:13:00
|
||||
*/
|
23
app/Events/UserInstantiated.php
Normal file
23
app/Events/UserInstantiated.php
Normal file
@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace App\Events;
|
||||
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
class UserInstantiated extends Event
|
||||
{
|
||||
use SerializesModels;
|
||||
|
||||
public $uid;
|
||||
|
||||
/**
|
||||
* Create a new event instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($uid)
|
||||
{
|
||||
$this->uid = $uid;
|
||||
}
|
||||
|
||||
}
|
23
app/Events/UserLoggedIn.php
Normal file
23
app/Events/UserLoggedIn.php
Normal file
@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace App\Events;
|
||||
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
class UserLoggedIn extends Event
|
||||
{
|
||||
use SerializesModels;
|
||||
|
||||
public $user;
|
||||
|
||||
/**
|
||||
* Create a new event instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(\App\Models\User $user)
|
||||
{
|
||||
$this->user = $user;
|
||||
}
|
||||
|
||||
}
|
26
app/Events/UserTryToLogin.php
Normal file
26
app/Events/UserTryToLogin.php
Normal file
@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace App\Events;
|
||||
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
class UserTryToLogin extends Event
|
||||
{
|
||||
use SerializesModels;
|
||||
|
||||
public $identification;
|
||||
|
||||
public $auth_type;
|
||||
|
||||
/**
|
||||
* Create a new event instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($identification, $auth_type)
|
||||
{
|
||||
$this->identification = $identification;
|
||||
$this->auth_type = $auth_type;
|
||||
}
|
||||
|
||||
}
|
@ -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;
|
||||
|
@ -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()
|
||||
]);
|
||||
|
@ -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)
|
||||
|
@ -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.
|
||||
*
|
||||
|
@ -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
|
||||
|
@ -60,7 +60,12 @@
|
||||
<a class="btn btn-primary btn-sm" href="?action=enable&id={{ $plugin->name }}">启用插件</a>
|
||||
@endif
|
||||
|
||||
@if ($plugin->isEnabled() && $plugin->hasConfigView())
|
||||
<a class="btn btn-default btn-sm" href="?action=config&id={{ $plugin->name }}">插件配置</a>
|
||||
@else
|
||||
<a class="btn btn-default btn-sm" disabled="disabled" title="插件已被禁用或无配置页" data-toggle="tooltip" data-placement="top">插件配置</a>
|
||||
@endif
|
||||
|
||||
<a class="btn btn-danger btn-sm" href="javascript:deletePlugin('{{ $plugin->name }}');">删除插件</a>
|
||||
|
||||
</td>
|
||||
|
Loading…
Reference in New Issue
Block a user