fix some minor issues for plugins
This commit is contained in:
parent
b232503fab
commit
5fc43ed45b
19
app/Events/ConfigureAdminMenu.php
Normal file
19
app/Events/ConfigureAdminMenu.php
Normal file
@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Events;
|
||||
|
||||
class ConfigureAdminMenu extends Event
|
||||
{
|
||||
public $menu;
|
||||
|
||||
/**
|
||||
* Create a new event instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(array &$menu)
|
||||
{
|
||||
// pass array by reference
|
||||
$this->menu = &$menu;
|
||||
}
|
||||
}
|
21
app/Events/UserAuthenticated.php
Normal file
21
app/Events/UserAuthenticated.php
Normal file
@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace App\Events;
|
||||
|
||||
use App\Models\User;
|
||||
|
||||
class UserAuthenticated extends Event
|
||||
{
|
||||
public $user;
|
||||
|
||||
/**
|
||||
* Create a new event instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(User $user)
|
||||
{
|
||||
$this->user = $user;
|
||||
}
|
||||
|
||||
}
|
@ -2,12 +2,10 @@
|
||||
|
||||
namespace App\Events;
|
||||
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use App\Models\User;
|
||||
|
||||
class UserLoggedIn extends Event
|
||||
{
|
||||
use SerializesModels;
|
||||
|
||||
public $user;
|
||||
|
||||
/**
|
||||
@ -15,7 +13,7 @@ class UserLoggedIn extends Event
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(\App\Models\User $user)
|
||||
public function __construct(User $user)
|
||||
{
|
||||
$this->user = $user;
|
||||
}
|
||||
|
21
app/Events/UserRegistered.php
Normal file
21
app/Events/UserRegistered.php
Normal file
@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace App\Events;
|
||||
|
||||
use App\Models\User;
|
||||
|
||||
class UserRegistered extends Event
|
||||
{
|
||||
public $user;
|
||||
|
||||
/**
|
||||
* Create a new event instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(User $user)
|
||||
{
|
||||
$this->user = $user;
|
||||
}
|
||||
|
||||
}
|
@ -9,6 +9,7 @@ use Utils;
|
||||
use Cookie;
|
||||
use Option;
|
||||
use Session;
|
||||
use App\Events;
|
||||
use App\Models\User;
|
||||
use App\Models\UserModel;
|
||||
use Illuminate\Http\Request;
|
||||
@ -34,7 +35,7 @@ class AuthController extends Controller
|
||||
// guess type of identification
|
||||
$auth_type = (validate($identification, 'email')) ? "email" : "username";
|
||||
|
||||
event(new \App\Events\UserTryToLogin($identification, $auth_type));
|
||||
event(new Events\UserTryToLogin($identification, $auth_type));
|
||||
|
||||
// Get user instance from repository.
|
||||
// If the given identification is not registered yet,
|
||||
@ -58,7 +59,7 @@ class AuthController extends Controller
|
||||
// time in minutes
|
||||
$time = $request->input('keep') == true ? 10080 : 60;
|
||||
|
||||
event(new \App\Events\UserLoggedIn($user));
|
||||
event(new Events\UserLoggedIn($user));
|
||||
|
||||
return json(trans('auth.login.success'), 0, [
|
||||
'token' => $user->getToken()
|
||||
@ -140,6 +141,8 @@ class AuthController extends Controller
|
||||
return json(trans('auth.register.registered'), 5);
|
||||
}
|
||||
|
||||
event(new Events\UserRegistered($user));
|
||||
|
||||
return json([
|
||||
'errno' => 0,
|
||||
'msg' => trans('auth.register.success'),
|
||||
|
@ -114,8 +114,7 @@ class PlayerController extends Controller
|
||||
|
||||
$old_name = $this->player->player_name;
|
||||
|
||||
$this->player->player_name = $new_name;
|
||||
$this->player->save();
|
||||
$this->player->rename($new_name);
|
||||
|
||||
return json(trans('user.player.rename.success', ['old' => $old_name, 'new' => $new_name]), 0);
|
||||
}
|
||||
|
@ -112,7 +112,7 @@ class UserController extends Controller
|
||||
setcookie('uid', '', time() - 3600, '/');
|
||||
setcookie('token', '', time() - 3600, '/');
|
||||
|
||||
Session::flush();
|
||||
session()->flush();
|
||||
|
||||
return json(trans('user.profile.delete.success'), 0);
|
||||
}
|
||||
|
@ -8,6 +8,7 @@ use Http;
|
||||
use Cookie;
|
||||
use Session;
|
||||
use App\Models\User;
|
||||
use App\Events\UserAuthenticated;
|
||||
use App\Exceptions\PrettyPageException;
|
||||
|
||||
class CheckAuthenticated
|
||||
@ -53,6 +54,8 @@ class CheckAuthenticated
|
||||
if ($return_user)
|
||||
return $user;
|
||||
|
||||
event(new UserAuthenticated($user));
|
||||
|
||||
return $next($request);
|
||||
} else {
|
||||
return redirect('auth/login')->with('msg', trans('auth.check.anonymous'));
|
||||
|
@ -8,6 +8,7 @@ use Illuminate\Support\Arr;
|
||||
use Illuminate\Support\Str;
|
||||
use App\Events\ConfigureRoutes;
|
||||
use App\Events\ConfigureUserMenu;
|
||||
use App\Events\ConfigureAdminMenu;
|
||||
|
||||
class Hook
|
||||
{
|
||||
@ -26,12 +27,14 @@ class Hook
|
||||
*/
|
||||
public static function addMenuItem($category, $position, array $menu)
|
||||
{
|
||||
Event::listen(ConfigureUserMenu::class, function ($event) use ($menu, $position)
|
||||
$class = $category == "user" ? ConfigureUserMenu::class : ConfigureAdminMenu::class;
|
||||
|
||||
Event::listen($class, function ($event) use ($menu, $position, $category)
|
||||
{
|
||||
$new = [];
|
||||
|
||||
$offset = 0;
|
||||
foreach ($event->menu['user'] as $item) {
|
||||
foreach ($event->menu[$category] as $item) {
|
||||
// push new menu items at the given position
|
||||
if ($offset == $position) {
|
||||
$new[] = $menu;
|
||||
@ -41,7 +44,7 @@ class Hook
|
||||
$offset++;
|
||||
}
|
||||
|
||||
$event->menu['user'] = $new;
|
||||
$event->menu[$category] = $new;
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -20,8 +20,11 @@ class UserRepository extends Repository
|
||||
if ($type == "uid") {
|
||||
return Arr::has($this->items, $identification);
|
||||
} else {
|
||||
Arr::where((array) $this->items, function($key, $value) use ($identification, $type) {
|
||||
return ($user->$type == $identification);
|
||||
return Arr::where((array) $this->items, function($key, $value) use ($identification, $type) {
|
||||
if (property_exists($value, $type))
|
||||
return false;
|
||||
|
||||
return ($value->$type == $identification);
|
||||
});
|
||||
}
|
||||
}
|
||||
@ -57,4 +60,9 @@ class UserRepository extends Repository
|
||||
|
||||
return Arr::get($this->items, $identification, null);
|
||||
}
|
||||
|
||||
public function getCurrentUser()
|
||||
{
|
||||
return $this->get(session('uid'));
|
||||
}
|
||||
}
|
||||
|
@ -143,7 +143,8 @@ if (! function_exists('bs_menu')) {
|
||||
{
|
||||
$menu = require BASE_DIR."/config/menu.php";
|
||||
|
||||
event(new App\Events\ConfigureUserMenu($menu));
|
||||
event($type == "user" ? new App\Events\ConfigureUserMenu($menu)
|
||||
: new App\Events\ConfigureAdminMenu($menu));
|
||||
|
||||
if (!isset($menu[$type])) {
|
||||
throw new InvalidArgumentException;
|
||||
|
@ -2,7 +2,7 @@
|
||||
* @Author: printempw
|
||||
* @Date: 2016-07-22 14:08:41
|
||||
* @Last Modified by: printempw
|
||||
* @Last Modified time: 2016-08-06 18:52:47
|
||||
* @Last Modified time: 2016-11-17 15:06:22
|
||||
*/
|
||||
|
||||
@import "style.scss";
|
||||
@ -14,17 +14,6 @@
|
||||
}
|
||||
}
|
||||
|
||||
.key {
|
||||
vertical-align: middle !important;
|
||||
}
|
||||
.value {
|
||||
width: 70%;
|
||||
}
|
||||
|
||||
td[class='key'], td[class='value'] {
|
||||
border-top: 0 !important;
|
||||
}
|
||||
|
||||
.btn-group {
|
||||
.btn {
|
||||
margin-right: 10px;
|
||||
|
@ -2,7 +2,7 @@
|
||||
* @Author: printempw
|
||||
* @Date: 2016-06-04 20:55:09
|
||||
* @Last Modified by: printempw
|
||||
* @Last Modified time: 2016-09-26 22:09:14
|
||||
* @Last Modified time: 2016-11-17 15:06:31
|
||||
*/
|
||||
|
||||
$font_stack: Ubuntu, 'Segoe UI', 'Microsoft Yahei', 'Microsoft Jhenghei', sans-serif;
|
||||
@ -204,3 +204,14 @@ input:-webkit-autofill {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.key {
|
||||
vertical-align: middle !important;
|
||||
}
|
||||
.value {
|
||||
width: 70%;
|
||||
}
|
||||
|
||||
td[class='key'], td[class='value'] {
|
||||
border-top: 0 !important;
|
||||
}
|
||||
|
@ -131,7 +131,7 @@ profile:
|
||||
|
||||
delete:
|
||||
title: Delete Account
|
||||
notice: Sure to delete your account on :sitename?
|
||||
notice: Sure to delete your account on :site?
|
||||
admin: Admin account can not be deleted.
|
||||
button: Delete My Account
|
||||
|
||||
|
@ -92,4 +92,5 @@ attributes:
|
||||
file: File
|
||||
name: Name
|
||||
player_name: 'Player Name'
|
||||
new_player_name: 'Player Name'
|
||||
identification: Email or player name
|
||||
|
@ -137,7 +137,7 @@ profile:
|
||||
|
||||
delete:
|
||||
title: 删除账号
|
||||
notice: 确定要删除你在 :sitename 上的账号吗?
|
||||
notice: 确定要删除你在 :site 上的账号吗?
|
||||
admin: 管理员账号不能被删除哟
|
||||
button: 删除我的账户
|
||||
|
||||
|
@ -83,6 +83,7 @@ attributes:
|
||||
file: 文件
|
||||
username: 用户名
|
||||
identification: 邮箱或角色名
|
||||
new_player_name: 角色名
|
||||
nickname: 昵称
|
||||
player_name: 角色名
|
||||
email: 邮箱
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
@foreach ((array) $items as $item)
|
||||
<?php list($id, $name) = $item; ?>
|
||||
<option {!! $selected == $id ? 'selected="selected"' : '' !!} value="{{ $id }}">{{ $name }}</option>";
|
||||
<option {!! $selected == $id ? 'selected="selected"' : '' !!} value="{{ $id }}">{{ $name }}</option>
|
||||
@endforeach
|
||||
|
||||
</select>
|
||||
|
Loading…
Reference in New Issue
Block a user