first commit
This commit is contained in:
24
backend/app/Http/Controllers/Auth/Department.php
Normal file
24
backend/app/Http/Controllers/Auth/Department.php
Normal file
@@ -0,0 +1,24 @@
|
||||
<?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\Http\Controllers\Auth;
|
||||
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use App\Services\Auth\UsersService;
|
||||
use App\Http\Controllers\Base;
|
||||
|
||||
class Department extends Base{
|
||||
|
||||
/**
|
||||
* @title 部门数据
|
||||
*/
|
||||
public function index(){
|
||||
|
||||
return $this->data;
|
||||
}
|
||||
}
|
||||
79
backend/app/Http/Controllers/Auth/Index.php
Normal file
79
backend/app/Http/Controllers/Auth/Index.php
Normal file
@@ -0,0 +1,79 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Auth;
|
||||
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use App\Http\Controllers\Base;
|
||||
use App\Services\Auth\AuthService;
|
||||
|
||||
class Index extends Base{
|
||||
/**
|
||||
* Create a new AuthController instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(){
|
||||
$this->middleware('auth:api', ['except' => ['login']]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a JWT via given credentials.
|
||||
*
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function login(AuthService $auth){
|
||||
try {
|
||||
$this->data['data'] = $auth->login();
|
||||
$this->data['code'] = 1;
|
||||
} catch (\Throwable $th) {
|
||||
$this->data['message'] = $th->getMessage();
|
||||
}
|
||||
|
||||
return $this->data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the authenticated User.
|
||||
*
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function me(){
|
||||
$this->data['data'] = auth()->user()->load(['roles', 'department']);
|
||||
return $this->data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Log the user out (Invalidate the token).
|
||||
*
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function logout(){
|
||||
auth()->logout();
|
||||
|
||||
return response()->json(['message' => 'Successfully logged out']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Refresh a token.
|
||||
*
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function refresh(){
|
||||
return $this->respondWithToken(auth()->refresh());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the token array structure.
|
||||
*
|
||||
* @param string $token
|
||||
*
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
protected function respondWithToken($token){
|
||||
return response()->json([
|
||||
'access_token' => $token,
|
||||
'token_type' => 'bearer',
|
||||
'expires_in' => auth()->factory()->getTTL() * 60
|
||||
]);
|
||||
}
|
||||
}
|
||||
63
backend/app/Http/Controllers/Auth/Permission.php
Normal file
63
backend/app/Http/Controllers/Auth/Permission.php
Normal file
@@ -0,0 +1,63 @@
|
||||
<?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\Http\Controllers\Auth;
|
||||
|
||||
use App\Http\Controllers\Base;
|
||||
use App\Services\Auth\AuthService;
|
||||
|
||||
class Permission extends Base{
|
||||
|
||||
/**
|
||||
* @title 菜单列表
|
||||
*
|
||||
* @param AuthService $service
|
||||
* @return void
|
||||
*/
|
||||
public function index(AuthService $service){
|
||||
$this->data['code'] = 1;
|
||||
$this->data['data'] = $service->getAuthMenu();
|
||||
return $this->data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @title 我的菜单及权限
|
||||
*
|
||||
* @param AuthService $service
|
||||
* @return void
|
||||
*/
|
||||
public function my(AuthService $service){
|
||||
$this->data['code'] = 1;
|
||||
$this->data['data'] = ['menu' => $service->getAuthMenu(), 'permissions' => $service->getAuthPermissions()];
|
||||
return $this->data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @title 添加菜单
|
||||
*
|
||||
* @param AuthService $service
|
||||
* @return void
|
||||
*/
|
||||
public function add(AuthService $service){
|
||||
$this->data['code'] = 1;
|
||||
$this->data['data'] = $service->getAuthMenu();
|
||||
return $this->data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @title 更新菜单
|
||||
*
|
||||
* @param AuthService $service
|
||||
* @return void
|
||||
*/
|
||||
public function edit(AuthService $service){
|
||||
$this->data['code'] = 1;
|
||||
$this->data['data'] = $service->getAuthMenu();
|
||||
return $this->data;
|
||||
}
|
||||
}
|
||||
121
backend/app/Http/Controllers/Auth/User.php
Normal file
121
backend/app/Http/Controllers/Auth/User.php
Normal file
@@ -0,0 +1,121 @@
|
||||
<?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\Http\Controllers\Auth;
|
||||
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use App\Services\Auth\UsersService;
|
||||
use App\Http\Controllers\Base;
|
||||
|
||||
class User extends Base{
|
||||
/**
|
||||
* @title 用户列表
|
||||
* @param int $uid
|
||||
* @return array
|
||||
*/
|
||||
public function index(UsersService $user){
|
||||
$list = $user->getUserList();
|
||||
$this->data['data'] = $list;
|
||||
return $this->data;
|
||||
}
|
||||
/**
|
||||
* @title 添加用户
|
||||
* @param int $uid
|
||||
* @return array
|
||||
*/
|
||||
public function add(){
|
||||
try {
|
||||
$res = app()->make(UsersService::class)->createUsers($this->request);
|
||||
$this->data['code'] = 1;
|
||||
$this->data['data'] = $res;
|
||||
} catch (\Exception $e) {
|
||||
$this->data['code'] = 0;
|
||||
$this->data['message'] = $e->getMessage();
|
||||
}
|
||||
return $this->data;
|
||||
}
|
||||
/**
|
||||
* @title 修改用户信息
|
||||
* @param int $uid
|
||||
* @return array
|
||||
*/
|
||||
public function edit(){
|
||||
try {
|
||||
$res = app()->make(UsersService::class)->updateUsers($this->request);
|
||||
$this->data['code'] = 1;
|
||||
$this->data['data'] = $res;
|
||||
$this->data['message'] = "更新成功!";
|
||||
} catch (\Exception $e) {
|
||||
$this->data['code'] = 0;
|
||||
$this->data['message'] = $e->getMessage();
|
||||
}
|
||||
return $this->data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @title 修改密码
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function passwd(){
|
||||
try {
|
||||
$res = app()->make(UsersService::class)->updateUserPassword($this->request);
|
||||
$this->data['code'] = 1;
|
||||
$this->data['data'] = $res;
|
||||
$this->data['message'] = "修改成功";
|
||||
} catch (\Exception $e) {
|
||||
$this->data['code'] = 0;
|
||||
$this->data['message'] = $e->getMessage();
|
||||
}
|
||||
return $this->data;
|
||||
}
|
||||
/**
|
||||
* @title 批量导入用户
|
||||
* @param int $uid
|
||||
* @return array
|
||||
*/
|
||||
public function insert(){
|
||||
try {
|
||||
$users = app()->make(UsersService::class)->insertAll($this->request);
|
||||
$this->data['data'] = $users;
|
||||
$this->data['code'] = 1;
|
||||
} catch (\Exception $e) {
|
||||
$this->data['code'] = 0;
|
||||
$this->data['message'] = $e->getMessage();
|
||||
}
|
||||
return $this->data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @title 用户信息
|
||||
* @param int $uid
|
||||
* @return array
|
||||
*/
|
||||
public function info(){
|
||||
$this->data['data'] = auth()->user()->load(['department', 'roles']);
|
||||
$this->data['code'] = 1;
|
||||
return $this->data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @title 用户授权
|
||||
* @return array
|
||||
*/
|
||||
public function auth(){
|
||||
try {
|
||||
$uid = $this->request->param('uid');
|
||||
$role = $this->request->param('role');
|
||||
app()->make(UsersService::class)->updateRoles($uid, $role);
|
||||
$this->data['message'] = '更新成功!';
|
||||
} catch (\Exception $e) {
|
||||
$this->data['code'] = 0;
|
||||
$this->data['message'] = $e->getMessage();
|
||||
}
|
||||
return $this->data;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user