Commit a224fa3d by 肖康

Merge branch 'dev/ver/1.0.0' of http://git.ichunt.net/semour/semour_web into dev/ver/1.0.0

parents 85345be1 3638edfd
......@@ -3,6 +3,7 @@
/public/storage
/storage/*.key
/.idea
.idea
/vendor/_laravel_idea
#/vendor
#.env
......
......@@ -2,7 +2,10 @@
<project version="4">
<component name="ChangeListManager">
<list default="true" id="fb90add0-1393-48c2-9f26-72365d42cd03" name="变更" comment="">
<change beforePath="$PROJECT_DIR$/.env" beforeDir="false" afterPath="$PROJECT_DIR$/.env" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/app/Http/Controllers/Api/AuthApiController.php" beforeDir="false" afterPath="$PROJECT_DIR$/app/Http/Controllers/Api/AuthApiController.php" afterDir="false" />
<change beforePath="$PROJECT_DIR$/routes/api.php" beforeDir="false" afterPath="$PROJECT_DIR$/routes/api.php" afterDir="false" />
<change beforePath="$PROJECT_DIR$/routes/web.php" beforeDir="false" afterPath="$PROJECT_DIR$/routes/web.php" afterDir="false" />
<change beforePath="$PROJECT_DIR$/storage/app/.gitignore" beforeDir="false" afterPath="$PROJECT_DIR$/storage/app/.gitignore" afterDir="false" />
<change beforePath="$PROJECT_DIR$/storage/app/public/.gitignore" beforeDir="false" afterPath="$PROJECT_DIR$/storage/app/public/.gitignore" afterDir="false" />
<change beforePath="$PROJECT_DIR$/storage/framework/.gitignore" beforeDir="false" afterPath="$PROJECT_DIR$/storage/framework/.gitignore" afterDir="false" />
......@@ -147,18 +150,18 @@
<property name="RunOnceActivity.OpenProjectViewOnStart" value="true" />
<property name="RunOnceActivity.ShowReadmeOnStart" value="true" />
<property name="WebServerToolWindowFactoryState" value="false" />
<property name="last_opened_file_path" value="$PROJECT_DIR$/resources/views/about" />
<property name="last_opened_file_path" value="$PROJECT_DIR$/app/Http" />
<property name="nodejs_interpreter_path.stuck_in_default_project" value="undefined stuck path" />
<property name="nodejs_package_manager_path" value="npm" />
<property name="vue.rearranger.settings.migration" value="true" />
</component>
<component name="RecentsManager">
<key name="CopyFile.RECENT_KEYS">
<recent name="\\wsl$\Ubuntu-20.04\data\www\semour_web\app\Http" />
<recent name="\\wsl$\Ubuntu-20.04\data\www\semour_web\app\Http\Controllers\Api" />
<recent name="\\wsl$\Ubuntu-20.04\data\www\semour_web\resources\views\about" />
<recent name="\\wsl$\Ubuntu-20.04\data\www\semour_web\app\Http\Traits" />
<recent name="\\wsl$\Ubuntu-20.04\data\www\semour_web\app\Http\Controllers\Api" />
<recent name="\\wsl$\Ubuntu-20.04\data\www\semour_web\app\Http\Api" />
<recent name="\\wsl$\Ubuntu-20.04\data\www\semour_web\public" />
</key>
<key name="MoveFile.RECENT_KEYS">
<recent name="\\wsl$\Ubuntu-20.04\data\www\semour_web\resources\views\home" />
......
<?php
namespace App\Http\ApiHelper;
interface ApiCode
{
const API_CODE_SUCCESS = 0;//接口请求正常
const API_CODE_ERROR = 1;//接口请求异常 可预测失败
const API_CODE_NEED_LOGIN = 101; //需要登录
const API_CODE_LOGIN_ERROR = 102; // 登录信息错误
const API_CODE_MOBILE_NOTFOUND_ERROR = 103; // 手机号不存在
const API_CODE_PASSWD_NOTFOUND_ERROR = 104; // 密码错误
const API_CODE_USER_DISABLE_ERROR = 105; // 账号被封禁
}
<?php
/**
* Created by PhpStorm.
* User: duwenjun
* Date: 2021/8/11
* Time: 2:52 PM
*/
namespace App\Http\ApiHelper;
class Response
{
public static function setError($errMsg, $errCode = ApiCode::API_CODE_ERROR, $data = [])
{
return json_encode(['code' => $errCode, 'msg' => $errMsg, 'data' => $data],
JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
}
public static function setSuccess($data, $code = ApiCode::API_CODE_SUCCESS, $msg = "")
{
return json_encode(['code' => $code, 'msg' => $msg, 'data' => $data],
JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
}
}
\ No newline at end of file
<?php
namespace App\Http\Controllers\Api;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
use Illuminate\Foundation\Auth\RedirectsUsers;
use Illuminate\Foundation\Auth\ThrottlesLogins;
use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Validator;
class AuthApiController extends Controller
{
use RedirectsUsers, ThrottlesLogins;
public function login(Request $request)
{
$validator = Validator::make($request->all(), [
'email' => 'required|string|email|max:255',
'password' => 'required|string|min:8|confirmed',
], [
'password.min' => 'Password must be at least 8 characters long.'
]);
if ($validator->fails()) {
return $this->setError($validator->errors()->first());
}
if ($this->attemptLogin($request)) {
$request->session()->regenerate();
return $this->setSuccess('login success');
}
$this->incrementLoginAttempts($request);
return $this->setError('login failure');
}
}
......@@ -2,13 +2,75 @@
namespace App\Http\Controllers\Api;
use App\Http\ApiHelper\ApiCode;
use App\Http\Traits\Response;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
use Illuminate\Foundation\Auth\AuthenticatesUsers;
use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Routing\Controller as BaseController;
use Illuminate\Support\Facades\Log;
class Controller extends BaseController
{
use AuthorizesRequests, DispatchesJobs, ValidatesRequests,Response;
use AuthorizesRequests, DispatchesJobs, ValidatesRequests, Response, AuthenticatesUsers;
public function setSuccessData($data = [], $count = 0, $code = ApiCode::API_CODE_SUCCESS, $msg = 'ok')
{
$res_data = [
"code" => $code,
"data" => $data,
];
if ($msg) {
$res_data['msg'] = $msg;
}
if ($count) {
$res_data['count'] = $count;
}
return response()->json($res_data);
}
public function setSuccess($msg = '操作成功', $code = ApiCode::API_CODE_SUCCESS, $data = [])
{
$res_data = [
"code" => $code,
"msg" => $msg,
'data' => (object)$data,
];
return response()->json($res_data);
}
public function setError($msg, $code = ApiCode::API_CODE_ERROR, $data = [])
{
$res_data = [
"code" => $code,
"msg" => $msg,
];
if ($data) {
$res_data['data'] = $data;
}
$this->logErr($msg, $code = ApiCode::API_CODE_ERROR, $data = null);
return response()->json($res_data);
}
private function logErr($msg, $code = ApiCode::API_CODE_ERROR, $data = null)
{
$request_uri = $_SERVER['REQUEST_URI'] ?? '';
$path_info = parse_url($request_uri);
$err_info = [
'domain' => $_SERVER['HTTP_HOST'] ?? '',
'interface' => isset($path_info) ? $path_info['path'] : '',
'user_agent' => $_SERVER['HTTP_USER_AGENT'] ?? '',
'ip' => request()->getClientIp(),
'time' => time(),
'other' => '',
'request_params' => $_REQUEST,
'msg' => $msg,
"code" => $code,
"data" => $data
];
Log::error(json_encode($err_info, JSON_UNESCAPED_UNICODE));
}
}
......@@ -14,7 +14,8 @@
"guzzlehttp/guzzle": "^6.3.1|^7.0.1",
"laravel/framework": "^7.29",
"laravel/tinker": "^2.5",
"laravel/ui": "2.*"
"laravel/ui": "2.*",
"ext-json": "*"
},
"require-dev": {
"facade/ignition": "^2.0",
......
......@@ -14,8 +14,11 @@ use Illuminate\Support\Facades\Route;
|
*/
Route::middleware(['auth.api'])->group(function () {
Route::get('/user', function (Request $request) {
return $request->user();
});
Route::middleware([])->namespace('Api')->group(function () {
Route::POST('/user/login', 'AuthApiController@login');
});
//Route::middleware(['auth'])->namespace('Api')->group(function () {
// Route::POST('/user/login', 'AuthApiController@login');
//});
......@@ -14,12 +14,15 @@ use Illuminate\Support\Facades\Route;
|
*/
Auth::routes(['verify' => true]);
//Auth::routes(['verify' => true]);
Route::get('/', 'HomeController@index')->name('home');
Route::middleware(['auth'])->group(function () {
Route::get('/test', function () {
return 'Test Page';
});
});
Route::get('/', 'HomeController@index')->name('home');
Route::get('/forget', 'AuthController@forget')->name('forget');
Route::get('/about/company', 'AboutController@company')->name('about.company');
Route::get('/about/certification', 'AboutController@certification')->name('about.certification');
//Route::get('/', 'HomeController@index')->name('home')->middleware('verified');
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment