add shipping rules
This commit is contained in:
@@ -2,8 +2,8 @@
|
||||
|
||||
namespace App\Repositories\Core\Auth;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use App\Models\Core\Auth\PasswordSecurity;
|
||||
use Carbon\Carbon;
|
||||
|
||||
class PasswordSecurities
|
||||
{
|
||||
@@ -16,12 +16,13 @@ class PasswordSecurities
|
||||
]);
|
||||
}
|
||||
|
||||
public static function getUserName($id) {
|
||||
public static function getUserName($id)
|
||||
{
|
||||
return self::getUser($id)->username;
|
||||
}
|
||||
|
||||
public static function getUser($id) {
|
||||
public static function getUser($id)
|
||||
{
|
||||
return PasswordSecurity::with('user')->find($id)->user;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -2,19 +2,6 @@
|
||||
|
||||
namespace App\Repositories\Core\Auth;
|
||||
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
use LangleyFoxall\LaravelNISTPasswordRules\PasswordRules;
|
||||
use LangleyFoxall\LaravelNISTPasswordRules\ContextSpecificWords;
|
||||
use LangleyFoxall\LaravelNISTPasswordRules\DerivativesOfContextSpecificWords;
|
||||
use LangleyFoxall\LaravelNISTPasswordRules\RepetitiveCharacters;
|
||||
use LangleyFoxall\LaravelNISTPasswordRules\SequentialCharacters;
|
||||
|
||||
|
||||
|
||||
use App\Repositories\Users;
|
||||
|
||||
class Passwords
|
||||
{
|
||||
public static function validator()
|
||||
@@ -27,9 +14,9 @@ class Passwords
|
||||
$validator->setMinSymbols(3);
|
||||
|
||||
if ($validator->isValid($password)) {
|
||||
printf('password %s is valid' . PHP_EOL, $password);
|
||||
printf('password %s is valid'.PHP_EOL, $password);
|
||||
} else {
|
||||
printf('password %s is invalid' . PHP_EOL, $password);
|
||||
printf('password %s is invalid'.PHP_EOL, $password);
|
||||
var_dump($validator->getErrors());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +1,9 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories\Core\Auth;
|
||||
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Laratrust\Traits\LaratrustUserTrait;
|
||||
use Yajra\DataTables\DataTables;
|
||||
|
||||
use App\Models\Core\Auth\Permission;
|
||||
use Yajra\DataTables\DataTables;
|
||||
|
||||
class Permissions
|
||||
{
|
||||
@@ -53,12 +50,14 @@ class Permissions
|
||||
public static function getTable($id)
|
||||
{
|
||||
$datas = Permission::withCount(['users']);
|
||||
|
||||
return Datatables::of($datas)->make(true);
|
||||
}
|
||||
|
||||
public static function delete($id)
|
||||
{
|
||||
Users::destroyByUniquePermission($id);
|
||||
|
||||
return Permission::destroy($id);
|
||||
}
|
||||
|
||||
@@ -70,6 +69,7 @@ class Permissions
|
||||
public static function create($data)
|
||||
{
|
||||
$permission = Permission::create($data);
|
||||
|
||||
return $permission;
|
||||
}
|
||||
|
||||
|
||||
@@ -2,21 +2,20 @@
|
||||
|
||||
namespace App\Repositories\Core\Auth;
|
||||
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use App\Models\Core\Auth\Role;
|
||||
use App\Models\Core\Auth\RoleUser;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Laratrust\Traits\LaratrustUserTrait;
|
||||
use Yajra\DataTables\DataTables;
|
||||
|
||||
use App\Models\Core\Auth\Role;
|
||||
use App\Models\Core\Auth\RoleUser;
|
||||
|
||||
class Roles
|
||||
{
|
||||
use LaratrustUserTrait;
|
||||
|
||||
public static function getListByRights()
|
||||
{
|
||||
$data = (!Auth::user()->hasRole('admin')) ? Role::whereNotIn('name', ['admin'])->get() : Role::all();
|
||||
$data = (! Auth::user()->hasRole('admin')) ? Role::whereNotIn('name', ['admin'])->get() : Role::all();
|
||||
|
||||
return $data->pluck('name', 'id')->toArray();
|
||||
}
|
||||
|
||||
@@ -32,6 +31,7 @@ class Roles
|
||||
$data['active'] = true;
|
||||
$role = Role::create($data);
|
||||
$role->attachPermissions($permissions);
|
||||
|
||||
return $role;
|
||||
}
|
||||
|
||||
@@ -43,6 +43,7 @@ class Roles
|
||||
$role = self::get($id);
|
||||
$role->update(['name' => $input['name']]);
|
||||
$role->syncPermissions($permissions);
|
||||
|
||||
return $role;
|
||||
}
|
||||
|
||||
@@ -68,6 +69,7 @@ class Roles
|
||||
{
|
||||
$role = self::get($id)->toArray();
|
||||
$role['permissions'] = self::get($id)->permissions->pluck('id')->toArray();
|
||||
|
||||
return $role;
|
||||
}
|
||||
|
||||
@@ -89,12 +91,14 @@ class Roles
|
||||
public static function getTable($id)
|
||||
{
|
||||
$datas = Role::orderBy('name', 'asc');
|
||||
|
||||
return Datatables::of($datas)->make(true);
|
||||
}
|
||||
|
||||
public static function getRolesByUser($user_id = false)
|
||||
{
|
||||
$user_id = $user_id ? $user_id : Users::getId();
|
||||
|
||||
return RoleUser::byUser($user_id);
|
||||
}
|
||||
|
||||
|
||||
@@ -2,15 +2,11 @@
|
||||
|
||||
namespace App\Repositories\Core\Auth;
|
||||
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Laratrust\Traits\LaratrustUserTrait;
|
||||
use Yajra\DataTables\DataTables;
|
||||
|
||||
use App\Models\Core\Auth\Team;
|
||||
use App\Models\Core\Auth\TeamUser;
|
||||
|
||||
use App\Repositories\Users;
|
||||
use Laratrust\Traits\LaratrustUserTrait;
|
||||
use Yajra\DataTables\DataTables;
|
||||
|
||||
class Teams
|
||||
{
|
||||
@@ -19,6 +15,7 @@ class Teams
|
||||
public static function getTeamsByUser($user_id = false)
|
||||
{
|
||||
$user_id = $user_id ? $user_id : Users::getId();
|
||||
|
||||
return TeamUser::byUser($user_id);
|
||||
}
|
||||
|
||||
@@ -75,12 +72,14 @@ class Teams
|
||||
public static function getTable($id)
|
||||
{
|
||||
$datas = Team::with(['societe'])->withCount(['users']);
|
||||
|
||||
return Datatables::of($datas)->make(true);
|
||||
}
|
||||
|
||||
public static function delete($id)
|
||||
{
|
||||
Users::destroyByUniqueTeam($id);
|
||||
|
||||
return Team::destroy($id);
|
||||
}
|
||||
|
||||
@@ -97,6 +96,7 @@ class Teams
|
||||
if (isset($data['id']) && $data['id']) {
|
||||
return self::update($data);
|
||||
}
|
||||
|
||||
return self::create($data);
|
||||
}
|
||||
|
||||
|
||||
@@ -2,9 +2,8 @@
|
||||
|
||||
namespace App\Repositories\Core\Auth;
|
||||
|
||||
use App\Models\Core\Auth\UserClient;
|
||||
use App\Models\Core\Auth\User;
|
||||
|
||||
use App\Models\Core\Auth\UserClient;
|
||||
use App\Repositories\Clients;
|
||||
|
||||
class UserClients
|
||||
@@ -12,7 +11,7 @@ class UserClients
|
||||
public static function associate($user_id, $clients_list)
|
||||
{
|
||||
$clients_existing = self::getClientsByUser($user_id)->toArray();
|
||||
$clients_list = is_array($clients_list) ? $clients_list : array();
|
||||
$clients_list = is_array($clients_list) ? $clients_list : [];
|
||||
|
||||
if (is_array($clients_existing)) {
|
||||
$clients_new = array_diff($clients_list, $clients_existing);
|
||||
@@ -22,9 +21,9 @@ class UserClients
|
||||
$clients_to_delete = $clients_existing;
|
||||
}
|
||||
|
||||
$history_element_infos = (!empty($clients_new)) ? self::associateClients($user_id, $clients_new) : false;
|
||||
$history_element_infos2 = (!empty($clients_to_delete)) ? self::dissociateClients($user_id, $clients_to_delete) : false;
|
||||
|
||||
$history_element_infos = (! empty($clients_new)) ? self::associateClients($user_id, $clients_new) : false;
|
||||
$history_element_infos2 = (! empty($clients_to_delete)) ? self::dissociateClients($user_id, $clients_to_delete) : false;
|
||||
|
||||
// $history_element = $old_translated_name['name'];
|
||||
// $history_element_id = $documentation_category_id;
|
||||
// Histories::insert(190, $history_element_id, $history_element);
|
||||
@@ -41,20 +40,22 @@ class UserClients
|
||||
|
||||
public static function associateClients($user_id, $clients)
|
||||
{
|
||||
$history = "";
|
||||
$history = '';
|
||||
foreach ($clients as $key => $client_id) {
|
||||
$client = Clients::get($client_id);
|
||||
if ($client) {
|
||||
self::associate_client($user_id, $client_id);
|
||||
$history .= $client['name'] . "| ";
|
||||
$history .= $client['name'].'| ';
|
||||
}
|
||||
}
|
||||
|
||||
return $history;
|
||||
}
|
||||
|
||||
public static function associate_client($user_id, $client_id)
|
||||
{
|
||||
self::copyUser($user_id, $client_id);
|
||||
|
||||
return UserClient::create(['user_id' => $user_id, 'client_id' => $client_id]);
|
||||
}
|
||||
|
||||
@@ -83,7 +84,7 @@ class UserClients
|
||||
$password = $user->password;
|
||||
Clients::switchClient($client_id);
|
||||
$client_user = User::on($connection->tenantName())->withTrashed()->where('username', $user->username)->first();
|
||||
if (!$client_user) {
|
||||
if (! $client_user) {
|
||||
$user = $user->toArray();
|
||||
$user['password'] = $password;
|
||||
unset($user['id']);
|
||||
@@ -106,17 +107,19 @@ class UserClients
|
||||
|
||||
public static function dissociateClients($user_id, $clients)
|
||||
{
|
||||
$history = "";
|
||||
$history = '';
|
||||
foreach ($clients as $key => $client_id) {
|
||||
self::dissociate_client($user_id, $client_id);
|
||||
$history .= $client['name'] . "| ";
|
||||
$history .= $client['name'].'| ';
|
||||
}
|
||||
|
||||
return $history;
|
||||
}
|
||||
|
||||
public static function dissociate_client($user_id, $client_id)
|
||||
{
|
||||
self::deleteUser($user_id, $client_id);
|
||||
|
||||
return UserClient::byUser($user_id)->byClient($client_id)->delete();
|
||||
}
|
||||
|
||||
|
||||
@@ -2,18 +2,15 @@
|
||||
|
||||
namespace App\Repositories\Core\Auth;
|
||||
|
||||
use App\Models\Core\Auth\RoleUser;
|
||||
use App\Models\Core\Auth\User;
|
||||
use App\Repositories\Core\Upload;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
use Laratrust\Traits\LaratrustUserTrait;
|
||||
use LangleyFoxall\LaravelNISTPasswordRules\PasswordRules;
|
||||
|
||||
use App\Models\Core\Auth\User;
|
||||
use App\Models\Core\Auth\RoleUser;
|
||||
|
||||
use App\Repositories\Core\Upload;
|
||||
use Laratrust\Traits\LaratrustUserTrait;
|
||||
|
||||
class Users
|
||||
{
|
||||
@@ -27,7 +24,7 @@ class Users
|
||||
public static function getInfo($id = false)
|
||||
{
|
||||
$id = $id ? $id : self::getId();
|
||||
if (!$id) {
|
||||
if (! $id) {
|
||||
return false;
|
||||
}
|
||||
$user = self::get($id);
|
||||
@@ -36,6 +33,7 @@ class Users
|
||||
$data['avatar'] = self::getAvatar($id);
|
||||
$data['roles'] = $user->roles->pluck('id')->toArray();
|
||||
$data['permissions'] = $user->allPermissions()->pluck('id')->toArray();
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
@@ -46,6 +44,7 @@ class Users
|
||||
}
|
||||
$user = ($data['id'] ?? false) ? self::update($data) : self::create($data);
|
||||
$user->roles()->sync(array_keys($data['roles'] ?? []));
|
||||
|
||||
return $user;
|
||||
}
|
||||
|
||||
@@ -56,6 +55,7 @@ class Users
|
||||
$data['active'] = true;
|
||||
$user = User::create($data);
|
||||
PasswordSecurities::create($user->id);
|
||||
|
||||
return $user;
|
||||
}
|
||||
|
||||
@@ -64,25 +64,29 @@ class Users
|
||||
$id = $id ? $id : $data['id'];
|
||||
$user = self::get($id);
|
||||
$ret = $user->update($data);
|
||||
|
||||
return $user;
|
||||
}
|
||||
|
||||
public static function get($id = false)
|
||||
{
|
||||
$id = $id ? $id : self::getId();
|
||||
|
||||
return User::findOrFail($id);
|
||||
}
|
||||
|
||||
public static function getId()
|
||||
{
|
||||
$user = self::getUser();
|
||||
|
||||
return $user ? $user->id : false;
|
||||
}
|
||||
|
||||
public static function getName($id = false)
|
||||
{
|
||||
$user = $id ? self::get($id) : self::getUser();
|
||||
return $user->first_name . ' ' . $user->last_name;
|
||||
|
||||
return $user->first_name.' '.$user->last_name;
|
||||
}
|
||||
|
||||
public static function getUsername($id = false)
|
||||
@@ -108,6 +112,7 @@ class Users
|
||||
public static function delete($id)
|
||||
{
|
||||
$ret = RoleUser::byUser($id)->delete();
|
||||
|
||||
return User::destroy($id);
|
||||
}
|
||||
|
||||
@@ -119,6 +124,7 @@ class Users
|
||||
public static function hasRole($role, $user = false)
|
||||
{
|
||||
$user = $user ? $user : self::getUser();
|
||||
|
||||
return $user ? $user->hasRole($role) : false;
|
||||
}
|
||||
|
||||
@@ -129,14 +135,15 @@ class Users
|
||||
}
|
||||
$user = $user ? $user : self::getUser();
|
||||
$permissions = self::getPermissions($user);
|
||||
|
||||
return $user ? self::checkPermission($permissions, $permission) : false;
|
||||
// TODO why is posing problem ???
|
||||
// return $user ? $user->hasPermission($permission) : false;
|
||||
// return $user ? $user->hasPermission($permission) : false;
|
||||
}
|
||||
|
||||
public static function checkPermission($permissions, $permission)
|
||||
{
|
||||
if (!strpos($permission, '*')) {
|
||||
if (! strpos($permission, '*')) {
|
||||
return in_array($permission, $permissions);
|
||||
}
|
||||
$permission = str_replace('*', '', $permission);
|
||||
@@ -145,12 +152,14 @@ class Users
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static function getRoles($user = false)
|
||||
{
|
||||
$user = $user ? $user : self::getUser();
|
||||
|
||||
return $user ? $user->roles->pluck('name')->toArray() : false;
|
||||
}
|
||||
|
||||
@@ -158,10 +167,11 @@ class Users
|
||||
{
|
||||
return Roles::getListByRights();
|
||||
}
|
||||
|
||||
|
||||
public static function getPermissions($user = false)
|
||||
{
|
||||
$user = $user ? $user : self::getUser();
|
||||
|
||||
return $user ? $user->allPermissions()->pluck('name')->toArray() : false;
|
||||
}
|
||||
|
||||
@@ -183,11 +193,12 @@ class Users
|
||||
public static function getAvatar($user_id)
|
||||
{
|
||||
$avatar = self::get($user_id)->avatar;
|
||||
if (!$avatar) {
|
||||
if (! $avatar) {
|
||||
return '/assets/img/no-avatar.png';
|
||||
}
|
||||
$path = '/images/avatars/';
|
||||
return $path . $avatar;
|
||||
|
||||
return $path.$avatar;
|
||||
}
|
||||
|
||||
public static function selectOptions()
|
||||
@@ -233,6 +244,7 @@ class Users
|
||||
$file_uploaded = Upload::store($file, $targetDir);
|
||||
$tab = pathinfo($file_uploaded);
|
||||
$response['name'] = $tab['basename'];
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
@@ -244,6 +256,7 @@ class Users
|
||||
public static function update_password($id, $password)
|
||||
{
|
||||
$password = Hash::make($password);
|
||||
|
||||
return User::find($id)->update(['password' => $password]);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user