Skip to content

Commit

Permalink
细节优化
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangjiangbin committed Aug 19, 2017
1 parent 6b311b9 commit 8577ccb
Show file tree
Hide file tree
Showing 21 changed files with 303 additions and 129 deletions.
83 changes: 58 additions & 25 deletions app/Http/Controllers/AdminController.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@

class AdminController extends BaseController
{
protected static $config;

function __construct()
{
self::$config = $this->systemConfig();
}

public function index(Request $request)
{
if (!$request->session()->has('user')) {
Expand Down Expand Up @@ -187,9 +194,8 @@ public function addUser(Request $request)
}
} else {
// 最后一个可用端口
$config = $this->systemConfig();
$last_user = User::orderBy('id', 'desc')->first();
$view['last_port'] = $config['is_rand_port'] ? $this->getRandPort() : $last_user->port + 1;
$view['last_port'] = self::$config['is_rand_port'] ? $this->getRandPort() : $last_user->port + 1;

// 加密方式、协议、混淆
$view['method_list'] = $this->methodList();
Expand Down Expand Up @@ -484,7 +490,7 @@ public function articleList(Request $request)
return Redirect::to('login');
}

$articleList = Article::paginate(10);
$articleList = Article::orderBy('sort', 'desc')->paginate(10);

$view['articleList'] = $articleList;

Expand Down Expand Up @@ -959,6 +965,7 @@ public function monitor(Request $request)
}

$view['traffic'] = $traffic;
$view['nodeList'] = $node_list;

return Response::view('admin/monitor', $view);
}
Expand Down Expand Up @@ -1120,54 +1127,80 @@ public function system(Request $request)
return Response::view('admin/system', $view);
}

// 启用、禁用随机端口
public function enableRandPort(Request $request)
// 设置某个配置项
public function setConfig(Request $request)
{
$value = intval($request->get('value'));
$name = trim($request->get('name'));
$value = trim($request->get('value'));

if ($name == '' || $value == '') {
return Response::json(['status' => 'fail', 'data' => '', 'message' => '设置失败:请求参数异常']);
}

Config::where('id', 1)->update(['value' => $value]);
// 屏蔽异常配置
if (!array_key_exists($name, self::$config)) {
return Response::json(['status' => 'fail', 'data' => '', 'message' => '设置失败:配置不存在']);
}

// 如果开启用户邮件重置密码,则先设置网站名称和网址
if ($name == 'is_reset_password' && $value == '1') {
$config = Config::where('name', 'website_name')->first();
if ($config->value == '') {
return Response::json(['status' => 'fail', 'data' => '', 'message' => '设置失败:开启重置密码需要先设置【网站名称】']);
}

$config = Config::where('name', 'website_url')->first();
if ($config->value == '') {
return Response::json(['status' => 'fail', 'data' => '', 'message' => '设置失败:开启重置密码需要先设置【网站地址】']);
}
}

$ret = Config::where('name', $name)->update(['value' => $value]);
if (!$ret) {
return Response::json(['status' => 'fail', 'data' => '', 'message' => '设置失败']);
}

return Response::json(['status' => 'success', 'data' => '', 'message' => '操作成功']);
}

// 启用、禁用自定义端口
public function enableUserRandPort(Request $request)
// 设置可生成邀请码数
public function setInviteNum(Request $request)
{
$value = intval($request->get('value'));

Config::where('id', 2)->update(['value' => $value]);
Config::where('id', 3)->update(['value' => $value]);

return Response::json(['status' => 'success', 'data' => '', 'message' => '操作成功']);
return Response::json(['status' => 'success', 'data' => '', 'message' => '设置成功']);
}

// 启用、禁用注册
public function enableRegister(Request $request)
// 设置网站名称
public function setWebsiteName(Request $request)
{
$value = intval($request->get('value'));
$value = trim($request->get('value'));

Config::where('id', 4)->update(['value' => $value]);
Config::where('id', 6)->update(['value' => $value]);

return Response::json(['status' => 'success', 'data' => '', 'message' => '操作成功']);
return Response::json(['status' => 'success', 'data' => '', 'message' => '设置成功']);
}

// 启用、禁用邀请注册
public function enableInviteRegister(Request $request)
// 设置网站地址
public function setWebsiteUrl(Request $request)
{
$value = intval($request->get('value'));
$value = trim($request->get('value'));

Config::where('id', 5)->update(['value' => $value]);
Config::where('id', 9)->update(['value' => $value]);

return Response::json(['status' => 'success', 'data' => '', 'message' => '操作成功']);
return Response::json(['status' => 'success', 'data' => '', 'message' => '设置成功']);
}

// 设置可生成邀请码数
public function setInviteNum(Request $request)
// 设置重置密码次数
public function setResetPasswordTimes(Request $request)
{
$value = intval($request->get('value'));

Config::where('id', 3)->update(['value' => $value]);
Config::where('id', 8)->update(['value' => $value]);

return Response::json(['status' => 'success', 'data' => '', 'message' => '操作成功']);
return Response::json(['status' => 'success', 'data' => '', 'message' => '设置成功']);
}

