mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/unity.git
synced 2026-08-19 04:13:58 +00:00
setup
This commit is contained in:
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Admin\Api;
|
||||
|
||||
use Auth;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
use App\Http\Modules\Admin\AdminModule;
|
||||
|
||||
use App\Http\Controllers\Admin\BaseController;
|
||||
|
||||
class AdminController extends BaseController
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
public function self(Request $request)
|
||||
{
|
||||
$self = AdminModule::self($request);
|
||||
return $self;
|
||||
}
|
||||
|
||||
public function list(Request $request)
|
||||
{
|
||||
$admin = AdminModule::list($request);
|
||||
return $admin;
|
||||
}
|
||||
|
||||
public function show(Request $request, $hash_id)
|
||||
{
|
||||
$admin = AdminModule::show($request, $hash_id);
|
||||
return $admin;
|
||||
}
|
||||
|
||||
public function store(Request $request)
|
||||
{
|
||||
$admin = AdminModule::store($request);
|
||||
return $admin;
|
||||
}
|
||||
|
||||
public function update(Request $request, $hash_id)
|
||||
{
|
||||
$admin = AdminModule::update($request, $hash_id);
|
||||
return $admin;
|
||||
}
|
||||
|
||||
public function validCheck(Request $request, $hash_id = '')
|
||||
{
|
||||
$method = empty($hash_id) ? 'POST' :'PUT';
|
||||
$valid = AdminModule::validCheck($request, $hash_id, $method);
|
||||
return $valid;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Admin\API;
|
||||
|
||||
use Auth;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
use App\Http\Modules\Admin\AdminRoleModule;
|
||||
|
||||
use App\Http\Controllers\Admin\BaseController;
|
||||
|
||||
class AdminRoleController extends BaseController
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
public function list(Request $request)
|
||||
{
|
||||
$admin_role = AdminRoleModule::list($request);
|
||||
return $admin_role;
|
||||
}
|
||||
|
||||
public function show(Request $request, $hash_id)
|
||||
{
|
||||
$admin_role = AdminRoleModule::show($request, $hash_id);
|
||||
return $admin_role;
|
||||
}
|
||||
|
||||
public function store(Request $request)
|
||||
{
|
||||
$admin_role = AdminRoleModule::store($request);
|
||||
return $admin_role;
|
||||
}
|
||||
|
||||
public function update(Request $request, $hash_id)
|
||||
{
|
||||
$admin_role = AdminRoleModule::update($request, $hash_id);
|
||||
return $admin_role;
|
||||
}
|
||||
|
||||
public function validCheck(Request $request, $hash_id = '')
|
||||
{
|
||||
$method = empty($hash_id) ? 'POST' :'PUT';
|
||||
$valid = AdminRoleModule::validCheck($request, $hash_id, $method);
|
||||
return $valid;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Admin\Api;
|
||||
|
||||
use Auth;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
use App\Http\Modules\Admin\LoginModule;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
|
||||
class LoginController extends Controller
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public function login(Request $request)
|
||||
{
|
||||
$login = LoginModule::login($request);
|
||||
return $login;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Admin\API;
|
||||
|
||||
use Auth;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
use App\Http\Modules\Admin\PermissionModule;
|
||||
|
||||
use App\Http\Controllers\Admin\BaseController;
|
||||
|
||||
class PermissionController extends BaseController
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
public function list(Request $request)
|
||||
{
|
||||
$permission = PermissionModule::list($request);
|
||||
return $permission;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Admin\API;
|
||||
|
||||
use Auth;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
use App\Http\Modules\Admin\UserModule;
|
||||
|
||||
use App\Http\Controllers\Admin\BaseController;
|
||||
|
||||
class UserController extends BaseController
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
public function list(Request $request)
|
||||
{
|
||||
$user = UserModule::list($request);
|
||||
return $user;
|
||||
}
|
||||
|
||||
public function show(Request $request, $hash_id)
|
||||
{
|
||||
$user = UserModule::show($request, $hash_id);
|
||||
return $user;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Admin;
|
||||
use Auth;
|
||||
use App\Http\Controllers\Controller;
|
||||
|
||||
class BaseController extends Controller {
|
||||
|
||||
public function __construct() {
|
||||
\Config::set('auth.guards.api.provider', 'admins');
|
||||
$this->middleware(['auth:admin-api', 'scope:only-admin']);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Admin\Web;
|
||||
|
||||
use Auth;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
|
||||
class AppController extends Controller
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public function index(Request $request)
|
||||
{
|
||||
return view('admin.app');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
|
||||
use Illuminate\Foundation\Bus\DispatchesJobs;
|
||||
use Illuminate\Foundation\Validation\ValidatesRequests;
|
||||
use Illuminate\Routing\Controller as BaseController;
|
||||
|
||||
class Controller extends BaseController
|
||||
{
|
||||
use AuthorizesRequests, DispatchesJobs, ValidatesRequests;
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\User\Api;
|
||||
|
||||
use Auth;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
use App\Http\Modules\User\LoginModule;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
|
||||
class LoginController extends Controller
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public function login(Request $request)
|
||||
{
|
||||
$login = LoginModule::login($request);
|
||||
return $login;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\User\Api;
|
||||
|
||||
use Auth;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
use App\Http\Modules\User\UserModule;
|
||||
|
||||
use App\Http\Controllers\User\BaseController;
|
||||
|
||||
class UserController extends BaseController
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
public function self(Request $request)
|
||||
{
|
||||
$self = UserModule::self($request);
|
||||
return $self;
|
||||
}
|
||||
|
||||
// public function list(Request $request)
|
||||
// {
|
||||
// $admin_list = AdminModule::list($request);
|
||||
// return $admin_list;
|
||||
// }
|
||||
|
||||
// public function show(Request $request, $hash_id)
|
||||
// {
|
||||
// $admin = AdminModule::show($request, $hash_id);
|
||||
// return $admin;
|
||||
// }
|
||||
|
||||
// public function store(Request $request)
|
||||
// {
|
||||
// $admin = AdminModule::store($request);
|
||||
// return $admin;
|
||||
// }
|
||||
|
||||
// public function update(Request $request, $hash_id)
|
||||
// {
|
||||
// $admin = AdminModule::update($request, $hash_id);
|
||||
// return $admin;
|
||||
// }
|
||||
|
||||
// public function validCheck(Request $request, $hash_id = '')
|
||||
// {
|
||||
// $method = empty($hash_id) ? 'POST' :'PUT' ;
|
||||
// $valid = AdminModule::validCheck($request, $hash_id, $method);
|
||||
// return $valid;
|
||||
// }
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\User;
|
||||
use Auth;
|
||||
use App\Http\Controllers\Controller;
|
||||
|
||||
class BaseController extends Controller{
|
||||
|
||||
public function __construct() {
|
||||
\Config::set('auth.guards.api.provider', 'users');
|
||||
$this->middleware(['auth:user-api', 'scope:only-user']);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\User\Web;
|
||||
|
||||
use Auth;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
|
||||
class AppController extends Controller
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public function index(Request $request)
|
||||
{
|
||||
return view('user.app');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,91 @@
|
||||
<?php
|
||||
namespace App\Http\Helpers;
|
||||
|
||||
use Illuminate\Support\Str;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
|
||||
class ExcelHandel
|
||||
{
|
||||
function __construct()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public static function generateFolder($set_path = '')
|
||||
{
|
||||
$folder = public_path() . $set_path;
|
||||
\File::isDirectory($folder) or \File::makeDirectory($folder, 0777, true, true); //check folder is exist
|
||||
return $folder;
|
||||
}
|
||||
|
||||
public static function insertExcel($path = '', $base64Set = [])
|
||||
{
|
||||
$file_info = [];
|
||||
$folder_path = ExcelHandel::generateFolder('/share/excels/' . $path);
|
||||
|
||||
foreach ($base64Set as $key => $row) {
|
||||
|
||||
$exceldata = $row;
|
||||
$filename = (string) Str::uuid();
|
||||
|
||||
$f = finfo_open();
|
||||
$mime_type = finfo_file($f, $exceldata, FILEINFO_MIME_TYPE);
|
||||
|
||||
$extension = 'xls';
|
||||
|
||||
switch ($mime_type) {
|
||||
case 'application/vnd.ms-excel':
|
||||
$extension = 'xls';
|
||||
break;
|
||||
case 'application/zip':
|
||||
$extension = 'xlsx';
|
||||
break;
|
||||
}
|
||||
|
||||
if (empty($extension)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$exceldata = explode('base64,', $exceldata);
|
||||
$exceldata = base64_decode($exceldata[1]);
|
||||
|
||||
$filename_with_ext = $filename . '.' . $extension;
|
||||
|
||||
$file = ExcelHandel::generateExcel($path, $exceldata, $filename, $extension);
|
||||
|
||||
$file_info[] = [
|
||||
'path' => $path,
|
||||
'filename' => $filename_with_ext,
|
||||
'mime_type' => $mime_type,
|
||||
'extension' => $extension,
|
||||
'file_info' => empty($file) ? [] : $file,
|
||||
];
|
||||
}
|
||||
|
||||
return $file_info;
|
||||
}
|
||||
|
||||
public static function generateExcel($path = '', $exceldata = '', $filename = '', $extension = '')
|
||||
{
|
||||
$file_info = [];
|
||||
$file = \File::put(public_path('share/excels/' . $path) . '/' . $filename . '.' . $extension, $exceldata);
|
||||
$file_info['original']['file'] = public_path('/share/excels/' . $path . '/' . $filename . '.' . $extension);
|
||||
$file_info['large']['file'] = public_path('/share/excels/' . $path . '/' . $filename . '.' . $extension);
|
||||
$file_info['medium']['file'] = public_path('/share/excels/' . $path . '/' . $filename . '.' . $extension);
|
||||
$file_info['small']['file'] = public_path('/share/excels/' . $path . '/' . $filename . '.' . $extension);
|
||||
|
||||
return $file_info;
|
||||
}
|
||||
|
||||
public static function removeExcel($excel_info = [])
|
||||
{
|
||||
$excel_info = json_decode(json_encode($excel_info), true);
|
||||
foreach ($excel_info as $key => $row) {
|
||||
if (!empty($row['path'])) {
|
||||
\File::delete([$row['file_info']['original']['file']]);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,195 @@
|
||||
<?php
|
||||
namespace App\Http\Helpers;
|
||||
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
|
||||
class General
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public static function storeCachePerviousQuery($query = '', $name = '')
|
||||
{
|
||||
$query_string = urldecode(preg_replace('/(%5B)\d+(%5D=)/i', '$1$2', http_build_query($query)));
|
||||
Cache::put($name, $query_string, 1800);
|
||||
}
|
||||
|
||||
public static function getCachePerviousQuery($name = '')
|
||||
{
|
||||
return Cache::get($name);
|
||||
}
|
||||
|
||||
public static function returnTokenData($object = [], $token = '')
|
||||
{
|
||||
$data = (object)[
|
||||
'status' => true,
|
||||
'access_token' => $token,
|
||||
'data' => $object
|
||||
];
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
public static function returnErrorData($error = [])
|
||||
{
|
||||
$data = (object)[
|
||||
'status' => false,
|
||||
'errors' => $error
|
||||
];
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
public static function returnData($object = [], $query_string = '')
|
||||
{
|
||||
if ($query_string) {
|
||||
$data = (object)[
|
||||
'status' => true,
|
||||
'pervious_query' => $query_string,
|
||||
'data' => $object
|
||||
];
|
||||
}
|
||||
else {
|
||||
$data = (object)[
|
||||
'status' => true,
|
||||
'data' => $object
|
||||
];
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
public static function paginationGenerator($data = [], $params = [], $extract = [])
|
||||
{
|
||||
$pagination = [];
|
||||
|
||||
$data->appends($params)->links();
|
||||
$pagination = [
|
||||
'status' => true,
|
||||
'total' => $data->total(),
|
||||
'has_more_page' => $data->hasMorePages(),
|
||||
'query_string' => urldecode(preg_replace('/(%5B)\d+(%5D=)/i', '$1$2', http_build_query($params))),
|
||||
'page' => [
|
||||
'next_page' => urldecode(preg_replace('/(%5B)\d+(%5D=)/i', '$1$2', $data->nextPageUrl())),
|
||||
'pervious_page' => urldecode(preg_replace('/(%5B)\d+(%5D=)/i', '$1$2', $data->previousPageUrl())),
|
||||
],
|
||||
'data' => $extract
|
||||
];
|
||||
|
||||
return $pagination;
|
||||
}
|
||||
|
||||
public static function returnMimeType($file = [])
|
||||
{
|
||||
$f = finfo_open();
|
||||
$mime_type = finfo_file($f, $file[0], FILEINFO_MIME_TYPE);
|
||||
return $mime_type;
|
||||
}
|
||||
|
||||
public static function returnQueryString($params = [])
|
||||
{
|
||||
$query_string = urldecode(preg_replace('/(%5B)\d+(%5D=)/i', '$1$2', http_build_query($params)));
|
||||
return $query_string;
|
||||
}
|
||||
|
||||
public static function seoURL($string)
|
||||
{
|
||||
//Lower case everything
|
||||
$string = strtolower($string);
|
||||
//Remove all url format string
|
||||
$string =preg_replace("/\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|$!:,.;]*[A-Z0-9+&@#\/%=~_|$]/i", "", $string);
|
||||
|
||||
$string = preg_replace("~[^\p{L}\n\s_]+~u", "", $string);
|
||||
|
||||
//Clean up multiple dashes or whitespaces
|
||||
$string = preg_replace("/[\s-]+/", " ", $string);
|
||||
//Trim first - avoid spaces on beginning or end of the text
|
||||
$string = trim($string);
|
||||
|
||||
// Check whether is English
|
||||
$match = preg_match('/^[A-Za-z0-9 _]+$/', $string);
|
||||
|
||||
$isEnglish = $match == 1;
|
||||
|
||||
if ($isEnglish == 1) {
|
||||
$string = mb_substr($string, 0, 60);
|
||||
$strArray = explode(" ",$string);
|
||||
if (sizeof($strArray) != 1) {
|
||||
// unset($strArray[intval(sizeof($strArray))-1]);
|
||||
}
|
||||
$string = implode(' ',$strArray);
|
||||
|
||||
}else{
|
||||
$string = mb_substr($string, 0, 20,'UTF8');
|
||||
}
|
||||
|
||||
//Convert whitespaces and underscore to dash
|
||||
$string = preg_replace("/[\s_]/", "-", $string);
|
||||
|
||||
//Check empty string
|
||||
if (empty($string)) {
|
||||
$string = 'untitled';
|
||||
}
|
||||
return $string;
|
||||
}
|
||||
|
||||
public static function shortenNumber($number){
|
||||
if ($number < 1000) {
|
||||
$nformat = number_format($number);
|
||||
}else if ($number < 1000000) {
|
||||
// Anything less than a million
|
||||
$nformat = number_format($number/1000,1) . 'k';
|
||||
} else if ($number < 1000000000) {
|
||||
// Anything less than a billion
|
||||
$nformat = number_format($number / 1000000, 3) . 'm';
|
||||
} else {
|
||||
// At least a billion
|
||||
$nformat = number_format($number / 1000000000, 3) . 'b';
|
||||
}
|
||||
|
||||
return $nformat;
|
||||
}
|
||||
|
||||
public static function getExcerpt($str, $maxLength = 60, $startPos = 0)
|
||||
{
|
||||
$str = strip_tags($str);
|
||||
$str = html_entity_decode($str, ENT_QUOTES);
|
||||
$excerpt = $str;
|
||||
if(strlen($str) > $maxLength) {
|
||||
$excerpt = '';
|
||||
|
||||
$excerpt = mb_substr($str, $startPos, $maxLength-3, 'UTF-8');
|
||||
|
||||
$excerpt .= '...';
|
||||
}
|
||||
return $excerpt;
|
||||
}
|
||||
|
||||
public static function convertDayTime($date_time)
|
||||
{
|
||||
$date_time = date('Y-m-d H:i:s', strtotime($date_time));
|
||||
$dteStart = new \DateTime(date('Y-m-d H:i:s'));
|
||||
$dteEnd = new \DateTime($date_time);
|
||||
$dteDiff = $dteStart->diff($dteEnd);
|
||||
|
||||
if($dteEnd->format('Y') < $dteStart->format('Y')) {
|
||||
return 'Active ' . $dteEnd->format('d M Y');
|
||||
}
|
||||
elseif($dteDiff->days > 0) { //already posted one day
|
||||
return 'Active ' . $dteEnd->format('d M');
|
||||
}
|
||||
elseif($dteDiff->format('%H') > 0) { //already posted one hours
|
||||
$text = $dteDiff->format('%h') != 1 ? 'hrs ago' : 'hr ago';
|
||||
return 'Active ' . $dteDiff->format('%h') . $text;
|
||||
}
|
||||
elseif($dteDiff->format('%I') > 0) { //already posted one min
|
||||
return 'Active ' . $dteDiff->format('%i') . ' mins ago';
|
||||
}
|
||||
else{
|
||||
return 'Active ' . $dteDiff->format('%s') . ' sec ago'; //already posted one sec
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
namespace App\Http\Helpers;
|
||||
|
||||
use Hashids\Hashids;
|
||||
|
||||
class Hasher
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public static function encode($entity = '', ...$args)
|
||||
{
|
||||
$hash = new Hashids($entity, 11);
|
||||
return $hash->encode(...$args);
|
||||
}
|
||||
|
||||
public static function decode($entity = '', $enc)
|
||||
{
|
||||
if (is_int($enc)) {
|
||||
return $enc;
|
||||
}
|
||||
|
||||
$hash = new Hashids($entity, 11);
|
||||
return $hash->decode($enc) ? $hash->decode($enc)[0] : '';
|
||||
}
|
||||
|
||||
public static function decodeArray($entity = '', $set = [])
|
||||
{
|
||||
$return_set = [];
|
||||
foreach ($set as $key => $row) {
|
||||
$return_set[] = Hasher::decode($entity, $row);
|
||||
}
|
||||
|
||||
return $return_set;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,139 @@
|
||||
<?php
|
||||
namespace App\Http\Helpers;
|
||||
|
||||
use Illuminate\Support\Str;
|
||||
use Image;
|
||||
|
||||
class ImageHandel
|
||||
{
|
||||
function __construct()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public static function getImgFullPath($img_info = [], $type = 'object')
|
||||
{
|
||||
$default_file = asset('share/no-image.png');
|
||||
|
||||
if ($type == 'object') {
|
||||
$default_file = asset('share/non-image.png');
|
||||
}
|
||||
else if ($type == 'person') {
|
||||
$default_file = asset('share/non-person.png');
|
||||
}
|
||||
else if ($type == 'logo') {
|
||||
$default_file = asset('share/non-logo.png');
|
||||
}
|
||||
|
||||
$img_info = json_decode($img_info);
|
||||
if (!empty($img_info)) {
|
||||
foreach ($img_info as $key_img => $row_img) {
|
||||
$img_info[$key_img]->file_info->original->file = asset('storage/' . $row_img->file_info->original->file);
|
||||
}
|
||||
}
|
||||
else {
|
||||
$img_info = [(object)[
|
||||
'empty' => true,
|
||||
'file_info' => (object)[
|
||||
'original' => (object) [
|
||||
'file' => $default_file
|
||||
],
|
||||
'large' => (object) [
|
||||
'file' => $default_file
|
||||
],
|
||||
'medium' => (object) [
|
||||
'file' => $default_file
|
||||
],
|
||||
'small' => (object) [
|
||||
'file' => $default_file
|
||||
],
|
||||
]
|
||||
]];
|
||||
}
|
||||
return $img_info;
|
||||
}
|
||||
|
||||
public static function extractFullPath($file = '')
|
||||
{
|
||||
|
||||
$file = explode(asset('/storage'), $file);
|
||||
|
||||
|
||||
return $file[1];
|
||||
}
|
||||
|
||||
public static function generateFolder($path = '')
|
||||
{
|
||||
$folder = \Storage::disk('public')->makeDirectory($path);
|
||||
return $folder;
|
||||
}
|
||||
|
||||
public static function insertImage($path = '', $file = '')
|
||||
{
|
||||
$image = ImageHandel::base64ToImage($path, $file);
|
||||
return $image;
|
||||
}
|
||||
|
||||
public static function base64ToImage($path = '', $base64Set = [])
|
||||
{
|
||||
$img_info = [];
|
||||
$folder_path = ImageHandel::generateFolder('images/' . $path);
|
||||
|
||||
foreach ($base64Set as $key => $row) {
|
||||
|
||||
$imgdata = $row;
|
||||
$filename = (string) Str::uuid();
|
||||
|
||||
$f = finfo_open();
|
||||
$mime_type = finfo_file($f, $imgdata, FILEINFO_MIME_TYPE);
|
||||
|
||||
$extension = '';
|
||||
switch ($mime_type) {
|
||||
case 'image/gif':
|
||||
$extension = 'gif';
|
||||
break;
|
||||
case 'image/png':
|
||||
$extension = 'png';
|
||||
break;
|
||||
case 'image/jpeg':
|
||||
$extension = 'jpg';
|
||||
break;
|
||||
}
|
||||
|
||||
if (empty($extension)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$file_info = [];
|
||||
|
||||
$filename = $filename . '.' . $extension;
|
||||
$img = Image::make($row)->save(storage_path('app/public/images/' . $path) . '/' . $filename);
|
||||
|
||||
$file_info['original']['file'] = 'images/' . $path . '/' . $filename;
|
||||
$file_info['original']['width'] = $img->width();
|
||||
$file_info['original']['height'] = $img->height();
|
||||
|
||||
$img_info[] = [
|
||||
'on_cloud' => false,
|
||||
'path' => $path,
|
||||
'filename' => $filename,
|
||||
'mime_type' => $mime_type,
|
||||
'extension' => $extension,
|
||||
'file_info' => empty($file_info) ? [] : $file_info,
|
||||
];
|
||||
}
|
||||
|
||||
return $img_info;
|
||||
}
|
||||
|
||||
public static function removeImage($img_info = [])
|
||||
{
|
||||
foreach ($img_info as $key_img => $row_img) {
|
||||
if (!empty($row_img->path) && $row_img->path != 'seeder') {
|
||||
$img_original = ImageHandel::extractFullPath($row_img->file_info->original->file);
|
||||
\Storage::disk('public')->delete([$img_original]);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,114 @@
|
||||
<?php
|
||||
namespace App\Http\Helpers;
|
||||
|
||||
use Illuminate\Support\Str;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
|
||||
class PdfHandel
|
||||
{
|
||||
function __construct()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public static function getPdfFullPath($video_info = [])
|
||||
{
|
||||
$video_info = json_decode($video_info);
|
||||
if (!empty($video_info)) {
|
||||
foreach ($video_info as $key_img => $row_img) {
|
||||
$video_info[$key_img]->file_info->original->file = asset($row_img->file_info->original->file);
|
||||
}
|
||||
}
|
||||
else {
|
||||
$video_info = [(object)[
|
||||
'empty' => true,
|
||||
'file_info' => (object)[
|
||||
'original' => (object) [
|
||||
'file' => asset('share/no-image.png')
|
||||
]
|
||||
]
|
||||
]];
|
||||
}
|
||||
return $video_info;
|
||||
}
|
||||
|
||||
public static function extractFullPath($file = '')
|
||||
{
|
||||
$file = explode(asset('/'), $file);
|
||||
return $file[1];
|
||||
}
|
||||
|
||||
public static function generateFolder($set_path = '')
|
||||
{
|
||||
$folder = public_path() . $set_path;
|
||||
\File::isDirectory($folder) or \File::makeDirectory($folder, 0777, true, true); //check folder is exist
|
||||
return $folder;
|
||||
}
|
||||
|
||||
public static function insertPdf($path = '', $base64Set = [])
|
||||
{
|
||||
$file_info = [];
|
||||
$folder_path = PdfHandel::generateFolder('/share/images/' . $path);
|
||||
|
||||
foreach ($base64Set as $key => $row) {
|
||||
|
||||
$pdfdata = $row;
|
||||
$filename = (string) Str::uuid();
|
||||
|
||||
$f = finfo_open();
|
||||
$mime_type = finfo_file($f, $pdfdata, FILEINFO_MIME_TYPE);
|
||||
|
||||
$extension = 'pdf';
|
||||
switch ($mime_type) {
|
||||
case 'application/pdf':
|
||||
$extension = 'pdf';
|
||||
break;
|
||||
}
|
||||
|
||||
if (empty($extension)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$pdfdata = explode('base64,', $pdfdata);
|
||||
$pdfdata = base64_decode($pdfdata[1]);
|
||||
|
||||
$filename_with_ext = $filename . '.' . $extension;
|
||||
|
||||
$file = PdfHandel::generatePdf($path, $pdfdata, $filename, $extension);
|
||||
|
||||
$file_info[] = [
|
||||
'path' => $path,
|
||||
'filename' => $filename_with_ext,
|
||||
'mime_type' => $mime_type,
|
||||
'extension' => $extension,
|
||||
'file_info' => empty($file) ? [] : $file,
|
||||
];
|
||||
}
|
||||
|
||||
return $file_info;
|
||||
}
|
||||
|
||||
public static function generatePdf($path = '', $pdfdata = '', $filename = '', $extension = '')
|
||||
{
|
||||
$file_info = [];
|
||||
$file = \File::put(public_path('share/images/' . $path) . '/' . $filename . '.' . $extension, $pdfdata);
|
||||
$file_info['original']['file'] = asset('/share/images/' . $path . '/' . $filename . '.' . $extension);
|
||||
$file_info['large']['file'] = asset('/share/images/' . $path . '/' . $filename . '.' . $extension);
|
||||
$file_info['medium']['file'] = asset('/share/images/' . $path . '/' . $filename . '.' . $extension);
|
||||
$file_info['small']['file'] = asset('/share/images/' . $path . '/' . $filename . '.' . $extension);
|
||||
|
||||
return $file_info;
|
||||
}
|
||||
|
||||
public static function removePdf($img_info = [])
|
||||
{
|
||||
foreach ($img_info as $key_img => $row_img) {
|
||||
if (!empty($row_img->path)) {
|
||||
$img_original = PdfHandel::extractFullPath($row_img->file_info->original->file);
|
||||
\File::delete([$img_original]);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http;
|
||||
|
||||
use Illuminate\Foundation\Http\Kernel as HttpKernel;
|
||||
|
||||
class Kernel extends HttpKernel
|
||||
{
|
||||
/**
|
||||
* The application's global HTTP middleware stack.
|
||||
*
|
||||
* These middleware are run during every request to your application.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $middleware = [
|
||||
// \App\Http\Middleware\TrustHosts::class,
|
||||
\App\Http\Middleware\TrustProxies::class,
|
||||
\Fruitcake\Cors\HandleCors::class,
|
||||
\App\Http\Middleware\PreventRequestsDuringMaintenance::class,
|
||||
\Illuminate\Foundation\Http\Middleware\ValidatePostSize::class,
|
||||
\App\Http\Middleware\TrimStrings::class,
|
||||
\Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull::class,
|
||||
\App\Http\Middleware\Cors::class,
|
||||
];
|
||||
|
||||
/**
|
||||
* The application's route middleware groups.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $middlewareGroups = [
|
||||
'web' => [
|
||||
\App\Http\Middleware\EncryptCookies::class,
|
||||
\Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
|
||||
\Illuminate\Session\Middleware\StartSession::class,
|
||||
// \Illuminate\Session\Middleware\AuthenticateSession::class,
|
||||
\Illuminate\View\Middleware\ShareErrorsFromSession::class,
|
||||
// \App\Http\Middleware\VerifyCsrfToken::class,
|
||||
\Illuminate\Routing\Middleware\SubstituteBindings::class,
|
||||
],
|
||||
|
||||
'api' => [
|
||||
'throttle:api',
|
||||
\Illuminate\Routing\Middleware\SubstituteBindings::class,
|
||||
],
|
||||
];
|
||||
|
||||
/**
|
||||
* The application's route middleware.
|
||||
*
|
||||
* These middleware may be assigned to groups or used individually.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $routeMiddleware = [
|
||||
'auth' => \App\Http\Middleware\Authenticate::class,
|
||||
'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class,
|
||||
'cache.headers' => \Illuminate\Http\Middleware\SetCacheHeaders::class,
|
||||
'can' => \Illuminate\Auth\Middleware\Authorize::class,
|
||||
'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class,
|
||||
'password.confirm' => \Illuminate\Auth\Middleware\RequirePassword::class,
|
||||
'signed' => \Illuminate\Routing\Middleware\ValidateSignature::class,
|
||||
'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,
|
||||
'verified' => \Illuminate\Auth\Middleware\EnsureEmailIsVerified::class,
|
||||
|
||||
'scope' => \App\Http\Middleware\ScopeCheck::class,
|
||||
'role' => \Spatie\Permission\Middlewares\RoleMiddleware::class,
|
||||
'permission' => \Spatie\Permission\Middlewares\PermissionMiddleware::class,
|
||||
'role_or_permission' => \Spatie\Permission\Middlewares\RoleOrPermissionMiddleware::class,
|
||||
'is_app_access_authorized' => \App\Http\Middleware\IsAppAccessAuthorized::class,
|
||||
];
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Illuminate\Auth\Middleware\Authenticate as Middleware;
|
||||
|
||||
class Authenticate extends Middleware
|
||||
{
|
||||
/**
|
||||
* Get the path the user should be redirected to when they are not authenticated.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return string|null
|
||||
*/
|
||||
protected function redirectTo($request)
|
||||
{
|
||||
if (! $request->expectsJson()) {
|
||||
return route('unauthorized');
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Closure;
|
||||
|
||||
class Cors
|
||||
{
|
||||
/**
|
||||
* Handle an incoming request.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \Closure $next
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle($request, Closure $next)
|
||||
{
|
||||
return $next($request)
|
||||
->header('Access-Control-Allow-Origin', '*')
|
||||
->header('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE')
|
||||
->header('Access-Control-Allow-Headers', 'Accept, Authorization, Content-Type, X-CSRF-Token, X-Requested-With', 'App-Key');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Illuminate\Cookie\Middleware\EncryptCookies as Middleware;
|
||||
|
||||
class EncryptCookies extends Middleware
|
||||
{
|
||||
/**
|
||||
* The names of the cookies that should not be encrypted.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $except = [
|
||||
//
|
||||
];
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Closure;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class IsAppAccessAuthorized
|
||||
{
|
||||
/**
|
||||
* Handle an incoming request.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \Closure $next
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle(Request $request, Closure $next)
|
||||
{
|
||||
if (isset(getallheaders()['App-Key']) && (string) getallheaders()['App-Key'] === config('constants.app_key')) {
|
||||
return $next($request);
|
||||
}
|
||||
else {
|
||||
return response()->json([
|
||||
'status' => false,
|
||||
'error' => config('error_code.invalid_app_key')
|
||||
], 422);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Illuminate\Foundation\Http\Middleware\PreventRequestsDuringMaintenance as Middleware;
|
||||
|
||||
class PreventRequestsDuringMaintenance extends Middleware
|
||||
{
|
||||
/**
|
||||
* The URIs that should be reachable while maintenance mode is enabled.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $except = [
|
||||
//
|
||||
];
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use App\Providers\RouteServiceProvider;
|
||||
use Closure;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
class RedirectIfAuthenticated
|
||||
{
|
||||
/**
|
||||
* Handle an incoming request.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \Closure $next
|
||||
* @param string|null ...$guards
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle(Request $request, Closure $next, ...$guards)
|
||||
{
|
||||
$guards = empty($guards) ? [null] : $guards;
|
||||
|
||||
foreach ($guards as $guard) {
|
||||
if (Auth::guard($guard)->check()) {
|
||||
return redirect(RouteServiceProvider::HOME);
|
||||
}
|
||||
}
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Auth;
|
||||
use Closure;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class ScopeCheck
|
||||
{
|
||||
/**
|
||||
* Handle an incoming request.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \Closure $next
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle(Request $request, Closure $next, $scope)
|
||||
{
|
||||
if (! $request->user() || ! $request->user()->token()) {
|
||||
throw new AuthenticationException;
|
||||
}
|
||||
|
||||
$user = $request->user();
|
||||
|
||||
if ($request->user()->tokenCan($scope)) {
|
||||
return $next($request);
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'status' => false,
|
||||
'error' => 'UNAUTHORIZE'
|
||||
], 403);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Illuminate\Foundation\Http\Middleware\TrimStrings as Middleware;
|
||||
|
||||
class TrimStrings extends Middleware
|
||||
{
|
||||
/**
|
||||
* The names of the attributes that should not be trimmed.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $except = [
|
||||
'password',
|
||||
'password_confirmation',
|
||||
];
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Illuminate\Http\Middleware\TrustHosts as Middleware;
|
||||
|
||||
class TrustHosts extends Middleware
|
||||
{
|
||||
/**
|
||||
* Get the host patterns that should be trusted.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function hosts()
|
||||
{
|
||||
return [
|
||||
$this->allSubdomainsOfApplicationUrl(),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Fideloper\Proxy\TrustProxies as Middleware;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class TrustProxies extends Middleware
|
||||
{
|
||||
/**
|
||||
* The trusted proxies for this application.
|
||||
*
|
||||
* @var array|string|null
|
||||
*/
|
||||
protected $proxies;
|
||||
|
||||
/**
|
||||
* The headers that should be used to detect proxies.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $headers = Request::HEADER_X_FORWARDED_FOR | Request::HEADER_X_FORWARDED_HOST | Request::HEADER_X_FORWARDED_PORT | Request::HEADER_X_FORWARDED_PROTO | Request::HEADER_X_FORWARDED_AWS_ELB;
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Illuminate\Foundation\Http\Middleware\VerifyCsrfToken as Middleware;
|
||||
|
||||
class VerifyCsrfToken extends Middleware
|
||||
{
|
||||
/**
|
||||
* The URIs that should be excluded from CSRF verification.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $except = [
|
||||
'user-backsys/api/*',
|
||||
'admin-backsys/api/*',
|
||||
'contributor-backsys/api/*',
|
||||
'reviewer-backsys/api/*'
|
||||
];
|
||||
}
|
||||
@@ -0,0 +1,277 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Modules\Admin;
|
||||
|
||||
use Auth;
|
||||
use App\Models\Admin;
|
||||
use App\Models\AdminLog;
|
||||
|
||||
use App\Http\Rules\Admin\Image64Check;
|
||||
use App\Http\Rules\Admin\ExistCheck;
|
||||
|
||||
use App\Http\Helpers\General;
|
||||
use App\Http\Helpers\Hasher;
|
||||
use App\Http\Helpers\ImageHandel;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
use App\Http\Controllers\Admin\BaseController;
|
||||
|
||||
class AdminModule extends BaseController
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
public static function self(Request $request)
|
||||
{
|
||||
$self = Auth::guard('admin-api')->user();
|
||||
$self->role_list = $self->getRoleNames();
|
||||
$self->permission_list = $self->getAllPermissions()->pluck('name');
|
||||
|
||||
unset($self->roles);
|
||||
unset($self->permissions);
|
||||
|
||||
$data = General::returnData($self);
|
||||
return response()->json($data);
|
||||
}
|
||||
|
||||
public static function list(Request $request)
|
||||
{
|
||||
General::storeCachePerviousQuery($request->query(), 'admin_query');
|
||||
|
||||
$name = $request->get('name', null);
|
||||
$email = $request->get('email', null);
|
||||
$status = $request->get('status', []);
|
||||
$page = $request->get('page', null);
|
||||
$limit = $request->get('limit', 10);
|
||||
|
||||
$query = Admin::query();
|
||||
|
||||
if (strlen($name) > 0) {
|
||||
$query->where('name', 'like', '%' . $name . '%');
|
||||
}
|
||||
|
||||
if (strlen($email) > 0) {
|
||||
$query->where('email', 'like', '%' . $email . '%');
|
||||
}
|
||||
|
||||
if (!empty($status) > 0) {
|
||||
$query->whereIn('status', $status);
|
||||
}
|
||||
|
||||
if (!Auth::guard('admin-api')->user()->hasRole('Shadow Admin')) {
|
||||
$query->whereNotIn('id', [1]);
|
||||
}
|
||||
|
||||
$query->orderBy('id', 'desc');
|
||||
|
||||
$params = [
|
||||
'name' => $name,
|
||||
'email' => $email,
|
||||
'status' => $status,
|
||||
'page' => $page
|
||||
];
|
||||
|
||||
$admin_list = $query->paginate($limit);
|
||||
|
||||
$extract = [];
|
||||
foreach ($admin_list as $key => $row) {
|
||||
$extract[] = $row;
|
||||
|
||||
}
|
||||
$pagination = General::paginationGenerator($admin_list, $params, $extract);
|
||||
|
||||
return $pagination;
|
||||
}
|
||||
|
||||
public static function show(Request $request, $hash_id)
|
||||
{
|
||||
$id = Hasher::decode('admins', $hash_id);
|
||||
$admin = Admin::find($id);
|
||||
if ($admin) {
|
||||
$data = General::returnData($admin, '');
|
||||
return response()->json($data);
|
||||
}
|
||||
return abort(404);
|
||||
}
|
||||
|
||||
public static function store(Request $request)
|
||||
{
|
||||
$validation = AdminModule::validation($request);
|
||||
if (!$validation->status) {
|
||||
return response()->json($validation, 422);
|
||||
}
|
||||
|
||||
DB::beginTransaction();
|
||||
|
||||
$name = $request->input('name');
|
||||
$email = $request->input('email');
|
||||
$password = $request->input('password');
|
||||
$status = $request->input('status');
|
||||
|
||||
$admin = new Admin();
|
||||
$admin->name = $name;
|
||||
$admin->email = $email;
|
||||
$admin->password = bcrypt($password);
|
||||
$admin->status = $status;
|
||||
|
||||
// img
|
||||
$img = $request->input('img');
|
||||
if (!empty($img)) {
|
||||
$img = json_encode(ImageHandel::insertImage('admin', $img));
|
||||
$admin->img = $img;
|
||||
if (!$img) {
|
||||
DB::rollBack();
|
||||
}
|
||||
}
|
||||
|
||||
$admin->created_by = Auth::guard('admin-api')->user()->id;
|
||||
$admin->updated_by = Auth::guard('admin-api')->user()->id;
|
||||
$admin->save();
|
||||
|
||||
// role
|
||||
$role_id = $request->input('role_id');
|
||||
$role_id = Hasher::decodeArray('roles', $role_id);
|
||||
$admin->syncRoles($role_id);
|
||||
|
||||
// log
|
||||
AdminModule::makeLog($admin->id, 'admin (' . Auth::guard('admin-api')->user()->id . ') created');
|
||||
|
||||
DB::commit();
|
||||
|
||||
$query_string = General::getCachePerviousQuery('admin_query');
|
||||
$data = General::returnData($admin, $query_string);
|
||||
|
||||
return response()->json($data);
|
||||
}
|
||||
|
||||
public static function update(Request $request, $hash_id)
|
||||
{
|
||||
$id = Hasher::decode('admins', $hash_id);
|
||||
$validation = AdminModule::validation($request, $id, 'PUT');
|
||||
if (!$validation->status) {
|
||||
return response()->json($validation, 422);
|
||||
}
|
||||
|
||||
DB::beginTransaction();
|
||||
|
||||
$name = $request->input('name');
|
||||
$email = $request->input('email');
|
||||
$password = $request->input('password');
|
||||
$status = $request->input('status');
|
||||
|
||||
$admin = Admin::find($id);
|
||||
$admin->name = $name ?? $admin->name;
|
||||
$admin->email = $email ?? $admin->email;
|
||||
if (!empty($password)) {
|
||||
$admin->password = bcrypt($password);
|
||||
}
|
||||
$admin->status = $status ?? 2;
|
||||
|
||||
// img
|
||||
$img = $request->input('img');
|
||||
if (!empty($img)) {
|
||||
$remove_image = $admin->img;
|
||||
$remove_image = $remove_image ? ImageHandel::removeImage($remove_image) : '';
|
||||
$img = json_encode(ImageHandel::insertImage('admin', $img));
|
||||
$admin->img = $img;
|
||||
if (!$img) {
|
||||
DB::rollBack();
|
||||
}
|
||||
}
|
||||
|
||||
$admin->updated_by = Auth::guard('admin-api')->user()->id;
|
||||
$admin->update();
|
||||
|
||||
//role
|
||||
$role_id = $request->input('role_id');
|
||||
$role_id = Hasher::decodeArray('roles', $role_id);
|
||||
$admin->syncRoles($role_id);
|
||||
|
||||
// log
|
||||
AdminModule::makeLog($admin->id, 'admin (' . Auth::guard('admin-api')->user()->id . ') updated');
|
||||
|
||||
DB::commit();
|
||||
|
||||
$query_string = General::getCachePerviousQuery('admin_query');
|
||||
$data = General::returnData($admin, $query_string);
|
||||
|
||||
return response()->json($data);
|
||||
}
|
||||
|
||||
public static function validCheck(Request $request, $hash_id = '', $method = 'POST')
|
||||
{
|
||||
$id = $hash_id ? Hasher::decode('admins', $hash_id) : '';
|
||||
$validation = AdminModule::validation($request, $id, $method);
|
||||
if (!$validation->status) {
|
||||
return response()->json($validation, 422);
|
||||
}
|
||||
}
|
||||
|
||||
private static function validation(Request $request, $id = '', $method = 'POST')
|
||||
{
|
||||
$data = $request->all();
|
||||
$rule= [];
|
||||
|
||||
if ($method == 'POST') {
|
||||
$rule = [
|
||||
// 'img' => 'required',
|
||||
'name' => 'required',
|
||||
'email' => 'required|email|max:255|unique:admins,email',
|
||||
'password' => 'required|min:6|confirmed',
|
||||
'role_id' => ['required', new ExistCheck('role')],
|
||||
];
|
||||
}
|
||||
|
||||
if ($method == 'PUT') {
|
||||
$rule = [
|
||||
'img' => '',
|
||||
'name' => 'required',
|
||||
'email' => 'required|email|max:255|unique:admins,email,' . $id,
|
||||
'password' => 'sometimes|confirmed',
|
||||
'role_id' => ['required', new ExistCheck('role')],
|
||||
];
|
||||
}
|
||||
|
||||
if (!empty($data['img'])) {
|
||||
foreach ($data['img'] as $key => $row) {
|
||||
$rule['img'.'.'.$key] = ['required', new Image64Check()];
|
||||
}
|
||||
}
|
||||
|
||||
$validator = Validator::make($data, $rule, config('error_code'));
|
||||
|
||||
$errors = $validator->errors();
|
||||
|
||||
if (!empty($data['img'])) {
|
||||
foreach ($data['img'] as $key => $row) {
|
||||
if ($errors->first('img'.'.'.$key)) {
|
||||
$errors->add('img', config('error_code.img_error'));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($validator->fails()) {
|
||||
$data = General::returnErrorData($errors);
|
||||
return $data;
|
||||
}
|
||||
else {
|
||||
return (object)['status' => true];
|
||||
}
|
||||
}
|
||||
|
||||
public static function makeLog($id = '', $remark = '')
|
||||
{
|
||||
$entity = Admin::find($id);
|
||||
$log = new AdminLog();
|
||||
$log->admin_id = $entity->id;
|
||||
$log->history = json_encode($entity);
|
||||
$log->remark = $remark;
|
||||
$log->save();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Modules\Admin;
|
||||
|
||||
use Auth;
|
||||
use App\Models\Admin;
|
||||
use App\Http\Rules\Admin\LoginRule;
|
||||
|
||||
use App\Http\Helpers\General;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class LoginModule
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public static function login(Request $request)
|
||||
{
|
||||
$validation = LoginModule::validation($request, '', 'LOGIN');
|
||||
if (!$validation->status) {
|
||||
return response()->json($validation, 422);
|
||||
}
|
||||
|
||||
$email = $request->input('email');
|
||||
|
||||
$admin = Admin::
|
||||
where('email', $email)
|
||||
->first();
|
||||
|
||||
$token = $admin->createToken($admin->id, ['only-admin']);
|
||||
$data = General::returnTokenData($admin, $token->accessToken, true);
|
||||
return response()->json($data);
|
||||
}
|
||||
|
||||
private static function validation(Request $request, $id = '', $method = 'POST')
|
||||
{
|
||||
$data = $request->all();
|
||||
|
||||
$rule= [];
|
||||
if ($method == 'LOGIN') {
|
||||
$rule = [
|
||||
'email' => ['required', new LoginRule($data['password'] ?? '')],
|
||||
'password' => ['required']
|
||||
];
|
||||
}
|
||||
|
||||
$validator = Validator::make($data, $rule, config('error_code'));
|
||||
|
||||
$errors = $validator->errors();
|
||||
|
||||
if ($validator->fails()) {
|
||||
$data = General::returnErrorData($errors);
|
||||
return $data;
|
||||
}
|
||||
else {
|
||||
return (object)['status' => true];
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Modules\Admin;
|
||||
|
||||
use Auth;
|
||||
use App\Models\Permission;
|
||||
|
||||
use App\Http\Helpers\General;
|
||||
use App\Http\Helpers\Hasher;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
|
||||
class PermissionModule
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public static function list(Request $request)
|
||||
{
|
||||
$name = $request->get('name', null);
|
||||
$guard_name = $request->get('guard_name', null);
|
||||
$status = $request->get('status', null);
|
||||
$page = $request->get('page', null);
|
||||
$limit = $request->get('limit', Permission::all()->count());
|
||||
|
||||
$query = Permission::query();
|
||||
|
||||
if (strlen($name) > 0) {
|
||||
$query->where('name', $name);
|
||||
}
|
||||
|
||||
if (strlen($guard_name) > 0) {
|
||||
$query->where('guard_name', $guard_name);
|
||||
}
|
||||
|
||||
if (strlen($status) > 0) {
|
||||
$query->where('status', $status);
|
||||
}
|
||||
|
||||
$query->orderBy('id', 'desc');
|
||||
|
||||
$params = [
|
||||
'name' => $name,
|
||||
'status' => $status,
|
||||
'page' => $page
|
||||
];
|
||||
|
||||
$role_list = $query->paginate($limit);
|
||||
|
||||
$extract = [];
|
||||
foreach ($role_list as $key => $row) {
|
||||
$extract[] = $row;
|
||||
|
||||
}
|
||||
|
||||
$pagination = General::PaginationGenerator($role_list, $params, $extract);
|
||||
|
||||
return $pagination;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Modules\User;
|
||||
|
||||
use Auth;
|
||||
use App\Models\User;
|
||||
use App\Http\Rules\User\LoginRule;
|
||||
|
||||
use App\Http\Helpers\General;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class LoginModule
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public static function login(Request $request)
|
||||
{
|
||||
$validation = LoginModule::validation($request, '', 'LOGIN');
|
||||
if (!$validation->status) {
|
||||
return response()->json($validation, 422);
|
||||
}
|
||||
|
||||
$email = $request->input('email');
|
||||
|
||||
$user = User::
|
||||
where('email', $email)
|
||||
->first();
|
||||
|
||||
$token = $user->createToken($user->id, ['only-user']);
|
||||
$data = General::returnTokenData($user, $token->accessToken, true);
|
||||
return response()->json($data);
|
||||
}
|
||||
|
||||
private static function validation(Request $request, $id = '', $method = 'POST')
|
||||
{
|
||||
$data = $request->all();
|
||||
|
||||
$rule= [];
|
||||
if ($method == 'LOGIN') {
|
||||
$rule = [
|
||||
'email' => ['required', new LoginRule('manual', $data['password'] ?? '')],
|
||||
'password' => ['required']
|
||||
];
|
||||
}
|
||||
|
||||
$validator = Validator::make($data, $rule, config('error_code'));
|
||||
|
||||
$errors = $validator->errors();
|
||||
|
||||
if ($validator->fails()) {
|
||||
$data = General::returnErrorData($errors);
|
||||
return $data;
|
||||
}
|
||||
else {
|
||||
return (object)['status' => true];
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Modules\User;
|
||||
|
||||
use Auth;
|
||||
use App\Models\User;
|
||||
use App\Models\UserLog;
|
||||
|
||||
use App\Http\Rules\User\UnderCheck;
|
||||
use App\Http\Rules\User\ExistCheck;
|
||||
use App\Http\Rules\User\Image64Check;
|
||||
use App\Http\Rules\User\CkeckAuthUpdate;
|
||||
|
||||
use App\Http\Helpers\General;
|
||||
use App\Http\Helpers\Hasher;
|
||||
use App\Http\Helpers\ImageHandel;
|
||||
use Carbon\Carbon;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
use App\Http\Controllers\User\BaseController;
|
||||
|
||||
class UserModule extends BaseController
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
public static function self(Request $request)
|
||||
{
|
||||
$self = Auth::guard('user-api')->user();
|
||||
|
||||
$data = General::returnData($self, true);
|
||||
return response()->json($data);
|
||||
}
|
||||
|
||||
public static function makeLog($id = '', $remark = '')
|
||||
{
|
||||
$user = User::find($id);
|
||||
$user_log = new UserLog();
|
||||
$user_log->user_id = $user->id;
|
||||
$user_log->history = json_encode($user);
|
||||
$user_log->remark = $remark;
|
||||
$user_log->save();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,148 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Rules\Admin;
|
||||
|
||||
use App\Models\Country;
|
||||
use App\Models\Role;
|
||||
use App\Models\Permission;
|
||||
use App\Models\Currency;
|
||||
use App\Models\Language;
|
||||
use App\Models\MediaPropertyType;
|
||||
use App\Models\MimeType;
|
||||
|
||||
use App\Http\Helpers\Hasher;
|
||||
|
||||
use Illuminate\Contracts\Validation\Rule;
|
||||
|
||||
class ExistCheck implements Rule
|
||||
{
|
||||
/**
|
||||
* Create a new rule instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
|
||||
private $type;
|
||||
private $should_not;
|
||||
|
||||
public function __construct($type = '', $should_not = false)
|
||||
{
|
||||
$this->type = $type;
|
||||
$this->should_not = $should_not;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the validation rule passes.
|
||||
*
|
||||
* @param string $attribute
|
||||
* @param mixed $value
|
||||
* @return bool
|
||||
*/
|
||||
public function passes($attribute, $value)
|
||||
{
|
||||
$this->attribute = $attribute;
|
||||
$value = is_array($value) ? $value : [$value];
|
||||
|
||||
if ($this->type == 'country') {
|
||||
foreach ($value as $key => $row) {
|
||||
if(!empty($row)) {
|
||||
$id = Hasher::decode('countries', $row);
|
||||
$data = Country::find($id);
|
||||
if (!$data) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->type == 'role') {
|
||||
foreach ($value as $key => $row) {
|
||||
if(!empty($row)) {
|
||||
$id = Hasher::decode('roles', $row);
|
||||
$data = Role::find($id);
|
||||
if (!$data) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->type == 'permission') {
|
||||
foreach ($value as $key => $row) {
|
||||
if(!empty($row)) {
|
||||
$id = Hasher::decode('permissions', $row);
|
||||
$data = Permission::find($id);
|
||||
if (!$data) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->type == 'currency') {
|
||||
foreach ($value as $key => $row) {
|
||||
if(!empty($row)) {
|
||||
$id = Hasher::decode('currencies', $row);
|
||||
$data = Currency::find($id);
|
||||
if (!$data) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->type == 'language') {
|
||||
foreach ($value as $key => $row) {
|
||||
if(!empty($row)) {
|
||||
$id = Hasher::decode('languages', $row);
|
||||
$data = Language::find($id);
|
||||
if (!$data) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->type == 'media_property_type') {
|
||||
foreach ($value as $key => $row) {
|
||||
if(!empty($row)) {
|
||||
$id = Hasher::decode('media_property_types', $row);
|
||||
$data = MediaPropertyType::find($id);
|
||||
if (!$data) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->type == 'mime_type') {
|
||||
foreach ($value as $key => $row) {
|
||||
if(!empty($row)) {
|
||||
$id = Hasher::decode('mime_types', $row);
|
||||
$data = MimeType::find($id);
|
||||
if (!$data) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation error message.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function message()
|
||||
{
|
||||
if (!$this->should_not) {
|
||||
return config('error_code.exist_error');
|
||||
}
|
||||
else {
|
||||
return config('error_code.unique_error');
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Rules\Admin;
|
||||
|
||||
use Illuminate\Contracts\Validation\Rule;
|
||||
|
||||
class Image64Check implements Rule
|
||||
{
|
||||
/**
|
||||
* Create a new rule instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the validation rule passes.
|
||||
*
|
||||
* @param string $attribute
|
||||
* @param mixed $value
|
||||
* @return bool
|
||||
*/
|
||||
public function passes($attribute, $value)
|
||||
{
|
||||
$this->attribute = $attribute;
|
||||
|
||||
$accept_mime_type = ['image/gif', 'image/png', 'image/jpeg'];
|
||||
|
||||
$f = finfo_open();
|
||||
$mime_type = finfo_file($f, $value, FILEINFO_MIME_TYPE);
|
||||
|
||||
if (!in_array($mime_type, $accept_mime_type)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation error message.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function message()
|
||||
{
|
||||
return config('error_code.img_error');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Rules\Admin;
|
||||
|
||||
use Auth;
|
||||
use App\Models\Admin;
|
||||
|
||||
use Illuminate\Contracts\Validation\Rule;
|
||||
|
||||
class LoginRule implements Rule
|
||||
{
|
||||
/**
|
||||
* Create a new rule instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
|
||||
protected $password;
|
||||
|
||||
public function __construct($password = '')
|
||||
{
|
||||
$this->password = $password;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the validation rule passes.
|
||||
*
|
||||
* @param string $attribute
|
||||
* @param mixed $value
|
||||
* @return bool
|
||||
*/
|
||||
public function passes($attribute, $value)
|
||||
{
|
||||
$email = $value;
|
||||
$password = $this->password;
|
||||
|
||||
if (Auth::guard('admin')->attempt(['email' => $email, 'password' => $password])) {
|
||||
$data = Admin::
|
||||
where('email', $email)
|
||||
->whereIn('status', [1])
|
||||
->count();
|
||||
if (!$data) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation error message.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function message()
|
||||
{
|
||||
return config('error_code.login_error');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,121 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Rules\User;
|
||||
|
||||
use Auth;
|
||||
use App\Models\User;
|
||||
use App\Models\UserSocialAccount;
|
||||
|
||||
use Illuminate\Contracts\Validation\Rule;
|
||||
use OTPHP\TOTP;
|
||||
|
||||
class LoginRule implements Rule
|
||||
{
|
||||
/**
|
||||
* Create a new rule instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
|
||||
protected $type;
|
||||
protected $password;
|
||||
protected $totp;
|
||||
protected $pending_error;
|
||||
|
||||
public function __construct(
|
||||
$type = '',
|
||||
$password = '',
|
||||
$totp = '',
|
||||
$pending_error = false
|
||||
)
|
||||
{
|
||||
$this->type = $type;
|
||||
$this->password = $password;
|
||||
$this->totp = $totp;
|
||||
$this->pending_error = $pending_error;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Determine if the validation rule passes.
|
||||
*
|
||||
* @param string $attribute
|
||||
* @param mixed $value
|
||||
* @return bool
|
||||
*/
|
||||
public function passes($attribute, $value)
|
||||
{
|
||||
if ($this->type == 'manual') {
|
||||
$email = $value;
|
||||
$password = $this->password;
|
||||
|
||||
if (Auth::guard('user')->attempt(['email' => $email, 'password' => $password])) {
|
||||
$data = User::
|
||||
where('email', $email)
|
||||
->whereIn('status', [1, 9])
|
||||
->count();
|
||||
if (!$data) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// if ($this->type == 'social') {
|
||||
// $social_media_type_id = $value;
|
||||
// $provider_id = $this->password;
|
||||
// $data = UserSocialAccount::
|
||||
// where('social_media_type_id', $social_media_type_id)
|
||||
// ->where('provider_id', $provider_id)
|
||||
// ->whereHas('user', function($q) {
|
||||
// $q->whereIn('status', [1]);
|
||||
// })
|
||||
// ->count();
|
||||
|
||||
// if (!$data) {
|
||||
// return false;
|
||||
// }
|
||||
// return true;
|
||||
// }
|
||||
|
||||
// if ($this->type == 'totp') {
|
||||
// $social_media_type_id = $value;
|
||||
// $provider_id = $this->password;
|
||||
// $data = UserSocialAccount::
|
||||
// where('social_media_type_id', $social_media_type_id)
|
||||
// ->where('provider_id', $provider_id)
|
||||
// ->count();
|
||||
// if (!$data) {
|
||||
// return false;
|
||||
// }
|
||||
// $totp = new TOTP(
|
||||
// $social_media_type_id . $provider_id,
|
||||
// env('TOTP_SECRET'),
|
||||
// 100,
|
||||
// 'sha512',
|
||||
// 8
|
||||
// );
|
||||
|
||||
// if (!$totp->verify($this->totp)) {
|
||||
// return false;
|
||||
// }
|
||||
// return true;
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation error message.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function message()
|
||||
{
|
||||
if (!$this->pending_error) {
|
||||
return config('error_code.login_error');
|
||||
}
|
||||
else {
|
||||
return config('error_code.pending_error');
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user