Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
orvice committed Jan 17, 2016
2 parents ab9090d + 489cf13 commit ae01889
Show file tree
Hide file tree
Showing 12 changed files with 393 additions and 76 deletions.
14 changes: 13 additions & 1 deletion app/Controllers/Admin/NodeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,21 @@

namespace App\Controllers\Admin;

class NodeController
use App\Models\Node;
use App\Controllers\BaseController;

class NodeController extends BaseController
{
public function index(){
$nodes = Node::all();
return $this->view()->assign('nodes',$nodes)->display('admin/node.tpl');
}

public function create(){

}

public function edit(){

}
}
19 changes: 0 additions & 19 deletions app/Controllers/Password.php

This file was deleted.

74 changes: 74 additions & 0 deletions app/Controllers/PasswordController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<?php

namespace App\Controllers;

use App\Models\User;
use App\Models\PasswordReset;
use App\Services\Password;
use App\Utils\Hash;

/***
* Class Password
* @package App\Controllers
* 密码重置
*/

class PasswordController extends BaseController
{
public function reset(){
return $this->view()->display('password/reset.tpl');
}

public function handleReset($request, $response, $args){
$email = $request->getParam('email');
// check limit

// send email
$user = User::where('email',$email)->first();
if ($user == null){
$rs['ret'] = 0;
$rs['msg'] = '此邮箱不存在.';
return $response->getBody()->write(json_encode($rs));
}
Password::sendResetEmail($email);
$rs['ret'] = 1;
$rs['msg'] = '重置邮件已经发送,请检查邮箱.';
return $response->getBody()->write(json_encode($rs));
}

public function token($request, $response, $args){
$token = $args['token'];
return $this->view()->assign('token',$token)->display('password/token.tpl');
}

public function handleToken($request, $response, $args){
$tokenStr = $args['token'];
$password = $request->getParam('password');
// check token
$token = PasswordReset::where('token',$tokenStr)->first();
if ($token == null || $token->expire_time < time() ){
$rs['ret'] = 0;
$rs['msg'] = '链接已经失效,请重新获取';
return $response->getBody()->write(json_encode($rs));
}

$user = User::where('email',$token->email)->first();
if ($user == null){
$rs['ret'] = 0;
$rs['msg'] = '链接已经失效,请重新获取';
return $response->getBody()->write(json_encode($rs));
}

// reset password
$hashPassword = Hash::passwordHash($password);
$user->pass = $hashPassword;
if(!$user->save()){
$rs['ret'] = 0;
$rs['msg'] = '重置失败,请重试';
return $response->getBody()->write(json_encode($rs));
}
$rs['ret'] = 1;
$rs['msg'] = '重置成功';
return $response->getBody()->write(json_encode($rs));
}
}
9 changes: 0 additions & 9 deletions app/Models/Password.php

This file was deleted.

9 changes: 9 additions & 0 deletions app/Models/PasswordReset.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

namespace App\Models;


class PasswordReset extends Model
{
protected $table = 'ss_password_reset';
}
5 changes: 4 additions & 1 deletion app/Services/Mail.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@

namespace App\Services;

use App\Services\Config;
/***
* Mail Service
*/

use App\Services\Mail\Mailgun;
use App\Services\Mail\Smtp;

Expand Down
42 changes: 42 additions & 0 deletions app/Services/Password.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php


namespace App\Services;

use App\Models\PasswordReset;
use App\Utils\Tools;
/***
* Class Password
* @package App\Services
*/

class Password
{
/**
* @param $email string
* @return bool
*/
public static function sendResetEmail($email){
$pwdRst = new PasswordReset();
$pwdRst->email = $email;
$pwdRst->init_time = time();
$pwdRst->expire_time = time() + 3600*24; // @todo
$pwdRst->token = Tools::genRandomChar(64);
if(!$pwdRst->save()){
return false;
}
$subject = Config::get('appName')."重置密码";
$text = '请访问此链接申请重置密码'.Config::get('baseUrl')."/password/token/";
try{
Mail::send($email,$subject,$text);
}catch (Exception $e){
return false;
}
return true;
}

public static function resetBy($token,$password){

}

}
11 changes: 10 additions & 1 deletion config/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,20 @@
$this->get('/logout', 'App\Controllers\AuthController:logout');
})->add(new Guest());

