v2 first commit
This commit is contained in:
36
app/Jobs/Auth/CreatePermission.php
Normal file
36
app/Jobs/Auth/CreatePermission.php
Normal file
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace App\Jobs\Auth;
|
||||
|
||||
use App\Abstracts\Job;
|
||||
use App\Models\Auth\Permission;
|
||||
use Artisan;
|
||||
|
||||
class CreatePermission extends Job
|
||||
{
|
||||
protected $request;
|
||||
|
||||
/**
|
||||
* Create a new job instance.
|
||||
*
|
||||
* @param $request
|
||||
*/
|
||||
public function __construct($request)
|
||||
{
|
||||
$this->request = $this->getRequestInstance($request);
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the job.
|
||||
*
|
||||
* @return Permission
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$permission = Permission::create($this->request->all());
|
||||
|
||||
Artisan::call('cache:clear');
|
||||
|
||||
return $permission;
|
||||
}
|
||||
}
|
||||
40
app/Jobs/Auth/CreateRole.php
Normal file
40
app/Jobs/Auth/CreateRole.php
Normal file
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace App\Jobs\Auth;
|
||||
|
||||
use App\Abstracts\Job;
|
||||
use App\Models\Auth\Role;
|
||||
use Artisan;
|
||||
|
||||
class CreateRole extends Job
|
||||
{
|
||||
protected $request;
|
||||
|
||||
/**
|
||||
* Create a new job instance.
|
||||
*
|
||||
* @param $request
|
||||
*/
|
||||
public function __construct($request)
|
||||
{
|
||||
$this->request = $this->getRequestInstance($request);
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the job.
|
||||
*
|
||||
* @return Permission
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$role = Role::create($this->request->input());
|
||||
|
||||
if ($this->request->has('permissions')) {
|
||||
$role->permissions()->attach($this->request->get('permissions'));
|
||||
}
|
||||
|
||||
Artisan::call('cache:clear');
|
||||
|
||||
return $role;
|
||||
}
|
||||
}
|
||||
63
app/Jobs/Auth/CreateUser.php
Normal file
63
app/Jobs/Auth/CreateUser.php
Normal file
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
|
||||
namespace App\Jobs\Auth;
|
||||
|
||||
use App\Abstracts\Job;
|
||||
use App\Models\Auth\User;
|
||||
use Artisan;
|
||||
|
||||
class CreateUser extends Job
|
||||
{
|
||||
protected $request;
|
||||
|
||||
/**
|
||||
* Create a new job instance.
|
||||
*
|
||||
* @param $request
|
||||
*/
|
||||
public function __construct($request)
|
||||
{
|
||||
$this->request = $this->getRequestInstance($request);
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the job.
|
||||
*
|
||||
* @return Permission
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$user = User::create($this->request->input());
|
||||
|
||||
if ($this->request->has('permissions')) {
|
||||
$user->permissions()->attach($this->request->get('permissions'));
|
||||
}
|
||||
|
||||
// Upload picture
|
||||
if ($this->request->file('picture')) {
|
||||
$media = $this->getMedia($this->request->file('picture'), 'users');
|
||||
|
||||
$user->attachMedia($media, 'picture');
|
||||
}
|
||||
|
||||
// Attach roles
|
||||
$user->roles()->attach($this->request->get('roles'));
|
||||
|
||||
// Attach companies
|
||||
$user->companies()->attach($this->request->get('companies'));
|
||||
|
||||
Artisan::call('cache:clear');
|
||||
|
||||
// Add User Dashboard
|
||||
foreach ($user->companies as $company) {
|
||||
Artisan::call('user:seed', [
|
||||
'user' => $user->id,
|
||||
'company' => $company->id,
|
||||
]);
|
||||
}
|
||||
|
||||
Artisan::call('cache:clear');
|
||||
|
||||
return $user;
|
||||
}
|
||||
}
|
||||
35
app/Jobs/Auth/DeletePermission.php
Normal file
35
app/Jobs/Auth/DeletePermission.php
Normal file
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace App\Jobs\Auth;
|
||||
|
||||
use App\Abstracts\Job;
|
||||
use Artisan;
|
||||
|
||||
class DeletePermission extends Job
|
||||
{
|
||||
protected $permission;
|
||||
|
||||
/**
|
||||
* Create a new job instance.
|
||||
*
|
||||
* @param $permission
|
||||
*/
|
||||
public function __construct($permission)
|
||||
{
|
||||
$this->permission = $permission;
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the job.
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$this->permission->delete();
|
||||
|
||||
Artisan::call('cache:clear');
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
35
app/Jobs/Auth/DeleteRole.php
Normal file
35
app/Jobs/Auth/DeleteRole.php
Normal file
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace App\Jobs\Auth;
|
||||
|
||||
use App\Abstracts\Job;
|
||||
use Artisan;
|
||||
|
||||
class DeleteRole extends Job
|
||||
{
|
||||
protected $role;
|
||||
|
||||
/**
|
||||
* Create a new job instance.
|
||||
*
|
||||
* @param $role
|
||||
*/
|
||||
public function __construct($role)
|
||||
{
|
||||
$this->role = $role;
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the job.
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$this->role->delete();
|
||||
|
||||
Artisan::call('cache:clear');
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
52
app/Jobs/Auth/DeleteUser.php
Normal file
52
app/Jobs/Auth/DeleteUser.php
Normal file
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
namespace App\Jobs\Auth;
|
||||
|
||||
use App\Abstracts\Job;
|
||||
use Artisan;
|
||||
|
||||
class DeleteUser extends Job
|
||||
{
|
||||
protected $user;
|
||||
|
||||
/**
|
||||
* Create a new job instance.
|
||||
*
|
||||
* @param $user
|
||||
*/
|
||||
public function __construct($user)
|
||||
{
|
||||
$this->user = $user;
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the job.
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$this->authorize();
|
||||
|
||||
$this->user->delete();
|
||||
|
||||
Artisan::call('cache:clear');
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if this action is applicable.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function authorize()
|
||||
{
|
||||
// Can't delete yourself
|
||||
if ($this->user->id == user()->id) {
|
||||
$message = trans('auth.error.self_delete');
|
||||
|
||||
throw new \Exception($message);
|
||||
}
|
||||
}
|
||||
}
|
||||
40
app/Jobs/Auth/UpdatePermission.php
Normal file
40
app/Jobs/Auth/UpdatePermission.php
Normal file
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace App\Jobs\Auth;
|
||||
|
||||
use App\Abstracts\Job;
|
||||
use App\Models\Auth\Permission;
|
||||
use Artisan;
|
||||
|
||||
class UpdatePermission extends Job
|
||||
{
|
||||
protected $permission;
|
||||
|
||||
protected $request;
|
||||
|
||||
/**
|
||||
* Create a new job instance.
|
||||
*
|
||||
* @param $permission
|
||||
* @param $request
|
||||
*/
|
||||
public function __construct($permission, $request)
|
||||
{
|
||||
$this->permission = $permission;
|
||||
$this->request = $this->getRequestInstance($request);
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the job.
|
||||
*
|
||||
* @return Permission
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$this->permission->update($this->request->all());
|
||||
|
||||
Artisan::call('cache:clear');
|
||||
|
||||
return $this->permission;
|
||||
}
|
||||
}
|
||||
44
app/Jobs/Auth/UpdateRole.php
Normal file
44
app/Jobs/Auth/UpdateRole.php
Normal file
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace App\Jobs\Auth;
|
||||
|
||||
use App\Abstracts\Job;
|
||||
use App\Models\Auth\Role;
|
||||
use Artisan;
|
||||
|
||||
class UpdateRole extends Job
|
||||
{
|
||||
protected $role;
|
||||
|
||||
protected $request;
|
||||
|
||||
/**
|
||||
* Create a new job instance.
|
||||
*
|
||||
* @param $role
|
||||
* @param $request
|
||||
*/
|
||||
public function __construct($role, $request)
|
||||
{
|
||||
$this->role = $role;
|
||||
$this->request = $this->getRequestInstance($request);
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the job.
|
||||
*
|
||||
* @return Role
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$this->role->update($this->request->all());
|
||||
|
||||
if ($this->request->has('permissions')) {
|
||||
$this->role->permissions()->sync($this->request->get('permissions'));
|
||||
}
|
||||
|
||||
Artisan::call('cache:clear');
|
||||
|
||||
return $this->role;
|
||||
}
|
||||
}
|
||||
80
app/Jobs/Auth/UpdateUser.php
Normal file
80
app/Jobs/Auth/UpdateUser.php
Normal file
@@ -0,0 +1,80 @@
|
||||
<?php
|
||||
|
||||
namespace App\Jobs\Auth;
|
||||
|
||||
use App\Abstracts\Job;
|
||||
use App\Models\Auth\User;
|
||||
use Artisan;
|
||||
|
||||
class UpdateUser extends Job
|
||||
{
|
||||
protected $user;
|
||||
|
||||
protected $request;
|
||||
|
||||
/**
|
||||
* Create a new job instance.
|
||||
*
|
||||
* @param $user
|
||||
* @param $request
|
||||
*/
|
||||
public function __construct($user, $request)
|
||||
{
|
||||
$this->user = $user;
|
||||
$this->request = $this->getRequestInstance($request);
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the job.
|
||||
*
|
||||
* @return User
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$this->authorize();
|
||||
|
||||
// Do not reset password if not entered/changed
|
||||
if (empty($this->request['password'])) {
|
||||
unset($this->request['password']);
|
||||
unset($this->request['password_confirmation']);
|
||||
}
|
||||
|
||||
$this->user->update($this->request->input());
|
||||
|
||||
// Upload picture
|
||||
if ($this->request->file('picture')) {
|
||||
$media = $this->getMedia($this->request->file('picture'), 'users');
|
||||
|
||||
$this->user->attachMedia($media, 'picture');
|
||||
}
|
||||
|
||||
// Sync roles
|
||||
if ($this->request->has('roles')) {
|
||||
$this->user->roles()->sync($this->request->get('roles'));
|
||||
}
|
||||
|
||||
// Sync companies
|
||||
if ($this->request->has('companies')) {
|
||||
$this->user->companies()->sync($this->request->get('companies'));
|
||||
}
|
||||
|
||||
Artisan::call('cache:clear');
|
||||
|
||||
return $this->user;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if this action is applicable.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function authorize()
|
||||
{
|
||||
// Can't disable yourself
|
||||
if (($this->request->get('enabled', 1) == 0) && ($this->user->id == user()->id)) {
|
||||
$message = trans('auth.error.self_disable');
|
||||
|
||||
throw new \Exception($message);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user