// 邀请码列表
Expand Down
10 changes: 8 additions & 2 deletions app/Http/Controllers/LoginController.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,19 @@ public function index(Request $request)

if (empty($username) || empty($password)) {
$request->session()->flash('errorMsg', '请输入用户名和密码');
return Redirect::to('login');

return Redirect::back();
}

$user = User::where('username', $username)->where('password', md5($password))->first();
if (!$user) {
$request->session()->flash('errorMsg', '用户名或密码错误');
return Redirect::to('login');

return Redirect::back()->withInput();
} else if (!$user->enable) {
$request->session()->flash('errorMsg', '账号已禁用');

return Redirect::back();
}

$request->session()->put('user', $user->toArray());
Expand Down
23 changes: 13 additions & 10 deletions app/Http/Controllers/RegisterController.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@
*/
class RegisterController extends BaseController
{
protected static $config;

function __construct()
{
self::$config = $this->systemConfig();
}

// 注册页
public function index(Request $request)
{
Expand Down Expand Up @@ -42,17 +49,15 @@ public function index(Request $request)
return Redirect::back()->withInput($request->except(['password', 'repassword']));
}

$config = $this->systemConfig();

// 是否开启注册
if (!$config['is_register']) {
if (!self::$config['is_register']) {
$request->session()->flash('errorMsg', '系统维护暂停注册,如需账号请联系管理员');

return Redirect::back();
}

// 如果需要邀请注册
if ($config['is_invite_register']) {
if (self::$config['is_invite_register']) {
if (empty($code)) {
$request->session()->flash('errorMsg', '请输入邀请码');

Expand All @@ -77,9 +82,8 @@ public function index(Request $request)
}

// 最后一个可用端口
$config = $this->systemConfig();
$last_user = User::orderBy('id', 'desc')->first();
$port = $config['is_rand_port'] ? $this->getRandPort() : $last_user->port + 1;
$port = self::$config['is_rand_port'] ? $this->getRandPort() : $last_user->port + 1;

// 创建新用户
$obj = new User();
Expand All @@ -94,15 +98,14 @@ public function index(Request $request)
$obj->save();

// 更新邀请码
if ($config['is_invite_register'] && $obj->id) {
if (self::$config['is_invite_register'] && $obj->id) {
Invite::where('id', $code->id)->update(['fuid' => $obj->id,'status' => 1]);
}

return Redirect::to('login');
} else {
$config = $this->systemConfig();
$view['is_register'] = $config['is_register'];
$view['is_invite_register'] = $config['is_invite_register'];
$view['is_register'] = self::$config['is_register'];
$view['is_invite_register'] = self::$config['is_invite_register'];

return Response::view('register', $view);
}
Expand Down
31 changes: 17 additions & 14 deletions app/Http/Controllers/UserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@

class UserController extends BaseController
{
protected static $config;

function __construct()
{
self::$config = $this->systemConfig();
}

public function index(Request $request)
{
if (!$request->session()->has('user')) {
Expand Down Expand Up @@ -232,9 +239,8 @@ public function invite(Request $request)

// 已生成的邀请码数量
$num = Invite::where('uid', $user['id'])->count();
$config = $this->systemConfig();

$view['num'] = $config['invite_num'] - $num <= 0 ? 0 : $config['invite_num'] - $num; // 还可以生成的邀请码数量
$view['num'] = self::$config['invite_num'] - $num <= 0 ? 0 : self::$config['invite_num'] - $num; // 还可以生成的邀请码数量
$view['inviteList'] = Invite::where('uid', $user['id'])->with(['generator', 'user'])->paginate(10); // 邀请码列表

return Response::view('user/invite', $view);
Expand All @@ -251,9 +257,8 @@ public function makeInvite(Request $request)

// 已生成的邀请码数量
$num = Invite::where('uid', $user['id'])->count();
$config = $this->systemConfig();
if ($num >= $config['invite_num']) {
return Response::json(['status' => 'fail', 'data' => '', 'message' => '生成失败:最多只能生成' . $config['invite_num'] . '个邀请码']);
if ($num >= self::$config['invite_num']) {
return Response::json(['status' => 'fail', 'data' => '', 'message' => '生成失败:最多只能生成' . self::$config['invite_num'] . '个邀请码']);
}

$obj = new Invite();
Expand All @@ -270,13 +275,11 @@ public function makeInvite(Request $request)
// 重设密码
public function resetPassword(Request $request)
{
$config = $this->systemConfig();

if ($request->method() == 'POST') {
$username = trim($request->get('username'));

// 是否开启重设密码
if (!$config['is_reset_password']) {
if (!self::$config['is_reset_password']) {
$request->session()->flash('errorMsg', '系统未开启重置密码功能,请联系管理员');

return Redirect::back()->withInput();
Expand All @@ -294,15 +297,15 @@ public function resetPassword(Request $request)
$resetTimes = 0;
if (Cache::has('resetPassword_' . md5($username))) {
$resetTimes = Cache::get('resetPassword_' . md5($username));
if ($resetTimes >= $config['reset_password_times']) {
$request->session()->flash('errorMsg', '同一个账号24小时内只能重设密码' . $config['reset_password_times'] . '次,请勿频繁操作');
if ($resetTimes >= self::$config['reset_password_times']) {
$request->session()->flash('errorMsg', '同一个账号24小时内只能重设密码' . self::$config['reset_password_times'] . '次,请勿频繁操作');

return Redirect::back();
}
}

// 生成取回密码的地址
$token = md5($config['website_name'] . $username . microtime());
$token = md5(self::$config['website_name'] . $username . microtime());
$verify = new Verify();
$verify->user_id = $user->id;
$verify->username = $username;
Expand All @@ -311,15 +314,15 @@ public function resetPassword(Request $request)
$verify->save();

// 发送邮件
$resetPasswordUrl = $config['website_url'] . '/reset/' . $token;
Mail::to($user->username)->send(new resetPassword($config['website_name'], $resetPasswordUrl));
$resetPasswordUrl = self::$config['website_url'] . '/reset/' . $token;
Mail::to($user->username)->send(new resetPassword(self::$config['website_name'], $resetPasswordUrl));

Cache::put('resetPassword_' . md5($username), $resetTimes + 1, 1440);
$request->session()->flash('successMsg', '重置成功,请查看邮箱');

return Redirect::back();
} else {
$view['is_reset_password'] = $config['is_reset_password'];
$view['is_reset_password'] = self::$config['is_reset_password'];

return Response::view('user/resetPassword', $view);
}
Expand Down
Binary file modified composer.phar
Binary file not shown.
2 changes: 1 addition & 1 deletion config/mail.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@

'from' => [
'address' => '[email protected]',
'name' => 'ÖØÖÃÃÜÂë',
'name' => '重置密码',
],

/*
Expand Down
5 changes: 5 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ config\database.php mysql选项自行配置数据库
确保 storage/framework 下有 cache sessions views 三个目录,且 storage 有777权限
````

#### 发送邮件配置
````
config\mail.php 修改其中的配置
````

#### NGINX配置文件加入
````
location / {
Expand Down
4 changes: 3 additions & 1 deletion resources/views/admin/articleList.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,21 +42,23 @@
<th> ID </th>
<th> 标题 </th>
<th> 排序 </th>
<th> 发布日期 </th>
<th> 状态 </th>
<th> 操作 </th>
</tr>
</thead>
<tbody>
@if($articleList->isEmpty())
<tr>
<td colspan="5">暂无数据</td>
<td colspan="6">暂无数据</td>
</tr>
@else
@foreach($articleList as $article)
<tr class="odd gradeX">
<td> {{$article->id}} </td>
<td> <a href="{{url('user/article?id=' . $article->id)}}" target="_blank"> {{$article->title}} </a> </td>
<td> {{$article->sort}} </td>
<td> {{$article->created_at}} </td>
<td> <span class="label label-danger"> {{$article->is_del ? '已删除' : '未删除'}} </span> </td>
<td>
<button type="button" class="btn btn-sm blue btn-outline" onclick="editArticle('{{$article->id}}')">编辑</button>
Expand Down
4 changes: 1 addition & 3 deletions resources/views/admin/inviteList.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,7 @@ function makeInvite() {
dataType: 'json',
success: function (ret) {
if (ret.status == 'success') {
bootbox.alert(ret.message, function () {
window.location.reload();
});
window.location.reload();
} else {
bootbox.alert(ret.message);
}
Expand Down
2 changes: 1 addition & 1 deletion resources/views/admin/layouts.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@
<li class="nav-item {{Request::getRequestUri() == '/admin/system' ? 'active open' : ''}}">
<a href="{{url('admin/system')}}" class="nav-link ">
<i class="icon-wrench"></i>
<span class="title">系统配置</span>
<span class="title">系统设置</span>
</a>
</li>
</ul>
Expand Down
6 changes: 3 additions & 3 deletions resources/views/admin/monitor.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,9 @@ function chart() {
@endif
var plot = $.plot($("#chart"), [
@if (!empty($traffic))
@foreach($traffic as $node_id => $node_traffic_list)
{data: {{'node_' . $node_id}}, label: "节点{{$node_id}}", lines: {lineWidth: 1}, shadowSize: 0},
@if (!empty($nodeList))
@foreach($nodeList as $node)
{data: {{'node_' . $node->id}}, label: "{{$node->name}}", lines: {lineWidth: 1}, shadowSize: 0},
@endforeach
@endif
], {
Expand Down
Loading

0 comments on commit 8577ccb

Please sign in to comment.