// Password
$app->group('/password', function () {
$this->get('/reset', 'App\Controllers\PasswordController:reset');
$this->post('/reset', 'App\Controllers\PasswordController:handleReset');
$this->get('/token/{token}', 'App\Controllers\PasswordController:token');
$this->post('/token/{token}', 'App\Controllers\PasswordController:handleToken');
})->add(new Guest());

// Admin
$app->group('/admin', function () {
$this->get('', 'App\Controllers\AdminController:index');
$this->get('/', 'App\Controllers\AdminController:index');
$this->get('/node', 'App\Controllers\AdminController:node');
$this->get('/node', 'App\Controllers\Admin\NodeController:index');
$this->get('/node/create', 'App\Controllers\Admin\NodeController:create');
$this->get('/profile', 'App\Controllers\AdminController:profile');
$this->get('/invite', 'App\Controllers\AdminController:invite');
$this->post('/invite', 'App\Controllers\AdminController:addInvite');
Expand Down
74 changes: 31 additions & 43 deletions views/default/admin/node.tpl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{include file='user/main.tpl'}
{include file='admin/main.tpl'}

<!-- Content Wrapper. Contains page content -->
<div class="content-wrapper">
Expand All @@ -12,53 +12,41 @@

<!-- Main content -->
<section class="content">
<!-- START PROGRESS BARS -->
<div class="row">
<div class="col-md-8">
<div class="box box-solid">
<div class="box-header">
<i class="fa fa-th-list"></i>
<h3 class="box-title">节点</h3>
</div><!-- /.box-header -->
<div class="box-body">
<div class="callout callout-warning">
<h4>注意!</h4>
<p>请勿在任何地方公开节点地址!</p>
</div>
{foreach $nodes as $node}
<div class="nav-tabs-custom">
<ul class="nav nav-tabs pull-right">
<li>
<a href="./node/{$node->id}">
查看配置文件/二维码
</a>
</li>
<li class="pull-left header"><i class="fa fa-angle-right"></i> {$node->name}</li>
</ul>
<div class="tab-content">
<div class="tab-pane active" id="tab_1-1">
<p> <a class="btn btn-xs bg-purple btn-flat margin" href="#">地址:</a> <code>{$node->server}</code>
<a class="btn btn-xs bg-orange btn-flat margin" href="#">{$node->status}</a>
<a class="btn btn-xs bg-green btn-flat margin" href="#">{$node->method}</a>
</p>
<p> {$node->info}</p>
</div><!-- /.tab-pane -->
</div><!-- /.tab-content -->
</div><!-- nav-tabs-custom -->
{/foreach}
<div class="col-xs-12">
<p> <a class="btn btn-success btn-sm" href="/admin/node/create">添加</a> </p>
<div class="box">
<div class="box-body table-responsive no-padding">
<table class="table table-hover">
<tr>
<th>ID</th>
<th>节点</th>
<th>加密</th>
<th>描述</th>
<th>排序</th>
<th>操作</th>
</tr>
{foreach $nodes as $node}
<tr>
<td>#{$node->id}</td>
<td> {$node->name}</td>
<td>{$node->method}</td>
<td>{$node->info}</td>
<td>{$node->order}</td>
<td>
<a class="btn btn-info btn-sm" href="/admin/node/{$node->id}">编辑</a>
<a class="btn btn-danger btn-sm" href="/admin/node/{$node->id}/delete">删除</a>
</td>
</tr>
{/foreach}
</table>
</div><!-- /.box-body -->


</div><!-- /.box -->
</div><!-- /.col (left) -->

<div class="col-md-4">
</div><!-- /.col (right) -->
</div>
</div>

</div><!-- /.row -->
<!-- END PROGRESS BARS -->
</section><!-- /.content -->
</div><!-- /.content-wrapper -->


{include file='user/footer.tpl'}
{include file='admin/footer.tpl'}
4 changes: 2 additions & 2 deletions views/default/admin/sys.tpl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{include file='user/main.tpl'}
{include file='admin/main.tpl'}

<div class="content-wrapper">
<section class="content-header">
Expand All @@ -23,4 +23,4 @@
</div>
</section><!-- /.content -->
</div><!-- /.content-wrapper -->
{include file='user/footer.tpl'}
{include file='admin/footer.tpl'}
Loading

0 comments on commit ae01889

Please sign in to comment.