前端目录调整

This commit is contained in:
molong
2022-05-12 21:23:18 +08:00
parent fe38e19924
commit a37870c93b
145 changed files with 3090 additions and 7244 deletions

16
app/controller/Base.php Normal file
View File

@@ -0,0 +1,16 @@
<?php
// +----------------------------------------------------------------------
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013 http://www.tensent.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
// +----------------------------------------------------------------------
namespace app\controller;
use app\BaseController;
class Base extends BaseController{
public $data = ['code' => 1, 'data' => '', 'message' => ''];
}

View File

@@ -1,17 +0,0 @@
<?php
namespace app\controller;
use app\BaseController;
class Index extends BaseController
{
public function index()
{
return '<style type="text/css">*{ padding: 0; margin: 0; } div{ padding: 4px 48px;} a{color:#2E5CD5;cursor: pointer;text-decoration: none} a:hover{text-decoration:underline; } body{ background: #fff; font-family: "Century Gothic","Microsoft yahei"; color: #333;font-size:18px;} h1{ font-size: 100px; font-weight: normal; margin-bottom: 12px; } p{ line-height: 1.6em; font-size: 42px }</style><div style="padding: 24px 48px;"> <h1>:) </h1><p> ThinkPHP V' . \think\facade\App::version() . '<br/><span style="font-size:30px;">14载初心不改 - 你值得信赖的PHP框架</span></p><span style="font-size:25px;">[ V6.0 版本由 <a href="https://www.yisu.com/" target="yisu">亿速云</a> 独家赞助发布 ]</span></div><script type="text/javascript" src="https://tajs.qq.com/stats?sId=64890268" charset="UTF-8"></script><script type="text/javascript" src="https://e.topthink.com/Public/static/client.js"></script><think id="ee9b1aa918103c4fc"></think>';
}
public function hello($name = 'ThinkPHP6')
{
return 'hello,' . $name;
}
}

View File

@@ -0,0 +1,26 @@
<?php
// +----------------------------------------------------------------------
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013 http://www.tensent.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
// +----------------------------------------------------------------------
namespace app\controller\auth;
use app\controller\Base;
use app\services\auth\LoginService;
class Index extends Base{
public function login(LoginService $service){
try {
$data = $service->authLogin($this->request);
$this->data['data'] = $data;
} catch (\think\Exception $e) {
$this->data['code'] = 0;
$this->data['message'] = $e->getMessage();
}
return $this->data;
}
}

View File

@@ -1,6 +1,7 @@
<?php
// 全局中间件定义文件
return [
\app\middleware\AllowCrossDomain::class,
\app\middleware\Api::class,
\app\middleware\Validate::class,
];

View File

@@ -0,0 +1,48 @@
<?php
// +----------------------------------------------------------------------
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013 http://www.tensent.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
// +----------------------------------------------------------------------
declare (strict_types = 1);
namespace app\middleware;
use think\Config;
use think\Request;
use think\Response;
class AllowCrossDomain{
protected $header = [
'Access-Control-Allow-Credentials' => 'true',
'Access-Control-Max-Age' => 1800,
'Access-Control-Allow-Methods' => 'GET, POST, PATCH, PUT, DELETE, OPTIONS',
'Access-Control-Allow-Headers' => 'Authorization, Content-Type, If-Match, If-Modified-Since, If-None-Match, If-Unmodified-Since, X-CSRF-TOKEN, X-Requested-With',
];
public function __construct(Config $config){
$this->header = array_merge($this->header, $config->get('cross', ''));
}
/**
* 允许跨域请求
* @access public
* @param Request $request
* @param Closure $next
* @param array $header
* @return Response
*/
public function handle($request, \Closure $next, ? array $header = []){
$header = !empty($header) ? array_merge($this->header, $header) : $this->header;
if (!isset($header['Access-Control-Allow-Origin'])) {
$origin = $request->header('origin');
$header['Access-Control-Allow-Origin'] = $origin ? $origin : "*";
}
return $next($request)->header($header);
}
}

View File

@@ -11,6 +11,9 @@ declare (strict_types = 1);
namespace app\middleware;
class Api{
public $data = ['code' => 1, 'data' => '', 'message' => ''];
/**
* 处理请求
*

15
app/model/BaseModel.php Normal file
View File

@@ -0,0 +1,15 @@
<?php
// +----------------------------------------------------------------------
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013 http://www.tensent.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
// +----------------------------------------------------------------------
namespace app\model;
use think\Model;
class BaseModel extends Model{
}

20
app/model/user/Users.php Normal file
View File

@@ -0,0 +1,20 @@
<?php
// +----------------------------------------------------------------------
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013 http://www.tensent.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
// +----------------------------------------------------------------------
namespace app\model\user;
use app\model\BaseModel;
use xiaodi\JWTAuth\Facade\Jwt;
class Users extends BaseModel{
public function getTokenAttr($value, $data){
$token = Jwt::store('api')->token($data)->__toString();
return $token;
}
}

View File

@@ -0,0 +1,36 @@
<?php
// +----------------------------------------------------------------------
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013 http://www.tensent.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
// +----------------------------------------------------------------------
namespace app\services\auth;
use app\model\user\Users;
class LoginService{
public function authLogin($request){
$params = $request->post();
$map = [];
foreach($params as $field => $value){
if(in_array($field, ['username', 'email', 'mobile']) && $field != 'password'){
$map[$field] = $value;
}
}
$user = Users::where($map)->field(['uid','username', 'password', 'email', 'avatar', 'department_id', 'status'])->findOrEmpty();
if (!$user->isEmpty()) {
if(password_verify(base64_decode($params['password']), $user->password)){
throw new \think\Exception('密码不正确!', 100002);
}elseif($user->status != 1){
throw new \think\Exception('当前用户不可用', 100003);
}else{
return $user->append(['token']);
}
}else{
throw new \think\Exception('当前用户不存在', 100001);
}
}
}