@@ -40,7 +40,7 @@ discard block |
||
| 40 | 40 | * |
| 41 | 41 | * @param array $relations |
| 42 | 42 | * @param string $sortBy |
| 43 | - * @param boolean $desc |
|
| 43 | + * @param integer $desc |
|
| 44 | 44 | * @param array $columns |
| 45 | 45 | * @return collection |
| 46 | 46 | */ |
@@ -60,7 +60,7 @@ discard block |
||
| 60 | 60 | * @param integer $perPage |
| 61 | 61 | * @param array $relations |
| 62 | 62 | * @param string $sortBy |
| 63 | - * @param boolean $desc |
|
| 63 | + * @param integer $desc |
|
| 64 | 64 | * @param array $columns |
| 65 | 65 | * @return collection |
| 66 | 66 | */ |
@@ -79,7 +79,7 @@ discard block |
||
| 79 | 79 | * @param integer $perPage |
| 80 | 80 | * @param array $relations |
| 81 | 81 | * @param string $sortBy |
| 82 | - * @param boolean $desc |
|
| 82 | + * @param integer $desc |
|
| 83 | 83 | * @param array $columns |
| 84 | 84 | * @return collection |
| 85 | 85 | */ |
@@ -100,7 +100,7 @@ discard block |
||
| 100 | 100 | * @param integer $perPage |
| 101 | 101 | * @param array $relations |
| 102 | 102 | * @param string $sortBy |
| 103 | - * @param boolean $desc |
|
| 103 | + * @param integer $desc |
|
| 104 | 104 | * @param array $columns |
| 105 | 105 | * @return collection |
| 106 | 106 | */ |
@@ -179,7 +179,7 @@ discard block |
||
| 179 | 179 | * @param array $conditions array of conditions |
| 180 | 180 | * @param array $relations |
| 181 | 181 | * @param string $sortBy |
| 182 | - * @param boolean $desc |
|
| 182 | + * @param integer $desc |
|
| 183 | 183 | * @param array $columns |
| 184 | 184 | * @return collection |
| 185 | 185 | */ |
@@ -214,7 +214,7 @@ discard block |
||
| 214 | 214 | * @param array $conditions array of conditions |
| 215 | 215 | * @param integer $perPage |
| 216 | 216 | * @param string $sortBy |
| 217 | - * @param boolean $desc |
|
| 217 | + * @param integer $desc |
|
| 218 | 218 | * @param array $columns |
| 219 | 219 | * @return collection |
| 220 | 220 | */ |
@@ -7,191 +7,191 @@ |
||
| 7 | 7 | |
| 8 | 8 | abstract class BaseService implements BaseServiceInterface |
| 9 | 9 | { |
| 10 | - /** |
|
| 11 | - * @var object |
|
| 12 | - */ |
|
| 13 | - protected $repo; |
|
| 10 | + /** |
|
| 11 | + * @var object |
|
| 12 | + */ |
|
| 13 | + protected $repo; |
|
| 14 | 14 | |
| 15 | - /** |
|
| 16 | - * Init new object. |
|
| 17 | - * |
|
| 18 | - * @param mixed $repo |
|
| 19 | - * @return void |
|
| 20 | - */ |
|
| 21 | - public function __construct($repo) |
|
| 22 | - { |
|
| 23 | - $this->repo = new CachingDecorator($repo, \App::make('Illuminate\Contracts\Cache\Repository')); |
|
| 24 | - } |
|
| 15 | + /** |
|
| 16 | + * Init new object. |
|
| 17 | + * |
|
| 18 | + * @param mixed $repo |
|
| 19 | + * @return void |
|
| 20 | + */ |
|
| 21 | + public function __construct($repo) |
|
| 22 | + { |
|
| 23 | + $this->repo = new CachingDecorator($repo, \App::make('Illuminate\Contracts\Cache\Repository')); |
|
| 24 | + } |
|
| 25 | 25 | |
| 26 | - /** |
|
| 27 | - * Fetch records with relations based on the given params. |
|
| 28 | - * |
|
| 29 | - * @param string $relations |
|
| 30 | - * @param array $conditions |
|
| 31 | - * @param integer $perPage |
|
| 32 | - * @param string $sortBy |
|
| 33 | - * @param boolean $desc |
|
| 34 | - * @return collection |
|
| 35 | - */ |
|
| 36 | - public function list($relations = [], $conditions = false, $perPage = 15, $sortBy = 'created_at', $desc = true) |
|
| 37 | - { |
|
| 38 | - return $this->repo->list($relations, $conditions, $perPage, $sortBy, $desc); |
|
| 39 | - } |
|
| 26 | + /** |
|
| 27 | + * Fetch records with relations based on the given params. |
|
| 28 | + * |
|
| 29 | + * @param string $relations |
|
| 30 | + * @param array $conditions |
|
| 31 | + * @param integer $perPage |
|
| 32 | + * @param string $sortBy |
|
| 33 | + * @param boolean $desc |
|
| 34 | + * @return collection |
|
| 35 | + */ |
|
| 36 | + public function list($relations = [], $conditions = false, $perPage = 15, $sortBy = 'created_at', $desc = true) |
|
| 37 | + { |
|
| 38 | + return $this->repo->list($relations, $conditions, $perPage, $sortBy, $desc); |
|
| 39 | + } |
|
| 40 | 40 | |
| 41 | - /** |
|
| 42 | - * Fetch all records with relations from the storage. |
|
| 43 | - * |
|
| 44 | - * @param array $relations |
|
| 45 | - * @param string $sortBy |
|
| 46 | - * @param boolean $desc |
|
| 47 | - * @param array $columns |
|
| 48 | - * @return collection |
|
| 49 | - */ |
|
| 50 | - public function all($relations = [], $sortBy = 'created_at', $desc = 1, $columns = ['*']) |
|
| 51 | - { |
|
| 52 | - return $this->repo->all($relations, $sortBy, $desc, $columns); |
|
| 53 | - } |
|
| 41 | + /** |
|
| 42 | + * Fetch all records with relations from the storage. |
|
| 43 | + * |
|
| 44 | + * @param array $relations |
|
| 45 | + * @param string $sortBy |
|
| 46 | + * @param boolean $desc |
|
| 47 | + * @param array $columns |
|
| 48 | + * @return collection |
|
| 49 | + */ |
|
| 50 | + public function all($relations = [], $sortBy = 'created_at', $desc = 1, $columns = ['*']) |
|
| 51 | + { |
|
| 52 | + return $this->repo->all($relations, $sortBy, $desc, $columns); |
|
| 53 | + } |
|
| 54 | 54 | |
| 55 | - /** |
|
| 56 | - * Fetch all records with relations from storage in pages |
|
| 57 | - * that matche the given query. |
|
| 58 | - * |
|
| 59 | - * @param string $query |
|
| 60 | - * @param integer $perPage |
|
| 61 | - * @param array $relations |
|
| 62 | - * @param string $sortBy |
|
| 63 | - * @param boolean $desc |
|
| 64 | - * @param array $columns |
|
| 65 | - * @return collection |
|
| 66 | - */ |
|
| 67 | - public function search($query, $perPage = 15, $relations = [], $sortBy = 'created_at', $desc = 1, $columns = ['*']) |
|
| 68 | - { |
|
| 69 | - return $this->repo->search($query, $perPage, $relations, $sortBy, $desc, $columns); |
|
| 70 | - } |
|
| 55 | + /** |
|
| 56 | + * Fetch all records with relations from storage in pages |
|
| 57 | + * that matche the given query. |
|
| 58 | + * |
|
| 59 | + * @param string $query |
|
| 60 | + * @param integer $perPage |
|
| 61 | + * @param array $relations |
|
| 62 | + * @param string $sortBy |
|
| 63 | + * @param boolean $desc |
|
| 64 | + * @param array $columns |
|
| 65 | + * @return collection |
|
| 66 | + */ |
|
| 67 | + public function search($query, $perPage = 15, $relations = [], $sortBy = 'created_at', $desc = 1, $columns = ['*']) |
|
| 68 | + { |
|
| 69 | + return $this->repo->search($query, $perPage, $relations, $sortBy, $desc, $columns); |
|
| 70 | + } |
|
| 71 | 71 | |
| 72 | - /** |
|
| 73 | - * Fetch all records with relations from storage in pages. |
|
| 74 | - * |
|
| 75 | - * @param integer $perPage |
|
| 76 | - * @param array $relations |
|
| 77 | - * @param string $sortBy |
|
| 78 | - * @param boolean $desc |
|
| 79 | - * @param array $columns |
|
| 80 | - * @return collection |
|
| 81 | - */ |
|
| 82 | - public function paginate($perPage = 15, $relations = [], $sortBy = 'created_at', $desc = 1, $columns = ['*']) |
|
| 83 | - { |
|
| 84 | - return $this->repo->paginate($perPage, $relations, $sortBy, $desc, $columns); |
|
| 85 | - } |
|
| 72 | + /** |
|
| 73 | + * Fetch all records with relations from storage in pages. |
|
| 74 | + * |
|
| 75 | + * @param integer $perPage |
|
| 76 | + * @param array $relations |
|
| 77 | + * @param string $sortBy |
|
| 78 | + * @param boolean $desc |
|
| 79 | + * @param array $columns |
|
| 80 | + * @return collection |
|
| 81 | + */ |
|
| 82 | + public function paginate($perPage = 15, $relations = [], $sortBy = 'created_at', $desc = 1, $columns = ['*']) |
|
| 83 | + { |
|
| 84 | + return $this->repo->paginate($perPage, $relations, $sortBy, $desc, $columns); |
|
| 85 | + } |
|
| 86 | 86 | |
| 87 | - /** |
|
| 88 | - * Fetch all records with relations based on |
|
| 89 | - * the given condition from storage in pages. |
|
| 90 | - * |
|
| 91 | - * @param array $conditions array of conditions |
|
| 92 | - * @param integer $perPage |
|
| 93 | - * @param array $relations |
|
| 94 | - * @param string $sortBy |
|
| 95 | - * @param boolean $desc |
|
| 96 | - * @param array $columns |
|
| 97 | - * @return collection |
|
| 98 | - */ |
|
| 99 | - public function paginateBy($conditions, $perPage = 15, $relations = [], $sortBy = 'created_at', $desc = 1, $columns = ['*']) |
|
| 100 | - { |
|
| 101 | - return $this->repo->paginateBy($conditions, $perPage, $relations, $sortBy, $desc, $columns); |
|
| 102 | - } |
|
| 87 | + /** |
|
| 88 | + * Fetch all records with relations based on |
|
| 89 | + * the given condition from storage in pages. |
|
| 90 | + * |
|
| 91 | + * @param array $conditions array of conditions |
|
| 92 | + * @param integer $perPage |
|
| 93 | + * @param array $relations |
|
| 94 | + * @param string $sortBy |
|
| 95 | + * @param boolean $desc |
|
| 96 | + * @param array $columns |
|
| 97 | + * @return collection |
|
| 98 | + */ |
|
| 99 | + public function paginateBy($conditions, $perPage = 15, $relations = [], $sortBy = 'created_at', $desc = 1, $columns = ['*']) |
|
| 100 | + { |
|
| 101 | + return $this->repo->paginateBy($conditions, $perPage, $relations, $sortBy, $desc, $columns); |
|
| 102 | + } |
|
| 103 | 103 | |
| 104 | - /** |
|
| 105 | - * Save the given model to the storage. |
|
| 106 | - * |
|
| 107 | - * @param array $data |
|
| 108 | - * @return mixed |
|
| 109 | - */ |
|
| 110 | - public function save(array $data) |
|
| 111 | - { |
|
| 112 | - return $this->repo->save($data); |
|
| 113 | - } |
|
| 104 | + /** |
|
| 105 | + * Save the given model to the storage. |
|
| 106 | + * |
|
| 107 | + * @param array $data |
|
| 108 | + * @return mixed |
|
| 109 | + */ |
|
| 110 | + public function save(array $data) |
|
| 111 | + { |
|
| 112 | + return $this->repo->save($data); |
|
| 113 | + } |
|
| 114 | 114 | |
| 115 | - /** |
|
| 116 | - * Delete record from the storage based on the given |
|
| 117 | - * condition. |
|
| 118 | - * |
|
| 119 | - * @param var $value condition value |
|
| 120 | - * @param string $attribute condition column name |
|
| 121 | - * @return void |
|
| 122 | - */ |
|
| 123 | - public function delete($value, $attribute = 'id') |
|
| 124 | - { |
|
| 125 | - return $this->repo->save($value, $attribute); |
|
| 126 | - } |
|
| 115 | + /** |
|
| 116 | + * Delete record from the storage based on the given |
|
| 117 | + * condition. |
|
| 118 | + * |
|
| 119 | + * @param var $value condition value |
|
| 120 | + * @param string $attribute condition column name |
|
| 121 | + * @return void |
|
| 122 | + */ |
|
| 123 | + public function delete($value, $attribute = 'id') |
|
| 124 | + { |
|
| 125 | + return $this->repo->save($value, $attribute); |
|
| 126 | + } |
|
| 127 | 127 | |
| 128 | - /** |
|
| 129 | - * Fetch records from the storage based on the given |
|
| 130 | - * id. |
|
| 131 | - * |
|
| 132 | - * @param integer $id |
|
| 133 | - * @param string[] $relations |
|
| 134 | - * @param array $columns |
|
| 135 | - * @return object |
|
| 136 | - */ |
|
| 137 | - public function find($id, $relations = [], $columns = ['*']) |
|
| 138 | - { |
|
| 139 | - return $this->repo->find($id, $relations, $columns); |
|
| 140 | - } |
|
| 128 | + /** |
|
| 129 | + * Fetch records from the storage based on the given |
|
| 130 | + * id. |
|
| 131 | + * |
|
| 132 | + * @param integer $id |
|
| 133 | + * @param string[] $relations |
|
| 134 | + * @param array $columns |
|
| 135 | + * @return object |
|
| 136 | + */ |
|
| 137 | + public function find($id, $relations = [], $columns = ['*']) |
|
| 138 | + { |
|
| 139 | + return $this->repo->find($id, $relations, $columns); |
|
| 140 | + } |
|
| 141 | 141 | |
| 142 | - /** |
|
| 143 | - * Fetch records from the storage based on the given |
|
| 144 | - * condition. |
|
| 145 | - * |
|
| 146 | - * @param array $conditions array of conditions |
|
| 147 | - * @param array $relations |
|
| 148 | - * @param string $sortBy |
|
| 149 | - * @param boolean $desc |
|
| 150 | - * @param array $columns |
|
| 151 | - * @return collection |
|
| 152 | - */ |
|
| 153 | - public function findBy($conditions, $relations = [], $sortBy = 'created_at', $desc = 1, $columns = ['*']) |
|
| 154 | - { |
|
| 155 | - return $this->repo->findBy($conditions, $relations, $sortBy, $desc, $columns); |
|
| 156 | - } |
|
| 142 | + /** |
|
| 143 | + * Fetch records from the storage based on the given |
|
| 144 | + * condition. |
|
| 145 | + * |
|
| 146 | + * @param array $conditions array of conditions |
|
| 147 | + * @param array $relations |
|
| 148 | + * @param string $sortBy |
|
| 149 | + * @param boolean $desc |
|
| 150 | + * @param array $columns |
|
| 151 | + * @return collection |
|
| 152 | + */ |
|
| 153 | + public function findBy($conditions, $relations = [], $sortBy = 'created_at', $desc = 1, $columns = ['*']) |
|
| 154 | + { |
|
| 155 | + return $this->repo->findBy($conditions, $relations, $sortBy, $desc, $columns); |
|
| 156 | + } |
|
| 157 | 157 | |
| 158 | - /** |
|
| 159 | - * Fetch the first record from the storage based on the given |
|
| 160 | - * condition. |
|
| 161 | - * |
|
| 162 | - * @param array $conditions array of conditions |
|
| 163 | - * @param array $relations |
|
| 164 | - * @param array $columns |
|
| 165 | - * @return object |
|
| 166 | - */ |
|
| 167 | - public function first($conditions, $relations = [], $columns = ['*']) |
|
| 168 | - { |
|
| 169 | - return $this->repo->first($conditions, $relations, $columns); |
|
| 170 | - } |
|
| 158 | + /** |
|
| 159 | + * Fetch the first record from the storage based on the given |
|
| 160 | + * condition. |
|
| 161 | + * |
|
| 162 | + * @param array $conditions array of conditions |
|
| 163 | + * @param array $relations |
|
| 164 | + * @param array $columns |
|
| 165 | + * @return object |
|
| 166 | + */ |
|
| 167 | + public function first($conditions, $relations = [], $columns = ['*']) |
|
| 168 | + { |
|
| 169 | + return $this->repo->first($conditions, $relations, $columns); |
|
| 170 | + } |
|
| 171 | 171 | |
| 172 | - /** |
|
| 173 | - * Return the deleted models in pages based on the given conditions. |
|
| 174 | - * |
|
| 175 | - * @param array $conditions array of conditions |
|
| 176 | - * @param integer $perPage |
|
| 177 | - * @param string $sortBy |
|
| 178 | - * @param boolean $desc |
|
| 179 | - * @param array $columns |
|
| 180 | - * @return collection |
|
| 181 | - */ |
|
| 182 | - public function deleted($conditions, $perPage = 15, $sortBy = 'created_at', $desc = 1, $columns = ['*']) |
|
| 183 | - { |
|
| 184 | - return $this->repo->deleted($conditions, $perPage, $sortBy, $desc, $columns); |
|
| 185 | - } |
|
| 172 | + /** |
|
| 173 | + * Return the deleted models in pages based on the given conditions. |
|
| 174 | + * |
|
| 175 | + * @param array $conditions array of conditions |
|
| 176 | + * @param integer $perPage |
|
| 177 | + * @param string $sortBy |
|
| 178 | + * @param boolean $desc |
|
| 179 | + * @param array $columns |
|
| 180 | + * @return collection |
|
| 181 | + */ |
|
| 182 | + public function deleted($conditions, $perPage = 15, $sortBy = 'created_at', $desc = 1, $columns = ['*']) |
|
| 183 | + { |
|
| 184 | + return $this->repo->deleted($conditions, $perPage, $sortBy, $desc, $columns); |
|
| 185 | + } |
|
| 186 | 186 | |
| 187 | - /** |
|
| 188 | - * Restore the deleted model. |
|
| 189 | - * |
|
| 190 | - * @param integer $id |
|
| 191 | - * @return void |
|
| 192 | - */ |
|
| 193 | - public function restore($id) |
|
| 194 | - { |
|
| 195 | - return $this->repo->restore($id); |
|
| 196 | - } |
|
| 187 | + /** |
|
| 188 | + * Restore the deleted model. |
|
| 189 | + * |
|
| 190 | + * @param integer $id |
|
| 191 | + * @return void |
|
| 192 | + */ |
|
| 193 | + public function restore($id) |
|
| 194 | + { |
|
| 195 | + return $this->repo->restore($id); |
|
| 196 | + } |
|
| 197 | 197 | } |
@@ -1,9 +1,6 @@ |
||
| 1 | 1 | <?php namespace App\Modules\PushNotificationDevices\Repositories; |
| 2 | 2 | |
| 3 | 3 | use App\Modules\Core\BaseClasses\BaseRepository; |
| 4 | -use LaravelFCM\Message\OptionsBuilder; |
|
| 5 | -use LaravelFCM\Message\PayloadDataBuilder; |
|
| 6 | -use LaravelFCM\Message\PayloadNotificationBuilder; |
|
| 7 | 4 | use App\Modules\PushNotificationDevices\PushNotificationDevice; |
| 8 | 5 | |
| 9 | 6 | class PushNotificationDeviceRepository extends BaseRepository |
@@ -8,14 +8,14 @@ |
||
| 8 | 8 | |
| 9 | 9 | class PushNotificationDeviceRepository extends BaseRepository |
| 10 | 10 | { |
| 11 | - /** |
|
| 12 | - * Init new object. |
|
| 13 | - * |
|
| 14 | - * @param PushNotificationDevice $model |
|
| 15 | - * @return void |
|
| 16 | - */ |
|
| 17 | - public function __construct(PushNotificationDevice $model) |
|
| 18 | - { |
|
| 19 | - parent::__construct($model); |
|
| 20 | - } |
|
| 11 | + /** |
|
| 12 | + * Init new object. |
|
| 13 | + * |
|
| 14 | + * @param PushNotificationDevice $model |
|
| 15 | + * @return void |
|
| 16 | + */ |
|
| 17 | + public function __construct(PushNotificationDevice $model) |
|
| 18 | + { |
|
| 19 | + parent::__construct($model); |
|
| 20 | + } |
|
| 21 | 21 | } |
@@ -21,7 +21,7 @@ |
||
| 21 | 21 | * |
| 22 | 22 | * @param integer $roleId |
| 23 | 23 | * @param array $permissionIds |
| 24 | - * @return object |
|
| 24 | + * @return boolean |
|
| 25 | 25 | */ |
| 26 | 26 | public function assignPermissions($roleId, $permissionIds) |
| 27 | 27 | { |
@@ -5,33 +5,33 @@ |
||
| 5 | 5 | |
| 6 | 6 | class RoleService extends BaseService |
| 7 | 7 | { |
| 8 | - /** |
|
| 9 | - * Init new object. |
|
| 10 | - * |
|
| 11 | - * @param RoleRepository $repo |
|
| 12 | - * @return void |
|
| 13 | - */ |
|
| 14 | - public function __construct(RoleRepository $repo) |
|
| 15 | - { |
|
| 16 | - parent::__construct($repo); |
|
| 17 | - } |
|
| 8 | + /** |
|
| 9 | + * Init new object. |
|
| 10 | + * |
|
| 11 | + * @param RoleRepository $repo |
|
| 12 | + * @return void |
|
| 13 | + */ |
|
| 14 | + public function __construct(RoleRepository $repo) |
|
| 15 | + { |
|
| 16 | + parent::__construct($repo); |
|
| 17 | + } |
|
| 18 | 18 | |
| 19 | - /** |
|
| 20 | - * Assign the given permission ids to the given role. |
|
| 21 | - * |
|
| 22 | - * @param integer $roleId |
|
| 23 | - * @param array $permissionIds |
|
| 24 | - * @return object |
|
| 25 | - */ |
|
| 26 | - public function assignPermissions($roleId, $permissionIds) |
|
| 27 | - { |
|
| 28 | - $role = false; |
|
| 29 | - \DB::transaction(function () use ($roleId, $permissionIds, &$role) { |
|
| 30 | - $role = $this->repo->find($roleId); |
|
| 31 | - $this->repo->detachPermissions($roleId); |
|
| 32 | - $this->repo->attachPermissions($roleId, $permissionIds); |
|
| 33 | - }); |
|
| 19 | + /** |
|
| 20 | + * Assign the given permission ids to the given role. |
|
| 21 | + * |
|
| 22 | + * @param integer $roleId |
|
| 23 | + * @param array $permissionIds |
|
| 24 | + * @return object |
|
| 25 | + */ |
|
| 26 | + public function assignPermissions($roleId, $permissionIds) |
|
| 27 | + { |
|
| 28 | + $role = false; |
|
| 29 | + \DB::transaction(function () use ($roleId, $permissionIds, &$role) { |
|
| 30 | + $role = $this->repo->find($roleId); |
|
| 31 | + $this->repo->detachPermissions($roleId); |
|
| 32 | + $this->repo->attachPermissions($roleId, $permissionIds); |
|
| 33 | + }); |
|
| 34 | 34 | |
| 35 | - return $role; |
|
| 36 | - } |
|
| 35 | + return $role; |
|
| 36 | + } |
|
| 37 | 37 | } |
@@ -26,7 +26,7 @@ |
||
| 26 | 26 | public function assignPermissions($roleId, $permissionIds) |
| 27 | 27 | { |
| 28 | 28 | $role = false; |
| 29 | - \DB::transaction(function () use ($roleId, $permissionIds, &$role) { |
|
| 29 | + \DB::transaction(function() use ($roleId, $permissionIds, &$role) { |
|
| 30 | 30 | $role = $this->repo->find($roleId); |
| 31 | 31 | $this->repo->detachPermissions($roleId); |
| 32 | 32 | $this->repo->attachPermissions($roleId, $permissionIds); |
@@ -5,7 +5,6 @@ |
||
| 5 | 5 | use Illuminate\Http\Request; |
| 6 | 6 | use App\Modules\Core\BaseClasses\BaseApiController; |
| 7 | 7 | use App\Modules\Users\Services\UserService; |
| 8 | -use App\Modules\Users\Proxy\LoginProxy; |
|
| 9 | 8 | use App\Modules\Core\Http\Resources\General as GeneralResource; |
| 10 | 9 | use Illuminate\Support\Facades\App; |
| 11 | 10 | use App\Modules\Users\Http\Requests\AssignRoles; |
@@ -24,225 +24,225 @@ |
||
| 24 | 24 | |
| 25 | 25 | class UserController extends BaseApiController |
| 26 | 26 | { |
| 27 | - /** |
|
| 28 | - * Path of the model resource |
|
| 29 | - * |
|
| 30 | - * @var string |
|
| 31 | - */ |
|
| 32 | - protected $modelResource = 'App\Modules\Users\Http\Resources\AclUser'; |
|
| 33 | - |
|
| 34 | - /** |
|
| 35 | - * List of all route actions that the base api controller |
|
| 36 | - * will skip permissions check for them. |
|
| 37 | - * @var array |
|
| 38 | - */ |
|
| 39 | - protected $skipPermissionCheck = ['account', 'logout', 'changePassword', 'saveProfile']; |
|
| 40 | - |
|
| 41 | - /** |
|
| 42 | - * List of all route actions that the base api controller |
|
| 43 | - * will skip login check for them. |
|
| 44 | - * @var array |
|
| 45 | - */ |
|
| 46 | - protected $skipLoginCheck = ['login', 'loginSocial', 'register', 'sendReset', 'resetPassword', 'refreshToken', 'confirmEmail', 'resendEmailConfirmation']; |
|
| 47 | - |
|
| 48 | - /** |
|
| 49 | - * Init new object. |
|
| 50 | - * |
|
| 51 | - * @param UserService $service |
|
| 52 | - * @return void |
|
| 53 | - */ |
|
| 54 | - public function __construct(UserService $service) |
|
| 55 | - { |
|
| 56 | - parent::__construct($service); |
|
| 57 | - } |
|
| 58 | - |
|
| 59 | - /** |
|
| 60 | - * Insert the given model to storage. |
|
| 61 | - * |
|
| 62 | - * @param InsertUser $request |
|
| 63 | - * @return \Illuminate\Http\Response |
|
| 64 | - */ |
|
| 65 | - public function insert(InsertUser $request) |
|
| 66 | - { |
|
| 67 | - return new $this->modelResource($this->service->save($request->all())); |
|
| 68 | - } |
|
| 69 | - |
|
| 70 | - /** |
|
| 71 | - * Update the given model to storage. |
|
| 72 | - * |
|
| 73 | - * @param UpdateUser $request |
|
| 74 | - * @return \Illuminate\Http\Response |
|
| 75 | - */ |
|
| 76 | - public function update(UpdateUser $request) |
|
| 77 | - { |
|
| 78 | - return new $this->modelResource($this->service->save($request->all())); |
|
| 79 | - } |
|
| 80 | - |
|
| 81 | - /** |
|
| 82 | - * Return the logged in user account. |
|
| 83 | - * |
|
| 84 | - * @param Request $request |
|
| 85 | - * @return \Illuminate\Http\Response |
|
| 86 | - */ |
|
| 87 | - public function account(Request $request) |
|
| 88 | - { |
|
| 89 | - return new $this->modelResource($this->service->account($request->relations)); |
|
| 90 | - } |
|
| 91 | - |
|
| 92 | - /** |
|
| 93 | - * Block the user. |
|
| 94 | - * |
|
| 95 | - * @param integer $id Id of the user. |
|
| 96 | - * @return \Illuminate\Http\Response |
|
| 97 | - */ |
|
| 98 | - public function block($id) |
|
| 99 | - { |
|
| 100 | - return new $this->modelResource($this->service->block($id)); |
|
| 101 | - } |
|
| 102 | - |
|
| 103 | - /** |
|
| 104 | - * Unblock the user. |
|
| 105 | - * |
|
| 106 | - * @param integer $id Id of the user. |
|
| 107 | - * @return \Illuminate\Http\Response |
|
| 108 | - */ |
|
| 109 | - public function unblock($id) |
|
| 110 | - { |
|
| 111 | - return new $this->modelResource($this->service->unblock($id)); |
|
| 112 | - } |
|
| 113 | - |
|
| 114 | - /** |
|
| 115 | - * Logout the user. |
|
| 116 | - * |
|
| 117 | - * @return \Illuminate\Http\Response |
|
| 118 | - */ |
|
| 119 | - public function logout() |
|
| 120 | - { |
|
| 121 | - return new GeneralResource($this->service->logout()); |
|
| 122 | - } |
|
| 123 | - |
|
| 124 | - /** |
|
| 125 | - * Handle a registration request. |
|
| 126 | - * |
|
| 127 | - * @param Register $request |
|
| 128 | - * @return \Illuminate\Http\Response |
|
| 129 | - */ |
|
| 130 | - public function register(Register $request) |
|
| 131 | - { |
|
| 132 | - return new $this->modelResource($this->service->register($request->get('name'), $request->get('email'), $request->get('password'))); |
|
| 133 | - } |
|
| 134 | - |
|
| 135 | - /** |
|
| 136 | - * Handle a login request to the application. |
|
| 137 | - * |
|
| 138 | - * @param Login $request |
|
| 139 | - * @return \Illuminate\Http\Response |
|
| 140 | - */ |
|
| 141 | - public function login(Login $request) |
|
| 142 | - { |
|
| 143 | - $result = $this->service->login($request->get('email'), $request->get('password'), $request->get('admin')); |
|
| 144 | - |
|
| 145 | - return (new $this->modelResource($result['user']))->additional(['meta' => $result['tokens']]); |
|
| 146 | - } |
|
| 147 | - |
|
| 148 | - /** |
|
| 149 | - * Handle a social login request of the none admin to the application. |
|
| 150 | - * |
|
| 151 | - * @param LoginSocial $request |
|
| 152 | - * @return \Illuminate\Http\Response |
|
| 153 | - */ |
|
| 154 | - public function loginSocial(LoginSocial $request) |
|
| 155 | - { |
|
| 156 | - $result = $this->service->loginSocial($request->get('auth_code'), $request->get('access_token'), $request->get('type')); |
|
| 157 | - |
|
| 158 | - return (new $this->modelResource($result['user']))->additional(['meta' => $result['tokens']]); |
|
| 159 | - } |
|
| 160 | - |
|
| 161 | - /** |
|
| 162 | - * Assign the given roles to the given user. |
|
| 163 | - * |
|
| 164 | - * @param AssignRoles $request |
|
| 165 | - * @return \Illuminate\Http\Response |
|
| 166 | - */ |
|
| 167 | - public function assignRoles(AssignRoles $request) |
|
| 168 | - { |
|
| 169 | - return new $this->modelResource($this->service->assignRoles($request->get('user_id'), $request->get('role_ids'))); |
|
| 170 | - } |
|
| 171 | - |
|
| 172 | - /** |
|
| 173 | - * Send a reset link to the given user. |
|
| 174 | - * |
|
| 175 | - * @param SendReset $request |
|
| 176 | - * @return \Illuminate\Http\Response |
|
| 177 | - */ |
|
| 178 | - public function sendReset(SendReset $request) |
|
| 179 | - { |
|
| 180 | - return new GeneralResource($this->service->sendReset($request->get('email'))); |
|
| 181 | - } |
|
| 182 | - |
|
| 183 | - /** |
|
| 184 | - * Reset the given user's password. |
|
| 185 | - * |
|
| 186 | - * @param ResetPassword $request |
|
| 187 | - * @return \Illuminate\Http\Response |
|
| 188 | - */ |
|
| 189 | - public function resetPassword(ResetPassword $request) |
|
| 190 | - { |
|
| 191 | - return new GeneralResource($this->service->resetPassword($request->get('email'), $request->get('password'), $request->get('password_confirmation'), $request->get('token'))); |
|
| 192 | - } |
|
| 193 | - |
|
| 194 | - /** |
|
| 195 | - * Change the logged in user password. |
|
| 196 | - * |
|
| 197 | - * @param ChangePassword $request |
|
| 198 | - * @return \Illuminate\Http\Response |
|
| 199 | - */ |
|
| 200 | - public function changePassword(ChangePassword $request) |
|
| 201 | - { |
|
| 202 | - return new GeneralResource($this->service->changePassword($request->get('password') , $request->get('old_password'))); |
|
| 203 | - } |
|
| 204 | - |
|
| 205 | - /** |
|
| 206 | - * Confirm email using the confirmation code. |
|
| 207 | - * |
|
| 208 | - * @param ConfirmEmail $request |
|
| 209 | - * @return \Illuminate\Http\Response |
|
| 210 | - */ |
|
| 211 | - public function confirmEmail(ConfirmEmail $request) |
|
| 212 | - { |
|
| 213 | - return new GeneralResource($this->service->confirmEmail($request->only('confirmation_code'))); |
|
| 214 | - } |
|
| 215 | - |
|
| 216 | - /** |
|
| 217 | - * Resend the email confirmation mail. |
|
| 218 | - * |
|
| 219 | - * @param ResendEmailConfirmation $request |
|
| 220 | - * @return \Illuminate\Http\Response |
|
| 221 | - */ |
|
| 222 | - public function resendEmailConfirmation(ResendEmailConfirmation $request) |
|
| 223 | - { |
|
| 224 | - return new GeneralResource($this->service->sendConfirmationEmail($request->get('email'))); |
|
| 225 | - } |
|
| 226 | - |
|
| 227 | - /** |
|
| 228 | - * Refresh the expired login token. |
|
| 229 | - * |
|
| 230 | - * @param RefreshToken $request |
|
| 231 | - * @return \Illuminate\Http\Response |
|
| 232 | - */ |
|
| 233 | - public function refreshToken(RefreshToken $request) |
|
| 234 | - { |
|
| 235 | - return new GeneralResource($this->service->refreshToken($request->get('refresh_token'))); |
|
| 236 | - } |
|
| 237 | - |
|
| 238 | - /** |
|
| 239 | - * Save the given data to the logged in user. |
|
| 240 | - * |
|
| 241 | - * @param SaveProfile $request |
|
| 242 | - * @return \Illuminate\Http\Response |
|
| 243 | - */ |
|
| 244 | - public function saveProfile(SaveProfile $request) |
|
| 245 | - { |
|
| 246 | - return new $this->modelResource($this->service->saveProfile($request->get('name'), $request->get('email'), $request->get('profile_picture'))); |
|
| 247 | - } |
|
| 27 | + /** |
|
| 28 | + * Path of the model resource |
|
| 29 | + * |
|
| 30 | + * @var string |
|
| 31 | + */ |
|
| 32 | + protected $modelResource = 'App\Modules\Users\Http\Resources\AclUser'; |
|
| 33 | + |
|
| 34 | + /** |
|
| 35 | + * List of all route actions that the base api controller |
|
| 36 | + * will skip permissions check for them. |
|
| 37 | + * @var array |
|
| 38 | + */ |
|
| 39 | + protected $skipPermissionCheck = ['account', 'logout', 'changePassword', 'saveProfile']; |
|
| 40 | + |
|
| 41 | + /** |
|
| 42 | + * List of all route actions that the base api controller |
|
| 43 | + * will skip login check for them. |
|
| 44 | + * @var array |
|
| 45 | + */ |
|
| 46 | + protected $skipLoginCheck = ['login', 'loginSocial', 'register', 'sendReset', 'resetPassword', 'refreshToken', 'confirmEmail', 'resendEmailConfirmation']; |
|
| 47 | + |
|
| 48 | + /** |
|
| 49 | + * Init new object. |
|
| 50 | + * |
|
| 51 | + * @param UserService $service |
|
| 52 | + * @return void |
|
| 53 | + */ |
|
| 54 | + public function __construct(UserService $service) |
|
| 55 | + { |
|
| 56 | + parent::__construct($service); |
|
| 57 | + } |
|
| 58 | + |
|
| 59 | + /** |
|
| 60 | + * Insert the given model to storage. |
|
| 61 | + * |
|
| 62 | + * @param InsertUser $request |
|
| 63 | + * @return \Illuminate\Http\Response |
|
| 64 | + */ |
|
| 65 | + public function insert(InsertUser $request) |
|
| 66 | + { |
|
| 67 | + return new $this->modelResource($this->service->save($request->all())); |
|
| 68 | + } |
|
| 69 | + |
|
| 70 | + /** |
|
| 71 | + * Update the given model to storage. |
|
| 72 | + * |
|
| 73 | + * @param UpdateUser $request |
|
| 74 | + * @return \Illuminate\Http\Response |
|
| 75 | + */ |
|
| 76 | + public function update(UpdateUser $request) |
|
| 77 | + { |
|
| 78 | + return new $this->modelResource($this->service->save($request->all())); |
|
| 79 | + } |
|
| 80 | + |
|
| 81 | + /** |
|
| 82 | + * Return the logged in user account. |
|
| 83 | + * |
|
| 84 | + * @param Request $request |
|
| 85 | + * @return \Illuminate\Http\Response |
|
| 86 | + */ |
|
| 87 | + public function account(Request $request) |
|
| 88 | + { |
|
| 89 | + return new $this->modelResource($this->service->account($request->relations)); |
|
| 90 | + } |
|
| 91 | + |
|
| 92 | + /** |
|
| 93 | + * Block the user. |
|
| 94 | + * |
|
| 95 | + * @param integer $id Id of the user. |
|
| 96 | + * @return \Illuminate\Http\Response |
|
| 97 | + */ |
|
| 98 | + public function block($id) |
|
| 99 | + { |
|
| 100 | + return new $this->modelResource($this->service->block($id)); |
|
| 101 | + } |
|
| 102 | + |
|
| 103 | + /** |
|
| 104 | + * Unblock the user. |
|
| 105 | + * |
|
| 106 | + * @param integer $id Id of the user. |
|
| 107 | + * @return \Illuminate\Http\Response |
|
| 108 | + */ |
|
| 109 | + public function unblock($id) |
|
| 110 | + { |
|
| 111 | + return new $this->modelResource($this->service->unblock($id)); |
|
| 112 | + } |
|
| 113 | + |
|
| 114 | + /** |
|
| 115 | + * Logout the user. |
|
| 116 | + * |
|
| 117 | + * @return \Illuminate\Http\Response |
|
| 118 | + */ |
|
| 119 | + public function logout() |
|
| 120 | + { |
|
| 121 | + return new GeneralResource($this->service->logout()); |
|
| 122 | + } |
|
| 123 | + |
|
| 124 | + /** |
|
| 125 | + * Handle a registration request. |
|
| 126 | + * |
|
| 127 | + * @param Register $request |
|
| 128 | + * @return \Illuminate\Http\Response |
|
| 129 | + */ |
|
| 130 | + public function register(Register $request) |
|
| 131 | + { |
|
| 132 | + return new $this->modelResource($this->service->register($request->get('name'), $request->get('email'), $request->get('password'))); |
|
| 133 | + } |
|
| 134 | + |
|
| 135 | + /** |
|
| 136 | + * Handle a login request to the application. |
|
| 137 | + * |
|
| 138 | + * @param Login $request |
|
| 139 | + * @return \Illuminate\Http\Response |
|
| 140 | + */ |
|
| 141 | + public function login(Login $request) |
|
| 142 | + { |
|
| 143 | + $result = $this->service->login($request->get('email'), $request->get('password'), $request->get('admin')); |
|
| 144 | + |
|
| 145 | + return (new $this->modelResource($result['user']))->additional(['meta' => $result['tokens']]); |
|
| 146 | + } |
|
| 147 | + |
|
| 148 | + /** |
|
| 149 | + * Handle a social login request of the none admin to the application. |
|
| 150 | + * |
|
| 151 | + * @param LoginSocial $request |
|
| 152 | + * @return \Illuminate\Http\Response |
|
| 153 | + */ |
|
| 154 | + public function loginSocial(LoginSocial $request) |
|
| 155 | + { |
|
| 156 | + $result = $this->service->loginSocial($request->get('auth_code'), $request->get('access_token'), $request->get('type')); |
|
| 157 | + |
|
| 158 | + return (new $this->modelResource($result['user']))->additional(['meta' => $result['tokens']]); |
|
| 159 | + } |
|
| 160 | + |
|
| 161 | + /** |
|
| 162 | + * Assign the given roles to the given user. |
|
| 163 | + * |
|
| 164 | + * @param AssignRoles $request |
|
| 165 | + * @return \Illuminate\Http\Response |
|
| 166 | + */ |
|
| 167 | + public function assignRoles(AssignRoles $request) |
|
| 168 | + { |
|
| 169 | + return new $this->modelResource($this->service->assignRoles($request->get('user_id'), $request->get('role_ids'))); |
|
| 170 | + } |
|
| 171 | + |
|
| 172 | + /** |
|
| 173 | + * Send a reset link to the given user. |
|
| 174 | + * |
|
| 175 | + * @param SendReset $request |
|
| 176 | + * @return \Illuminate\Http\Response |
|
| 177 | + */ |
|
| 178 | + public function sendReset(SendReset $request) |
|
| 179 | + { |
|
| 180 | + return new GeneralResource($this->service->sendReset($request->get('email'))); |
|
| 181 | + } |
|
| 182 | + |
|
| 183 | + /** |
|
| 184 | + * Reset the given user's password. |
|
| 185 | + * |
|
| 186 | + * @param ResetPassword $request |
|
| 187 | + * @return \Illuminate\Http\Response |
|
| 188 | + */ |
|
| 189 | + public function resetPassword(ResetPassword $request) |
|
| 190 | + { |
|
| 191 | + return new GeneralResource($this->service->resetPassword($request->get('email'), $request->get('password'), $request->get('password_confirmation'), $request->get('token'))); |
|
| 192 | + } |
|
| 193 | + |
|
| 194 | + /** |
|
| 195 | + * Change the logged in user password. |
|
| 196 | + * |
|
| 197 | + * @param ChangePassword $request |
|
| 198 | + * @return \Illuminate\Http\Response |
|
| 199 | + */ |
|
| 200 | + public function changePassword(ChangePassword $request) |
|
| 201 | + { |
|
| 202 | + return new GeneralResource($this->service->changePassword($request->get('password') , $request->get('old_password'))); |
|
| 203 | + } |
|
| 204 | + |
|
| 205 | + /** |
|
| 206 | + * Confirm email using the confirmation code. |
|
| 207 | + * |
|
| 208 | + * @param ConfirmEmail $request |
|
| 209 | + * @return \Illuminate\Http\Response |
|
| 210 | + */ |
|
| 211 | + public function confirmEmail(ConfirmEmail $request) |
|
| 212 | + { |
|
| 213 | + return new GeneralResource($this->service->confirmEmail($request->only('confirmation_code'))); |
|
| 214 | + } |
|
| 215 | + |
|
| 216 | + /** |
|
| 217 | + * Resend the email confirmation mail. |
|
| 218 | + * |
|
| 219 | + * @param ResendEmailConfirmation $request |
|
| 220 | + * @return \Illuminate\Http\Response |
|
| 221 | + */ |
|
| 222 | + public function resendEmailConfirmation(ResendEmailConfirmation $request) |
|
| 223 | + { |
|
| 224 | + return new GeneralResource($this->service->sendConfirmationEmail($request->get('email'))); |
|
| 225 | + } |
|
| 226 | + |
|
| 227 | + /** |
|
| 228 | + * Refresh the expired login token. |
|
| 229 | + * |
|
| 230 | + * @param RefreshToken $request |
|
| 231 | + * @return \Illuminate\Http\Response |
|
| 232 | + */ |
|
| 233 | + public function refreshToken(RefreshToken $request) |
|
| 234 | + { |
|
| 235 | + return new GeneralResource($this->service->refreshToken($request->get('refresh_token'))); |
|
| 236 | + } |
|
| 237 | + |
|
| 238 | + /** |
|
| 239 | + * Save the given data to the logged in user. |
|
| 240 | + * |
|
| 241 | + * @param SaveProfile $request |
|
| 242 | + * @return \Illuminate\Http\Response |
|
| 243 | + */ |
|
| 244 | + public function saveProfile(SaveProfile $request) |
|
| 245 | + { |
|
| 246 | + return new $this->modelResource($this->service->saveProfile($request->get('name'), $request->get('email'), $request->get('profile_picture'))); |
|
| 247 | + } |
|
| 248 | 248 | } |
@@ -199,7 +199,7 @@ |
||
| 199 | 199 | */ |
| 200 | 200 | public function changePassword(ChangePassword $request) |
| 201 | 201 | { |
| 202 | - return new GeneralResource($this->service->changePassword($request->get('password') , $request->get('old_password'))); |
|
| 202 | + return new GeneralResource($this->service->changePassword($request->get('password'), $request->get('old_password'))); |
|
| 203 | 203 | } |
| 204 | 204 | |
| 205 | 205 | /** |
@@ -1,7 +1,6 @@ |
||
| 1 | 1 | <?php namespace App\Modules\Users\Repositories; |
| 2 | 2 | |
| 3 | 3 | use App\Modules\Core\BaseClasses\BaseRepository; |
| 4 | -use Illuminate\Support\Arr; |
|
| 5 | 4 | use App\Modules\Users\AclUser; |
| 6 | 5 | |
| 7 | 6 | class UserRepository extends BaseRepository |
@@ -6,52 +6,52 @@ |
||
| 6 | 6 | |
| 7 | 7 | class UserRepository extends BaseRepository |
| 8 | 8 | { |
| 9 | - /** |
|
| 10 | - * Init new object. |
|
| 11 | - * |
|
| 12 | - * @param AclUser $model |
|
| 13 | - * @return void |
|
| 14 | - */ |
|
| 15 | - public function __construct(AclUser $model) |
|
| 16 | - { |
|
| 17 | - parent::__construct($model); |
|
| 18 | - } |
|
| 9 | + /** |
|
| 10 | + * Init new object. |
|
| 11 | + * |
|
| 12 | + * @param AclUser $model |
|
| 13 | + * @return void |
|
| 14 | + */ |
|
| 15 | + public function __construct(AclUser $model) |
|
| 16 | + { |
|
| 17 | + parent::__construct($model); |
|
| 18 | + } |
|
| 19 | 19 | |
| 20 | - /** |
|
| 21 | - * Detach all roles from the given role. |
|
| 22 | - * |
|
| 23 | - * @param mixed $role |
|
| 24 | - * @return object |
|
| 25 | - */ |
|
| 26 | - public function detachRoles($role) |
|
| 27 | - { |
|
| 28 | - $role = ! is_int($role) ? $role : $this->find($role); |
|
| 29 | - $role->roles()->detach(); |
|
| 30 | - } |
|
| 20 | + /** |
|
| 21 | + * Detach all roles from the given role. |
|
| 22 | + * |
|
| 23 | + * @param mixed $role |
|
| 24 | + * @return object |
|
| 25 | + */ |
|
| 26 | + public function detachRoles($role) |
|
| 27 | + { |
|
| 28 | + $role = ! is_int($role) ? $role : $this->find($role); |
|
| 29 | + $role->roles()->detach(); |
|
| 30 | + } |
|
| 31 | 31 | |
| 32 | - /** |
|
| 33 | - * Attach role ids to the given role. |
|
| 34 | - * |
|
| 35 | - * @param mixed $role |
|
| 36 | - * @param array $roleIds |
|
| 37 | - * @return object |
|
| 38 | - */ |
|
| 39 | - public function attachRoles($role, $roleIds) |
|
| 40 | - { |
|
| 41 | - $role = ! is_int($role) ? $role : $this->find($role); |
|
| 42 | - $role->roles()->attach($roleIds); |
|
| 43 | - } |
|
| 32 | + /** |
|
| 33 | + * Attach role ids to the given role. |
|
| 34 | + * |
|
| 35 | + * @param mixed $role |
|
| 36 | + * @param array $roleIds |
|
| 37 | + * @return object |
|
| 38 | + */ |
|
| 39 | + public function attachRoles($role, $roleIds) |
|
| 40 | + { |
|
| 41 | + $role = ! is_int($role) ? $role : $this->find($role); |
|
| 42 | + $role->roles()->attach($roleIds); |
|
| 43 | + } |
|
| 44 | 44 | |
| 45 | - /** |
|
| 46 | - * Count the given user the given roles. |
|
| 47 | - * |
|
| 48 | - * @param mixed $user |
|
| 49 | - * @param string[] $roles |
|
| 50 | - * @return boolean |
|
| 51 | - */ |
|
| 52 | - public function countRoles($user, $roles) |
|
| 53 | - { |
|
| 54 | - $user = ! is_int($user) ? $user : $this->find($user); |
|
| 55 | - return $user->roles()->whereIn('name', $roles)->count(); |
|
| 56 | - } |
|
| 45 | + /** |
|
| 46 | + * Count the given user the given roles. |
|
| 47 | + * |
|
| 48 | + * @param mixed $user |
|
| 49 | + * @param string[] $roles |
|
| 50 | + * @return boolean |
|
| 51 | + */ |
|
| 52 | + public function countRoles($user, $roles) |
|
| 53 | + { |
|
| 54 | + $user = ! is_int($user) ? $user : $this->find($user); |
|
| 55 | + return $user->roles()->whereIn('name', $roles)->count(); |
|
| 56 | + } |
|
| 57 | 57 | } |
@@ -132,7 +132,7 @@ |
||
| 132 | 132 | * |
| 133 | 133 | * @param integer $userId |
| 134 | 134 | * @param array $roleIds |
| 135 | - * @return object |
|
| 135 | + * @return boolean |
|
| 136 | 136 | */ |
| 137 | 137 | public function assignRoles($userId, $roleIds) |
| 138 | 138 | { |
@@ -11,390 +11,390 @@ |
||
| 11 | 11 | |
| 12 | 12 | class UserService extends BaseService |
| 13 | 13 | { |
| 14 | - /** |
|
| 15 | - * @var PermissionService |
|
| 16 | - */ |
|
| 17 | - protected $permissionService; |
|
| 18 | - |
|
| 19 | - /** |
|
| 20 | - * @var LoginProxy |
|
| 21 | - */ |
|
| 22 | - protected $loginProxy; |
|
| 23 | - |
|
| 24 | - /** |
|
| 25 | - * @var Media |
|
| 26 | - */ |
|
| 27 | - protected $media; |
|
| 28 | - |
|
| 29 | - /** |
|
| 30 | - * @var NotificationService |
|
| 31 | - */ |
|
| 32 | - protected $notificationService; |
|
| 33 | - |
|
| 34 | - /** |
|
| 35 | - * @var OauthClientService |
|
| 36 | - */ |
|
| 37 | - protected $oauthClientService; |
|
| 38 | - |
|
| 39 | - /** |
|
| 40 | - * Init new object. |
|
| 41 | - * |
|
| 42 | - * @param UserRepository $repo |
|
| 43 | - * @param PermissionService $permissionService |
|
| 44 | - * @param LoginProxy $loginProxy |
|
| 45 | - * @param Media $media |
|
| 46 | - * @param NotificationService $notificationService |
|
| 47 | - * @param OauthClientService $oauthClientService |
|
| 48 | - * @return void |
|
| 49 | - */ |
|
| 50 | - public function __construct( |
|
| 51 | - UserRepository $repo, |
|
| 52 | - PermissionService $permissionService, |
|
| 53 | - LoginProxy $loginProxy, |
|
| 54 | - Media $media, |
|
| 55 | - NotificationService $notificationService, |
|
| 56 | - OauthClientService $oauthClientService) |
|
| 57 | - { |
|
| 58 | - $this->permissionService = $permissionService; |
|
| 59 | - $this->loginProxy = $loginProxy; |
|
| 60 | - $this->media = $media; |
|
| 61 | - $this->notificationService = $notificationService; |
|
| 62 | - $this->oauthClientService = $oauthClientService; |
|
| 63 | - parent::__construct($repo); |
|
| 64 | - } |
|
| 65 | - |
|
| 66 | - /** |
|
| 67 | - * Return the logged in user account. |
|
| 68 | - * |
|
| 69 | - * @param array $relations |
|
| 70 | - * @return boolean |
|
| 71 | - */ |
|
| 72 | - public function account($relations = ['roles.permissions']) |
|
| 73 | - { |
|
| 74 | - $permissions = []; |
|
| 75 | - $user = $this->repo->find(\Auth::id(), $relations); |
|
| 76 | - foreach ($user->roles as $role) { |
|
| 77 | - $role->permissions->each(function ($permission) use (&$permissions) { |
|
| 78 | - $permissions[$permission->repo][$permission->id] = $permission->name; |
|
| 79 | - }); |
|
| 80 | - } |
|
| 81 | - $user->permissions = $permissions; |
|
| 82 | - |
|
| 83 | - return $user; |
|
| 84 | - } |
|
| 85 | - |
|
| 86 | - /** |
|
| 87 | - * Check if the logged in user or the given user |
|
| 88 | - * has the given permissions on the given model. |
|
| 89 | - * |
|
| 90 | - * @param string $permissionName |
|
| 91 | - * @param string $model |
|
| 92 | - * @param mixed $userId |
|
| 93 | - * @return boolean |
|
| 94 | - */ |
|
| 95 | - public function can($permissionName, $model, $userId = false) |
|
| 96 | - { |
|
| 97 | - $permission = $this->permissionService->first([ |
|
| 98 | - 'and' => [ |
|
| 99 | - 'model' => $model, |
|
| 100 | - 'name' => $permissionName, |
|
| 101 | - 'roles' => [ |
|
| 102 | - 'op' => 'has', |
|
| 103 | - 'val' => [ |
|
| 104 | - 'users' => [ |
|
| 105 | - 'op' => 'has', |
|
| 106 | - 'val' => [ |
|
| 107 | - 'users.id' => $userId ?: \Auth::id() |
|
| 108 | - ] |
|
| 109 | - ] |
|
| 110 | - ] |
|
| 111 | - ] |
|
| 112 | - ] |
|
| 113 | - ]); |
|
| 114 | - |
|
| 115 | - return $permission ? true : false; |
|
| 116 | - } |
|
| 117 | - |
|
| 118 | - /** |
|
| 119 | - * Check if the logged in or the given user has the given role. |
|
| 120 | - * |
|
| 121 | - * @param string[] $roles |
|
| 122 | - * @param mixed $user |
|
| 123 | - * @return boolean |
|
| 124 | - */ |
|
| 125 | - public function hasRoles($roles, $user = false) |
|
| 126 | - { |
|
| 127 | - return $this->repo->countRoles($user ?: \Auth::id(), $roles) ? true : false; |
|
| 128 | - } |
|
| 129 | - |
|
| 130 | - /** |
|
| 131 | - * Assign the given role ids to the given user. |
|
| 132 | - * |
|
| 133 | - * @param integer $userId |
|
| 134 | - * @param array $roleIds |
|
| 135 | - * @return object |
|
| 136 | - */ |
|
| 137 | - public function assignRoles($userId, $roleIds) |
|
| 138 | - { |
|
| 139 | - $user = false; |
|
| 140 | - \DB::transaction(function () use ($userId, $permissionIds, &$user) { |
|
| 141 | - $user = $this->repo->find($userId); |
|
| 142 | - $this->repo->detachPermissions($userId); |
|
| 143 | - $this->repo->attachPermissions($userId, $roleIds); |
|
| 144 | - }); |
|
| 145 | - |
|
| 146 | - return $user; |
|
| 147 | - } |
|
| 148 | - |
|
| 149 | - /** |
|
| 150 | - * Handle a login request to the application. |
|
| 151 | - * |
|
| 152 | - * @param string $email |
|
| 153 | - * @param string $password |
|
| 154 | - * @param boolean $adminLogin |
|
| 155 | - * @return object |
|
| 156 | - */ |
|
| 157 | - public function login($email, $password, $adminLogin = false) |
|
| 158 | - { |
|
| 159 | - if (! $user = $this->repo->first(['email' => $email])) { |
|
| 160 | - \ErrorHandler::loginFailed(); |
|
| 161 | - } elseif ($adminLogin && ! $this->hasRoles(['Admin'], $user)) { |
|
| 162 | - \ErrorHandler::loginFailed(); |
|
| 163 | - } elseif (! $adminLogin && $this->hasRoles(['Admin'], $user)) { |
|
| 164 | - \ErrorHandler::loginFailed(); |
|
| 165 | - } elseif ($user->blocked) { |
|
| 166 | - \ErrorHandler::userIsBlocked(); |
|
| 167 | - } elseif (! config('skeleton.disable_confirm_email') && ! $user->confirmed) { |
|
| 168 | - \ErrorHandler::emailNotConfirmed(); |
|
| 169 | - } |
|
| 170 | - |
|
| 171 | - return ['user' => $user, 'tokens' => $this->loginProxy->login($user->email, $password)]; |
|
| 172 | - } |
|
| 173 | - |
|
| 174 | - /** |
|
| 175 | - * Handle a social login request of the none admin to the application. |
|
| 176 | - * |
|
| 177 | - * @param string $authCode |
|
| 178 | - * @param string $accessToken |
|
| 179 | - * @param string $type |
|
| 180 | - * @return array |
|
| 181 | - */ |
|
| 182 | - public function loginSocial($authCode, $accessToken, $type) |
|
| 183 | - { |
|
| 184 | - $access_token = $authCode ? Arr::get(\Socialite::driver($type)->getAccessTokenResponse($authCode), 'access_token') : $accessToken; |
|
| 185 | - $user = \Socialite::driver($type)->userFromToken($access_token); |
|
| 186 | - |
|
| 187 | - if (! $user->email) { |
|
| 188 | - \ErrorHandler::noSocialEmail(); |
|
| 189 | - } |
|
| 190 | - |
|
| 191 | - if (! $this->repo->first(['email' => $user->email])) { |
|
| 192 | - $this->register(['email' => $user->email, 'password' => ''], true); |
|
| 193 | - } |
|
| 194 | - |
|
| 195 | - return $this->loginProxy->login($user->email, config('skeleton.social_pass')); |
|
| 196 | - } |
|
| 14 | + /** |
|
| 15 | + * @var PermissionService |
|
| 16 | + */ |
|
| 17 | + protected $permissionService; |
|
| 18 | + |
|
| 19 | + /** |
|
| 20 | + * @var LoginProxy |
|
| 21 | + */ |
|
| 22 | + protected $loginProxy; |
|
| 23 | + |
|
| 24 | + /** |
|
| 25 | + * @var Media |
|
| 26 | + */ |
|
| 27 | + protected $media; |
|
| 28 | + |
|
| 29 | + /** |
|
| 30 | + * @var NotificationService |
|
| 31 | + */ |
|
| 32 | + protected $notificationService; |
|
| 33 | + |
|
| 34 | + /** |
|
| 35 | + * @var OauthClientService |
|
| 36 | + */ |
|
| 37 | + protected $oauthClientService; |
|
| 38 | + |
|
| 39 | + /** |
|
| 40 | + * Init new object. |
|
| 41 | + * |
|
| 42 | + * @param UserRepository $repo |
|
| 43 | + * @param PermissionService $permissionService |
|
| 44 | + * @param LoginProxy $loginProxy |
|
| 45 | + * @param Media $media |
|
| 46 | + * @param NotificationService $notificationService |
|
| 47 | + * @param OauthClientService $oauthClientService |
|
| 48 | + * @return void |
|
| 49 | + */ |
|
| 50 | + public function __construct( |
|
| 51 | + UserRepository $repo, |
|
| 52 | + PermissionService $permissionService, |
|
| 53 | + LoginProxy $loginProxy, |
|
| 54 | + Media $media, |
|
| 55 | + NotificationService $notificationService, |
|
| 56 | + OauthClientService $oauthClientService) |
|
| 57 | + { |
|
| 58 | + $this->permissionService = $permissionService; |
|
| 59 | + $this->loginProxy = $loginProxy; |
|
| 60 | + $this->media = $media; |
|
| 61 | + $this->notificationService = $notificationService; |
|
| 62 | + $this->oauthClientService = $oauthClientService; |
|
| 63 | + parent::__construct($repo); |
|
| 64 | + } |
|
| 65 | + |
|
| 66 | + /** |
|
| 67 | + * Return the logged in user account. |
|
| 68 | + * |
|
| 69 | + * @param array $relations |
|
| 70 | + * @return boolean |
|
| 71 | + */ |
|
| 72 | + public function account($relations = ['roles.permissions']) |
|
| 73 | + { |
|
| 74 | + $permissions = []; |
|
| 75 | + $user = $this->repo->find(\Auth::id(), $relations); |
|
| 76 | + foreach ($user->roles as $role) { |
|
| 77 | + $role->permissions->each(function ($permission) use (&$permissions) { |
|
| 78 | + $permissions[$permission->repo][$permission->id] = $permission->name; |
|
| 79 | + }); |
|
| 80 | + } |
|
| 81 | + $user->permissions = $permissions; |
|
| 82 | + |
|
| 83 | + return $user; |
|
| 84 | + } |
|
| 85 | + |
|
| 86 | + /** |
|
| 87 | + * Check if the logged in user or the given user |
|
| 88 | + * has the given permissions on the given model. |
|
| 89 | + * |
|
| 90 | + * @param string $permissionName |
|
| 91 | + * @param string $model |
|
| 92 | + * @param mixed $userId |
|
| 93 | + * @return boolean |
|
| 94 | + */ |
|
| 95 | + public function can($permissionName, $model, $userId = false) |
|
| 96 | + { |
|
| 97 | + $permission = $this->permissionService->first([ |
|
| 98 | + 'and' => [ |
|
| 99 | + 'model' => $model, |
|
| 100 | + 'name' => $permissionName, |
|
| 101 | + 'roles' => [ |
|
| 102 | + 'op' => 'has', |
|
| 103 | + 'val' => [ |
|
| 104 | + 'users' => [ |
|
| 105 | + 'op' => 'has', |
|
| 106 | + 'val' => [ |
|
| 107 | + 'users.id' => $userId ?: \Auth::id() |
|
| 108 | + ] |
|
| 109 | + ] |
|
| 110 | + ] |
|
| 111 | + ] |
|
| 112 | + ] |
|
| 113 | + ]); |
|
| 114 | + |
|
| 115 | + return $permission ? true : false; |
|
| 116 | + } |
|
| 117 | + |
|
| 118 | + /** |
|
| 119 | + * Check if the logged in or the given user has the given role. |
|
| 120 | + * |
|
| 121 | + * @param string[] $roles |
|
| 122 | + * @param mixed $user |
|
| 123 | + * @return boolean |
|
| 124 | + */ |
|
| 125 | + public function hasRoles($roles, $user = false) |
|
| 126 | + { |
|
| 127 | + return $this->repo->countRoles($user ?: \Auth::id(), $roles) ? true : false; |
|
| 128 | + } |
|
| 129 | + |
|
| 130 | + /** |
|
| 131 | + * Assign the given role ids to the given user. |
|
| 132 | + * |
|
| 133 | + * @param integer $userId |
|
| 134 | + * @param array $roleIds |
|
| 135 | + * @return object |
|
| 136 | + */ |
|
| 137 | + public function assignRoles($userId, $roleIds) |
|
| 138 | + { |
|
| 139 | + $user = false; |
|
| 140 | + \DB::transaction(function () use ($userId, $permissionIds, &$user) { |
|
| 141 | + $user = $this->repo->find($userId); |
|
| 142 | + $this->repo->detachPermissions($userId); |
|
| 143 | + $this->repo->attachPermissions($userId, $roleIds); |
|
| 144 | + }); |
|
| 145 | + |
|
| 146 | + return $user; |
|
| 147 | + } |
|
| 148 | + |
|
| 149 | + /** |
|
| 150 | + * Handle a login request to the application. |
|
| 151 | + * |
|
| 152 | + * @param string $email |
|
| 153 | + * @param string $password |
|
| 154 | + * @param boolean $adminLogin |
|
| 155 | + * @return object |
|
| 156 | + */ |
|
| 157 | + public function login($email, $password, $adminLogin = false) |
|
| 158 | + { |
|
| 159 | + if (! $user = $this->repo->first(['email' => $email])) { |
|
| 160 | + \ErrorHandler::loginFailed(); |
|
| 161 | + } elseif ($adminLogin && ! $this->hasRoles(['Admin'], $user)) { |
|
| 162 | + \ErrorHandler::loginFailed(); |
|
| 163 | + } elseif (! $adminLogin && $this->hasRoles(['Admin'], $user)) { |
|
| 164 | + \ErrorHandler::loginFailed(); |
|
| 165 | + } elseif ($user->blocked) { |
|
| 166 | + \ErrorHandler::userIsBlocked(); |
|
| 167 | + } elseif (! config('skeleton.disable_confirm_email') && ! $user->confirmed) { |
|
| 168 | + \ErrorHandler::emailNotConfirmed(); |
|
| 169 | + } |
|
| 170 | + |
|
| 171 | + return ['user' => $user, 'tokens' => $this->loginProxy->login($user->email, $password)]; |
|
| 172 | + } |
|
| 173 | + |
|
| 174 | + /** |
|
| 175 | + * Handle a social login request of the none admin to the application. |
|
| 176 | + * |
|
| 177 | + * @param string $authCode |
|
| 178 | + * @param string $accessToken |
|
| 179 | + * @param string $type |
|
| 180 | + * @return array |
|
| 181 | + */ |
|
| 182 | + public function loginSocial($authCode, $accessToken, $type) |
|
| 183 | + { |
|
| 184 | + $access_token = $authCode ? Arr::get(\Socialite::driver($type)->getAccessTokenResponse($authCode), 'access_token') : $accessToken; |
|
| 185 | + $user = \Socialite::driver($type)->userFromToken($access_token); |
|
| 186 | + |
|
| 187 | + if (! $user->email) { |
|
| 188 | + \ErrorHandler::noSocialEmail(); |
|
| 189 | + } |
|
| 190 | + |
|
| 191 | + if (! $this->repo->first(['email' => $user->email])) { |
|
| 192 | + $this->register(['email' => $user->email, 'password' => ''], true); |
|
| 193 | + } |
|
| 194 | + |
|
| 195 | + return $this->loginProxy->login($user->email, config('skeleton.social_pass')); |
|
| 196 | + } |
|
| 197 | 197 | |
| 198 | - /** |
|
| 199 | - * Handle a registration request. |
|
| 200 | - * |
|
| 201 | - * @param string $name |
|
| 202 | - * @param string $email |
|
| 203 | - * @param string $password |
|
| 204 | - * @param boolean $skipConfirmEmail |
|
| 205 | - * @return array |
|
| 206 | - */ |
|
| 207 | - public function register($name, $email, $password, $skipConfirmEmail = false) |
|
| 208 | - { |
|
| 209 | - $user = $this->repo->save([ |
|
| 210 | - 'name' => $name, |
|
| 211 | - 'email' => $email, |
|
| 212 | - 'password' => $password, |
|
| 213 | - 'confirmed' => $skipConfirmEmail |
|
| 214 | - ]); |
|
| 215 | - |
|
| 216 | - if (! $skipConfirmEmail && ! config('skeleton.disable_confirm_email')) { |
|
| 217 | - $this->sendConfirmationEmail($user->email); |
|
| 218 | - } |
|
| 219 | - |
|
| 220 | - return $user; |
|
| 221 | - } |
|
| 198 | + /** |
|
| 199 | + * Handle a registration request. |
|
| 200 | + * |
|
| 201 | + * @param string $name |
|
| 202 | + * @param string $email |
|
| 203 | + * @param string $password |
|
| 204 | + * @param boolean $skipConfirmEmail |
|
| 205 | + * @return array |
|
| 206 | + */ |
|
| 207 | + public function register($name, $email, $password, $skipConfirmEmail = false) |
|
| 208 | + { |
|
| 209 | + $user = $this->repo->save([ |
|
| 210 | + 'name' => $name, |
|
| 211 | + 'email' => $email, |
|
| 212 | + 'password' => $password, |
|
| 213 | + 'confirmed' => $skipConfirmEmail |
|
| 214 | + ]); |
|
| 215 | + |
|
| 216 | + if (! $skipConfirmEmail && ! config('skeleton.disable_confirm_email')) { |
|
| 217 | + $this->sendConfirmationEmail($user->email); |
|
| 218 | + } |
|
| 219 | + |
|
| 220 | + return $user; |
|
| 221 | + } |
|
| 222 | 222 | |
| 223 | - /** |
|
| 224 | - * Block the user. |
|
| 225 | - * |
|
| 226 | - * @param integer $userId |
|
| 227 | - * @return object |
|
| 228 | - */ |
|
| 229 | - public function block($userId) |
|
| 230 | - { |
|
| 231 | - if (\Auth::id() == $userId || $this->hasRoles(['Admin'], $user) !== false) { |
|
| 232 | - \ErrorHandler::noPermissions(); |
|
| 233 | - } |
|
| 223 | + /** |
|
| 224 | + * Block the user. |
|
| 225 | + * |
|
| 226 | + * @param integer $userId |
|
| 227 | + * @return object |
|
| 228 | + */ |
|
| 229 | + public function block($userId) |
|
| 230 | + { |
|
| 231 | + if (\Auth::id() == $userId || $this->hasRoles(['Admin'], $user) !== false) { |
|
| 232 | + \ErrorHandler::noPermissions(); |
|
| 233 | + } |
|
| 234 | 234 | |
| 235 | - return $this->repo->save(['id' => $userId, 'blocked' => 1]); |
|
| 236 | - } |
|
| 237 | - |
|
| 238 | - /** |
|
| 239 | - * Unblock the user. |
|
| 240 | - * |
|
| 241 | - * @param integer $userId |
|
| 242 | - * @return object |
|
| 243 | - */ |
|
| 244 | - public function unblock($userId) |
|
| 245 | - { |
|
| 246 | - return $this->repo->save(['id' => $userId, 'blocked' => 0]); |
|
| 247 | - } |
|
| 248 | - |
|
| 249 | - /** |
|
| 250 | - * Send a reset link to the given user. |
|
| 251 | - * |
|
| 252 | - * @param string $email |
|
| 253 | - * @return void |
|
| 254 | - */ |
|
| 255 | - public function sendReset($email) |
|
| 256 | - { |
|
| 257 | - if (! $user = $this->repo->first(['email' => $email])) { |
|
| 258 | - \ErrorHandler::notFound('email'); |
|
| 259 | - } |
|
| 260 | - |
|
| 261 | - $token = \Password::getService()->create($user); |
|
| 262 | - $this->notificationService->notify($user, 'ResetPassword', $token); |
|
| 263 | - } |
|
| 264 | - |
|
| 265 | - /** |
|
| 266 | - * Reset the given user's password. |
|
| 267 | - * |
|
| 268 | - * @param string $email |
|
| 269 | - * @param string $password |
|
| 270 | - * @param string $passwordConfirmation |
|
| 271 | - * @param string $token |
|
| 272 | - * @return string|void |
|
| 273 | - */ |
|
| 274 | - public function resetPassword($email, $password, $passwordConfirmation, $token) |
|
| 275 | - { |
|
| 276 | - $response = \Password::reset([ |
|
| 277 | - 'email' => $email, |
|
| 278 | - 'password' => $password, |
|
| 279 | - 'password_confirmation' => $passwordConfirmation, |
|
| 280 | - 'token' => $token |
|
| 281 | - ], function ($user, $password) { |
|
| 282 | - $this->repo->save(['id' => $user->id, 'password' => $password]); |
|
| 283 | - }); |
|
| 284 | - |
|
| 285 | - switch ($response) { |
|
| 286 | - case \Password::PASSWORD_RESET: |
|
| 287 | - return 'success'; |
|
| 288 | - break; |
|
| 289 | - |
|
| 290 | - case \Password::INVALID_TOKEN: |
|
| 291 | - \ErrorHandler::invalidResetToken('token'); |
|
| 292 | - break; |
|
| 293 | - |
|
| 294 | - case \Password::INVALID_PASSWORD: |
|
| 295 | - \ErrorHandler::invalidResetPassword('email'); |
|
| 296 | - break; |
|
| 297 | - |
|
| 298 | - case \Password::INVALID_USER: |
|
| 299 | - \ErrorHandler::notFound('user'); |
|
| 300 | - break; |
|
| 301 | - |
|
| 302 | - default: |
|
| 303 | - \ErrorHandler::generalError(); |
|
| 304 | - break; |
|
| 305 | - } |
|
| 306 | - } |
|
| 307 | - |
|
| 308 | - /** |
|
| 309 | - * Change the logged in user password. |
|
| 310 | - * |
|
| 311 | - * @param string $password |
|
| 312 | - * @param string $oldPassword |
|
| 313 | - * @return void |
|
| 314 | - */ |
|
| 315 | - public function changePassword($password, $oldPassword) |
|
| 316 | - { |
|
| 317 | - $user = \Auth::user(); |
|
| 318 | - if (! \Hash::check($oldPassword, $user->password)) { |
|
| 319 | - \ErrorHandler::invalidOldPassword(); |
|
| 320 | - } |
|
| 321 | - |
|
| 322 | - $this->repo->save(['id' => $user->id, 'password' => $password]); |
|
| 323 | - } |
|
| 324 | - |
|
| 325 | - /** |
|
| 326 | - * Confirm email using the confirmation code. |
|
| 327 | - * |
|
| 328 | - * @param string $confirmationCode |
|
| 329 | - * @return void |
|
| 330 | - */ |
|
| 331 | - public function confirmEmail($confirmationCode) |
|
| 332 | - { |
|
| 333 | - if (! $user = $this->repo->first(['confirmation_code' => $confirmationCode])) { |
|
| 334 | - \ErrorHandler::invalidConfirmationCode(); |
|
| 335 | - } |
|
| 336 | - |
|
| 337 | - $this->repo->save(['id' => $user->id, 'confirmed' => 1, 'confirmation_code' => null]); |
|
| 338 | - } |
|
| 339 | - |
|
| 340 | - /** |
|
| 341 | - * Send the confirmation mail. |
|
| 342 | - * |
|
| 343 | - * @param string $email |
|
| 344 | - * @return void |
|
| 345 | - */ |
|
| 346 | - public function sendConfirmationEmail($email) |
|
| 347 | - { |
|
| 348 | - $user = $this->repo->first(['email' => $email]); |
|
| 349 | - if ($user->confirmed) { |
|
| 350 | - \ErrorHandler::emailAlreadyConfirmed(); |
|
| 351 | - } |
|
| 352 | - |
|
| 353 | - $this->repo->save(['id' => $user->id, 'confirmation_code' => sha1(microtime())]); |
|
| 354 | - $this->notificationService->notify($user, 'ConfirmEmail'); |
|
| 355 | - } |
|
| 356 | - |
|
| 357 | - /** |
|
| 358 | - * Save the given data to the logged in user. |
|
| 359 | - * |
|
| 360 | - * @param string $name |
|
| 361 | - * @param string $email |
|
| 362 | - * @param string $profilePicture |
|
| 363 | - * @return void |
|
| 364 | - */ |
|
| 365 | - public function saveProfile($name, $email, $profilePicture = false) |
|
| 366 | - { |
|
| 367 | - if ($profilePicture) { |
|
| 368 | - $data['profile_picture'] = $this->media->uploadImageBas64($profilePicture, 'admins/profile_pictures'); |
|
| 369 | - } |
|
| 235 | + return $this->repo->save(['id' => $userId, 'blocked' => 1]); |
|
| 236 | + } |
|
| 237 | + |
|
| 238 | + /** |
|
| 239 | + * Unblock the user. |
|
| 240 | + * |
|
| 241 | + * @param integer $userId |
|
| 242 | + * @return object |
|
| 243 | + */ |
|
| 244 | + public function unblock($userId) |
|
| 245 | + { |
|
| 246 | + return $this->repo->save(['id' => $userId, 'blocked' => 0]); |
|
| 247 | + } |
|
| 248 | + |
|
| 249 | + /** |
|
| 250 | + * Send a reset link to the given user. |
|
| 251 | + * |
|
| 252 | + * @param string $email |
|
| 253 | + * @return void |
|
| 254 | + */ |
|
| 255 | + public function sendReset($email) |
|
| 256 | + { |
|
| 257 | + if (! $user = $this->repo->first(['email' => $email])) { |
|
| 258 | + \ErrorHandler::notFound('email'); |
|
| 259 | + } |
|
| 260 | + |
|
| 261 | + $token = \Password::getService()->create($user); |
|
| 262 | + $this->notificationService->notify($user, 'ResetPassword', $token); |
|
| 263 | + } |
|
| 264 | + |
|
| 265 | + /** |
|
| 266 | + * Reset the given user's password. |
|
| 267 | + * |
|
| 268 | + * @param string $email |
|
| 269 | + * @param string $password |
|
| 270 | + * @param string $passwordConfirmation |
|
| 271 | + * @param string $token |
|
| 272 | + * @return string|void |
|
| 273 | + */ |
|
| 274 | + public function resetPassword($email, $password, $passwordConfirmation, $token) |
|
| 275 | + { |
|
| 276 | + $response = \Password::reset([ |
|
| 277 | + 'email' => $email, |
|
| 278 | + 'password' => $password, |
|
| 279 | + 'password_confirmation' => $passwordConfirmation, |
|
| 280 | + 'token' => $token |
|
| 281 | + ], function ($user, $password) { |
|
| 282 | + $this->repo->save(['id' => $user->id, 'password' => $password]); |
|
| 283 | + }); |
|
| 284 | + |
|
| 285 | + switch ($response) { |
|
| 286 | + case \Password::PASSWORD_RESET: |
|
| 287 | + return 'success'; |
|
| 288 | + break; |
|
| 289 | + |
|
| 290 | + case \Password::INVALID_TOKEN: |
|
| 291 | + \ErrorHandler::invalidResetToken('token'); |
|
| 292 | + break; |
|
| 293 | + |
|
| 294 | + case \Password::INVALID_PASSWORD: |
|
| 295 | + \ErrorHandler::invalidResetPassword('email'); |
|
| 296 | + break; |
|
| 297 | + |
|
| 298 | + case \Password::INVALID_USER: |
|
| 299 | + \ErrorHandler::notFound('user'); |
|
| 300 | + break; |
|
| 301 | + |
|
| 302 | + default: |
|
| 303 | + \ErrorHandler::generalError(); |
|
| 304 | + break; |
|
| 305 | + } |
|
| 306 | + } |
|
| 307 | + |
|
| 308 | + /** |
|
| 309 | + * Change the logged in user password. |
|
| 310 | + * |
|
| 311 | + * @param string $password |
|
| 312 | + * @param string $oldPassword |
|
| 313 | + * @return void |
|
| 314 | + */ |
|
| 315 | + public function changePassword($password, $oldPassword) |
|
| 316 | + { |
|
| 317 | + $user = \Auth::user(); |
|
| 318 | + if (! \Hash::check($oldPassword, $user->password)) { |
|
| 319 | + \ErrorHandler::invalidOldPassword(); |
|
| 320 | + } |
|
| 321 | + |
|
| 322 | + $this->repo->save(['id' => $user->id, 'password' => $password]); |
|
| 323 | + } |
|
| 324 | + |
|
| 325 | + /** |
|
| 326 | + * Confirm email using the confirmation code. |
|
| 327 | + * |
|
| 328 | + * @param string $confirmationCode |
|
| 329 | + * @return void |
|
| 330 | + */ |
|
| 331 | + public function confirmEmail($confirmationCode) |
|
| 332 | + { |
|
| 333 | + if (! $user = $this->repo->first(['confirmation_code' => $confirmationCode])) { |
|
| 334 | + \ErrorHandler::invalidConfirmationCode(); |
|
| 335 | + } |
|
| 336 | + |
|
| 337 | + $this->repo->save(['id' => $user->id, 'confirmed' => 1, 'confirmation_code' => null]); |
|
| 338 | + } |
|
| 339 | + |
|
| 340 | + /** |
|
| 341 | + * Send the confirmation mail. |
|
| 342 | + * |
|
| 343 | + * @param string $email |
|
| 344 | + * @return void |
|
| 345 | + */ |
|
| 346 | + public function sendConfirmationEmail($email) |
|
| 347 | + { |
|
| 348 | + $user = $this->repo->first(['email' => $email]); |
|
| 349 | + if ($user->confirmed) { |
|
| 350 | + \ErrorHandler::emailAlreadyConfirmed(); |
|
| 351 | + } |
|
| 352 | + |
|
| 353 | + $this->repo->save(['id' => $user->id, 'confirmation_code' => sha1(microtime())]); |
|
| 354 | + $this->notificationService->notify($user, 'ConfirmEmail'); |
|
| 355 | + } |
|
| 356 | + |
|
| 357 | + /** |
|
| 358 | + * Save the given data to the logged in user. |
|
| 359 | + * |
|
| 360 | + * @param string $name |
|
| 361 | + * @param string $email |
|
| 362 | + * @param string $profilePicture |
|
| 363 | + * @return void |
|
| 364 | + */ |
|
| 365 | + public function saveProfile($name, $email, $profilePicture = false) |
|
| 366 | + { |
|
| 367 | + if ($profilePicture) { |
|
| 368 | + $data['profile_picture'] = $this->media->uploadImageBas64($profilePicture, 'admins/profile_pictures'); |
|
| 369 | + } |
|
| 370 | 370 | |
| 371 | - $data['id'] = \Auth::id(); |
|
| 372 | - return $this->repo->save([ |
|
| 373 | - 'id' => \Auth::id(), |
|
| 374 | - 'name' => $name, |
|
| 375 | - 'email' => $email, |
|
| 376 | - 'profilePicture' => $profilePicture, |
|
| 377 | - ]); |
|
| 378 | - } |
|
| 379 | - |
|
| 380 | - /** |
|
| 381 | - * Logs out the user, revoke access token and refresh token. |
|
| 382 | - * |
|
| 383 | - * @return void |
|
| 384 | - */ |
|
| 385 | - public function logout() |
|
| 386 | - { |
|
| 387 | - $this->oauthClientService->revokeAccessToken(\Auth::user()->token()); |
|
| 388 | - } |
|
| 389 | - |
|
| 390 | - /** |
|
| 391 | - * Attempt to refresh the access token using the given refresh token. |
|
| 392 | - * |
|
| 393 | - * @param string $refreshToken |
|
| 394 | - * @return array |
|
| 395 | - */ |
|
| 396 | - public function refreshToken($refreshToken) |
|
| 397 | - { |
|
| 398 | - return $this->loginProxy->refreshToken($refreshToken); |
|
| 399 | - } |
|
| 371 | + $data['id'] = \Auth::id(); |
|
| 372 | + return $this->repo->save([ |
|
| 373 | + 'id' => \Auth::id(), |
|
| 374 | + 'name' => $name, |
|
| 375 | + 'email' => $email, |
|
| 376 | + 'profilePicture' => $profilePicture, |
|
| 377 | + ]); |
|
| 378 | + } |
|
| 379 | + |
|
| 380 | + /** |
|
| 381 | + * Logs out the user, revoke access token and refresh token. |
|
| 382 | + * |
|
| 383 | + * @return void |
|
| 384 | + */ |
|
| 385 | + public function logout() |
|
| 386 | + { |
|
| 387 | + $this->oauthClientService->revokeAccessToken(\Auth::user()->token()); |
|
| 388 | + } |
|
| 389 | + |
|
| 390 | + /** |
|
| 391 | + * Attempt to refresh the access token using the given refresh token. |
|
| 392 | + * |
|
| 393 | + * @param string $refreshToken |
|
| 394 | + * @return array |
|
| 395 | + */ |
|
| 396 | + public function refreshToken($refreshToken) |
|
| 397 | + { |
|
| 398 | + return $this->loginProxy->refreshToken($refreshToken); |
|
| 399 | + } |
|
| 400 | 400 | } |
@@ -74,7 +74,7 @@ discard block |
||
| 74 | 74 | $permissions = []; |
| 75 | 75 | $user = $this->repo->find(\Auth::id(), $relations); |
| 76 | 76 | foreach ($user->roles as $role) { |
| 77 | - $role->permissions->each(function ($permission) use (&$permissions) { |
|
| 77 | + $role->permissions->each(function($permission) use (&$permissions) { |
|
| 78 | 78 | $permissions[$permission->repo][$permission->id] = $permission->name; |
| 79 | 79 | }); |
| 80 | 80 | } |
@@ -137,7 +137,7 @@ discard block |
||
| 137 | 137 | public function assignRoles($userId, $roleIds) |
| 138 | 138 | { |
| 139 | 139 | $user = false; |
| 140 | - \DB::transaction(function () use ($userId, $permissionIds, &$user) { |
|
| 140 | + \DB::transaction(function() use ($userId, $permissionIds, &$user) { |
|
| 141 | 141 | $user = $this->repo->find($userId); |
| 142 | 142 | $this->repo->detachPermissions($userId); |
| 143 | 143 | $this->repo->attachPermissions($userId, $roleIds); |
@@ -156,15 +156,15 @@ discard block |
||
| 156 | 156 | */ |
| 157 | 157 | public function login($email, $password, $adminLogin = false) |
| 158 | 158 | { |
| 159 | - if (! $user = $this->repo->first(['email' => $email])) { |
|
| 159 | + if ( ! $user = $this->repo->first(['email' => $email])) { |
|
| 160 | 160 | \ErrorHandler::loginFailed(); |
| 161 | 161 | } elseif ($adminLogin && ! $this->hasRoles(['Admin'], $user)) { |
| 162 | 162 | \ErrorHandler::loginFailed(); |
| 163 | - } elseif (! $adminLogin && $this->hasRoles(['Admin'], $user)) { |
|
| 163 | + } elseif ( ! $adminLogin && $this->hasRoles(['Admin'], $user)) { |
|
| 164 | 164 | \ErrorHandler::loginFailed(); |
| 165 | 165 | } elseif ($user->blocked) { |
| 166 | 166 | \ErrorHandler::userIsBlocked(); |
| 167 | - } elseif (! config('skeleton.disable_confirm_email') && ! $user->confirmed) { |
|
| 167 | + } elseif ( ! config('skeleton.disable_confirm_email') && ! $user->confirmed) { |
|
| 168 | 168 | \ErrorHandler::emailNotConfirmed(); |
| 169 | 169 | } |
| 170 | 170 | |
@@ -184,11 +184,11 @@ discard block |
||
| 184 | 184 | $access_token = $authCode ? Arr::get(\Socialite::driver($type)->getAccessTokenResponse($authCode), 'access_token') : $accessToken; |
| 185 | 185 | $user = \Socialite::driver($type)->userFromToken($access_token); |
| 186 | 186 | |
| 187 | - if (! $user->email) { |
|
| 187 | + if ( ! $user->email) { |
|
| 188 | 188 | \ErrorHandler::noSocialEmail(); |
| 189 | 189 | } |
| 190 | 190 | |
| 191 | - if (! $this->repo->first(['email' => $user->email])) { |
|
| 191 | + if ( ! $this->repo->first(['email' => $user->email])) { |
|
| 192 | 192 | $this->register(['email' => $user->email, 'password' => ''], true); |
| 193 | 193 | } |
| 194 | 194 | |
@@ -213,7 +213,7 @@ discard block |
||
| 213 | 213 | 'confirmed' => $skipConfirmEmail |
| 214 | 214 | ]); |
| 215 | 215 | |
| 216 | - if (! $skipConfirmEmail && ! config('skeleton.disable_confirm_email')) { |
|
| 216 | + if ( ! $skipConfirmEmail && ! config('skeleton.disable_confirm_email')) { |
|
| 217 | 217 | $this->sendConfirmationEmail($user->email); |
| 218 | 218 | } |
| 219 | 219 | |
@@ -254,7 +254,7 @@ discard block |
||
| 254 | 254 | */ |
| 255 | 255 | public function sendReset($email) |
| 256 | 256 | { |
| 257 | - if (! $user = $this->repo->first(['email' => $email])) { |
|
| 257 | + if ( ! $user = $this->repo->first(['email' => $email])) { |
|
| 258 | 258 | \ErrorHandler::notFound('email'); |
| 259 | 259 | } |
| 260 | 260 | |
@@ -278,7 +278,7 @@ discard block |
||
| 278 | 278 | 'password' => $password, |
| 279 | 279 | 'password_confirmation' => $passwordConfirmation, |
| 280 | 280 | 'token' => $token |
| 281 | - ], function ($user, $password) { |
|
| 281 | + ], function($user, $password) { |
|
| 282 | 282 | $this->repo->save(['id' => $user->id, 'password' => $password]); |
| 283 | 283 | }); |
| 284 | 284 | |
@@ -315,7 +315,7 @@ discard block |
||
| 315 | 315 | public function changePassword($password, $oldPassword) |
| 316 | 316 | { |
| 317 | 317 | $user = \Auth::user(); |
| 318 | - if (! \Hash::check($oldPassword, $user->password)) { |
|
| 318 | + if ( ! \Hash::check($oldPassword, $user->password)) { |
|
| 319 | 319 | \ErrorHandler::invalidOldPassword(); |
| 320 | 320 | } |
| 321 | 321 | |
@@ -330,7 +330,7 @@ discard block |
||
| 330 | 330 | */ |
| 331 | 331 | public function confirmEmail($confirmationCode) |
| 332 | 332 | { |
| 333 | - if (! $user = $this->repo->first(['confirmation_code' => $confirmationCode])) { |
|
| 333 | + if ( ! $user = $this->repo->first(['confirmation_code' => $confirmationCode])) { |
|
| 334 | 334 | \ErrorHandler::invalidConfirmationCode(); |
| 335 | 335 | } |
| 336 | 336 | |
@@ -6,62 +6,62 @@ |
||
| 6 | 6 | class AclUserObserver |
| 7 | 7 | { |
| 8 | 8 | |
| 9 | - public function saving($model) |
|
| 10 | - { |
|
| 11 | - if ($model->isDirty('profile_picture')) { |
|
| 12 | - \Media::deleteImage($model->getOriginal('profile_picture')); |
|
| 13 | - } |
|
| 14 | - } |
|
| 9 | + public function saving($model) |
|
| 10 | + { |
|
| 11 | + if ($model->isDirty('profile_picture')) { |
|
| 12 | + \Media::deleteImage($model->getOriginal('profile_picture')); |
|
| 13 | + } |
|
| 14 | + } |
|
| 15 | 15 | |
| 16 | - public function saved($model) |
|
| 17 | - { |
|
| 18 | - // |
|
| 19 | - } |
|
| 16 | + public function saved($model) |
|
| 17 | + { |
|
| 18 | + // |
|
| 19 | + } |
|
| 20 | 20 | |
| 21 | - public function creating($model) |
|
| 22 | - { |
|
| 23 | - // |
|
| 24 | - } |
|
| 21 | + public function creating($model) |
|
| 22 | + { |
|
| 23 | + // |
|
| 24 | + } |
|
| 25 | 25 | |
| 26 | - public function created($model) |
|
| 27 | - { |
|
| 28 | - // |
|
| 29 | - } |
|
| 26 | + public function created($model) |
|
| 27 | + { |
|
| 28 | + // |
|
| 29 | + } |
|
| 30 | 30 | |
| 31 | - public function updating($model) |
|
| 32 | - { |
|
| 33 | - // |
|
| 34 | - } |
|
| 31 | + public function updating($model) |
|
| 32 | + { |
|
| 33 | + // |
|
| 34 | + } |
|
| 35 | 35 | |
| 36 | - public function updated($model) |
|
| 37 | - { |
|
| 38 | - if ($model->isDirty('blocked') && $model->blocked) { |
|
| 39 | - $model->tokens()->each(function ($token) { |
|
| 36 | + public function updated($model) |
|
| 37 | + { |
|
| 38 | + if ($model->isDirty('blocked') && $model->blocked) { |
|
| 39 | + $model->tokens()->each(function ($token) { |
|
| 40 | 40 | |
| 41 | - \Core::oauthClients()->revokeAccessToken($token); |
|
| 42 | - }); |
|
| 43 | - } |
|
| 44 | - } |
|
| 41 | + \Core::oauthClients()->revokeAccessToken($token); |
|
| 42 | + }); |
|
| 43 | + } |
|
| 44 | + } |
|
| 45 | 45 | |
| 46 | - public function deleting($model) |
|
| 47 | - { |
|
| 48 | - if ($model->getOriginal('id') == \Auth::id()) { |
|
| 49 | - \ErrorHandler::noPermissions(); |
|
| 50 | - } |
|
| 51 | - } |
|
| 46 | + public function deleting($model) |
|
| 47 | + { |
|
| 48 | + if ($model->getOriginal('id') == \Auth::id()) { |
|
| 49 | + \ErrorHandler::noPermissions(); |
|
| 50 | + } |
|
| 51 | + } |
|
| 52 | 52 | |
| 53 | - public function deleted($model) |
|
| 54 | - { |
|
| 55 | - // |
|
| 56 | - } |
|
| 53 | + public function deleted($model) |
|
| 54 | + { |
|
| 55 | + // |
|
| 56 | + } |
|
| 57 | 57 | |
| 58 | - public function restoring($model) |
|
| 59 | - { |
|
| 60 | - // |
|
| 61 | - } |
|
| 58 | + public function restoring($model) |
|
| 59 | + { |
|
| 60 | + // |
|
| 61 | + } |
|
| 62 | 62 | |
| 63 | - public function restored($model) |
|
| 64 | - { |
|
| 65 | - // |
|
| 66 | - } |
|
| 63 | + public function restored($model) |
|
| 64 | + { |
|
| 65 | + // |
|
| 66 | + } |
|
| 67 | 67 | } |
@@ -36,7 +36,7 @@ |
||
| 36 | 36 | public function updated($model) |
| 37 | 37 | { |
| 38 | 38 | if ($model->isDirty('blocked') && $model->blocked) { |
| 39 | - $model->tokens()->each(function ($token) { |
|
| 39 | + $model->tokens()->each(function($token) { |
|
| 40 | 40 | |
| 41 | 41 | \Core::oauthClients()->revokeAccessToken($token); |
| 42 | 42 | }); |
@@ -15,30 +15,30 @@ |
||
| 15 | 15 | |
| 16 | 16 | Route::group(['prefix' => 'users'], function () { |
| 17 | 17 | |
| 18 | - Route::get('/', 'UserController@index'); |
|
| 19 | - Route::get('/{id}', 'UserController@find'); |
|
| 20 | - Route::post('/', 'UserController@insert'); |
|
| 21 | - Route::put('/', 'UserController@update'); |
|
| 22 | - Route::delete('/{id}', 'UserController@delete'); |
|
| 23 | - Route::get('list/deleted', 'UserController@deleted'); |
|
| 24 | - Route::patch('restore/{id}', 'UserController@restore'); |
|
| 25 | - Route::get('block/{id}', 'UserController@block'); |
|
| 26 | - Route::get('unblock/{id}', 'UserController@unblock'); |
|
| 27 | - Route::post('assign/roles', 'UserController@assignRoles'); |
|
| 18 | + Route::get('/', 'UserController@index'); |
|
| 19 | + Route::get('/{id}', 'UserController@find'); |
|
| 20 | + Route::post('/', 'UserController@insert'); |
|
| 21 | + Route::put('/', 'UserController@update'); |
|
| 22 | + Route::delete('/{id}', 'UserController@delete'); |
|
| 23 | + Route::get('list/deleted', 'UserController@deleted'); |
|
| 24 | + Route::patch('restore/{id}', 'UserController@restore'); |
|
| 25 | + Route::get('block/{id}', 'UserController@block'); |
|
| 26 | + Route::get('unblock/{id}', 'UserController@unblock'); |
|
| 27 | + Route::post('assign/roles', 'UserController@assignRoles'); |
|
| 28 | 28 | |
| 29 | - Route::group(['prefix' => 'account'], function () { |
|
| 29 | + Route::group(['prefix' => 'account'], function () { |
|
| 30 | 30 | |
| 31 | - Route::get('my', 'UserController@account'); |
|
| 32 | - Route::get('logout', 'UserController@logout'); |
|
| 33 | - Route::post('refresh/token', 'UserController@refreshToken'); |
|
| 34 | - Route::post('save', 'UserController@saveProfile'); |
|
| 35 | - Route::post('register', 'UserController@register'); |
|
| 36 | - Route::post('login', 'UserController@login'); |
|
| 37 | - Route::post('login/social', 'UserController@loginSocial'); |
|
| 38 | - Route::post('send/reset', 'UserController@sendReset'); |
|
| 39 | - Route::post('reset/password', 'UserController@resetPassword'); |
|
| 40 | - Route::post('change/password', 'UserController@changePassword'); |
|
| 41 | - Route::post('confirm/email', 'UserController@confirmEmail'); |
|
| 42 | - Route::post('resend/email/confirmation', 'UserController@resendEmailConfirmation'); |
|
| 43 | - }); |
|
| 31 | + Route::get('my', 'UserController@account'); |
|
| 32 | + Route::get('logout', 'UserController@logout'); |
|
| 33 | + Route::post('refresh/token', 'UserController@refreshToken'); |
|
| 34 | + Route::post('save', 'UserController@saveProfile'); |
|
| 35 | + Route::post('register', 'UserController@register'); |
|
| 36 | + Route::post('login', 'UserController@login'); |
|
| 37 | + Route::post('login/social', 'UserController@loginSocial'); |
|
| 38 | + Route::post('send/reset', 'UserController@sendReset'); |
|
| 39 | + Route::post('reset/password', 'UserController@resetPassword'); |
|
| 40 | + Route::post('change/password', 'UserController@changePassword'); |
|
| 41 | + Route::post('confirm/email', 'UserController@confirmEmail'); |
|
| 42 | + Route::post('resend/email/confirmation', 'UserController@resendEmailConfirmation'); |
|
| 43 | + }); |
|
| 44 | 44 | }); |
@@ -13,7 +13,7 @@ discard block |
||
| 13 | 13 | | |
| 14 | 14 | */ |
| 15 | 15 | |
| 16 | -Route::group(['prefix' => 'users'], function () { |
|
| 16 | +Route::group(['prefix' => 'users'], function() { |
|
| 17 | 17 | |
| 18 | 18 | Route::get('/', 'UserController@index'); |
| 19 | 19 | Route::get('/{id}', 'UserController@find'); |
@@ -26,7 +26,7 @@ discard block |
||
| 26 | 26 | Route::get('unblock/{id}', 'UserController@unblock'); |
| 27 | 27 | Route::post('assign/roles', 'UserController@assignRoles'); |
| 28 | 28 | |
| 29 | - Route::group(['prefix' => 'account'], function () { |
|
| 29 | + Route::group(['prefix' => 'account'], function() { |
|
| 30 | 30 | |
| 31 | 31 | Route::get('my', 'UserController@account'); |
| 32 | 32 | Route::get('logout', 'UserController@logout'); |
@@ -8,105 +8,105 @@ |
||
| 8 | 8 | |
| 9 | 9 | class UsersTableSeeder extends Seeder |
| 10 | 10 | { |
| 11 | - /** |
|
| 12 | - * Run the database seeds. |
|
| 13 | - * |
|
| 14 | - * @return void |
|
| 15 | - */ |
|
| 16 | - public function run() |
|
| 17 | - { |
|
| 18 | - /** |
|
| 19 | - * Create Default roles. |
|
| 20 | - */ |
|
| 21 | - $role = Role::updateOrInsert([ |
|
| 22 | - 'name' => 'Admin', |
|
| 23 | - ],[ |
|
| 24 | - 'created_at' => \DB::raw('NOW()'), |
|
| 25 | - 'updated_at' => \DB::raw('NOW()') |
|
| 26 | - ]); |
|
| 11 | + /** |
|
| 12 | + * Run the database seeds. |
|
| 13 | + * |
|
| 14 | + * @return void |
|
| 15 | + */ |
|
| 16 | + public function run() |
|
| 17 | + { |
|
| 18 | + /** |
|
| 19 | + * Create Default roles. |
|
| 20 | + */ |
|
| 21 | + $role = Role::updateOrInsert([ |
|
| 22 | + 'name' => 'Admin', |
|
| 23 | + ],[ |
|
| 24 | + 'created_at' => \DB::raw('NOW()'), |
|
| 25 | + 'updated_at' => \DB::raw('NOW()') |
|
| 26 | + ]); |
|
| 27 | 27 | |
| 28 | - /** |
|
| 29 | - * Create Default user. |
|
| 30 | - */ |
|
| 31 | - AclUser::updateOrInsert([ |
|
| 32 | - 'email' => '[email protected]', |
|
| 33 | - ],[ |
|
| 34 | - 'name' => 'Admin', |
|
| 35 | - 'password' => \Hash::make('123456'), |
|
| 36 | - 'confirmed' => 1, |
|
| 37 | - 'created_at' => \DB::raw('NOW()'), |
|
| 38 | - 'updated_at' => \DB::raw('NOW()') |
|
| 39 | - ]); |
|
| 28 | + /** |
|
| 29 | + * Create Default user. |
|
| 30 | + */ |
|
| 31 | + AclUser::updateOrInsert([ |
|
| 32 | + 'email' => '[email protected]', |
|
| 33 | + ],[ |
|
| 34 | + 'name' => 'Admin', |
|
| 35 | + 'password' => \Hash::make('123456'), |
|
| 36 | + 'confirmed' => 1, |
|
| 37 | + 'created_at' => \DB::raw('NOW()'), |
|
| 38 | + 'updated_at' => \DB::raw('NOW()') |
|
| 39 | + ]); |
|
| 40 | 40 | |
| 41 | - /** |
|
| 42 | - * Insert the permissions related to users table. |
|
| 43 | - */ |
|
| 44 | - \DB::table('permissions')->insert( |
|
| 45 | - [ |
|
| 46 | - /** |
|
| 47 | - * Users model permissions. |
|
| 48 | - */ |
|
| 49 | - [ |
|
| 50 | - 'name' => 'index', |
|
| 51 | - 'model' => 'user', |
|
| 52 | - 'created_at' => \DB::raw('NOW()'), |
|
| 53 | - 'updated_at' => \DB::raw('NOW()') |
|
| 54 | - ], |
|
| 55 | - [ |
|
| 56 | - 'name' => 'find', |
|
| 57 | - 'model' => 'user', |
|
| 58 | - 'created_at' => \DB::raw('NOW()'), |
|
| 59 | - 'updated_at' => \DB::raw('NOW()') |
|
| 60 | - ], |
|
| 61 | - [ |
|
| 62 | - 'name' => 'insert', |
|
| 63 | - 'model' => 'user', |
|
| 64 | - 'created_at' => \DB::raw('NOW()'), |
|
| 65 | - 'updated_at' => \DB::raw('NOW()') |
|
| 66 | - ], |
|
| 67 | - [ |
|
| 68 | - 'name' => 'update', |
|
| 69 | - 'model' => 'user', |
|
| 70 | - 'created_at' => \DB::raw('NOW()'), |
|
| 71 | - 'updated_at' => \DB::raw('NOW()') |
|
| 72 | - ], |
|
| 73 | - [ |
|
| 74 | - 'name' => 'delete', |
|
| 75 | - 'model' => 'user', |
|
| 76 | - 'created_at' => \DB::raw('NOW()'), |
|
| 77 | - 'updated_at' => \DB::raw('NOW()') |
|
| 78 | - ], |
|
| 79 | - [ |
|
| 80 | - 'name' => 'deleted', |
|
| 81 | - 'model' => 'user', |
|
| 82 | - 'created_at' => \DB::raw('NOW()'), |
|
| 83 | - 'updated_at' => \DB::raw('NOW()') |
|
| 84 | - ], |
|
| 85 | - [ |
|
| 86 | - 'name' => 'restore', |
|
| 87 | - 'model' => 'user', |
|
| 88 | - 'created_at' => \DB::raw('NOW()'), |
|
| 89 | - 'updated_at' => \DB::raw('NOW()') |
|
| 90 | - ], |
|
| 91 | - [ |
|
| 92 | - 'name' => 'assignRoles', |
|
| 93 | - 'model' => 'user', |
|
| 94 | - 'created_at' => \DB::raw('NOW()'), |
|
| 95 | - 'updated_at' => \DB::raw('NOW()') |
|
| 96 | - ], |
|
| 97 | - [ |
|
| 98 | - 'name' => 'block', |
|
| 99 | - 'model' => 'user', |
|
| 100 | - 'created_at' => \DB::raw('NOW()'), |
|
| 101 | - 'updated_at' => \DB::raw('NOW()') |
|
| 102 | - ], |
|
| 103 | - [ |
|
| 104 | - 'name' => 'unblock', |
|
| 105 | - 'model' => 'user', |
|
| 106 | - 'created_at' => \DB::raw('NOW()'), |
|
| 107 | - 'updated_at' => \DB::raw('NOW()') |
|
| 108 | - ] |
|
| 109 | - ] |
|
| 110 | - ); |
|
| 111 | - } |
|
| 41 | + /** |
|
| 42 | + * Insert the permissions related to users table. |
|
| 43 | + */ |
|
| 44 | + \DB::table('permissions')->insert( |
|
| 45 | + [ |
|
| 46 | + /** |
|
| 47 | + * Users model permissions. |
|
| 48 | + */ |
|
| 49 | + [ |
|
| 50 | + 'name' => 'index', |
|
| 51 | + 'model' => 'user', |
|
| 52 | + 'created_at' => \DB::raw('NOW()'), |
|
| 53 | + 'updated_at' => \DB::raw('NOW()') |
|
| 54 | + ], |
|
| 55 | + [ |
|
| 56 | + 'name' => 'find', |
|
| 57 | + 'model' => 'user', |
|
| 58 | + 'created_at' => \DB::raw('NOW()'), |
|
| 59 | + 'updated_at' => \DB::raw('NOW()') |
|
| 60 | + ], |
|
| 61 | + [ |
|
| 62 | + 'name' => 'insert', |
|
| 63 | + 'model' => 'user', |
|
| 64 | + 'created_at' => \DB::raw('NOW()'), |
|
| 65 | + 'updated_at' => \DB::raw('NOW()') |
|
| 66 | + ], |
|
| 67 | + [ |
|
| 68 | + 'name' => 'update', |
|
| 69 | + 'model' => 'user', |
|
| 70 | + 'created_at' => \DB::raw('NOW()'), |
|
| 71 | + 'updated_at' => \DB::raw('NOW()') |
|
| 72 | + ], |
|
| 73 | + [ |
|
| 74 | + 'name' => 'delete', |
|
| 75 | + 'model' => 'user', |
|
| 76 | + 'created_at' => \DB::raw('NOW()'), |
|
| 77 | + 'updated_at' => \DB::raw('NOW()') |
|
| 78 | + ], |
|
| 79 | + [ |
|
| 80 | + 'name' => 'deleted', |
|
| 81 | + 'model' => 'user', |
|
| 82 | + 'created_at' => \DB::raw('NOW()'), |
|
| 83 | + 'updated_at' => \DB::raw('NOW()') |
|
| 84 | + ], |
|
| 85 | + [ |
|
| 86 | + 'name' => 'restore', |
|
| 87 | + 'model' => 'user', |
|
| 88 | + 'created_at' => \DB::raw('NOW()'), |
|
| 89 | + 'updated_at' => \DB::raw('NOW()') |
|
| 90 | + ], |
|
| 91 | + [ |
|
| 92 | + 'name' => 'assignRoles', |
|
| 93 | + 'model' => 'user', |
|
| 94 | + 'created_at' => \DB::raw('NOW()'), |
|
| 95 | + 'updated_at' => \DB::raw('NOW()') |
|
| 96 | + ], |
|
| 97 | + [ |
|
| 98 | + 'name' => 'block', |
|
| 99 | + 'model' => 'user', |
|
| 100 | + 'created_at' => \DB::raw('NOW()'), |
|
| 101 | + 'updated_at' => \DB::raw('NOW()') |
|
| 102 | + ], |
|
| 103 | + [ |
|
| 104 | + 'name' => 'unblock', |
|
| 105 | + 'model' => 'user', |
|
| 106 | + 'created_at' => \DB::raw('NOW()'), |
|
| 107 | + 'updated_at' => \DB::raw('NOW()') |
|
| 108 | + ] |
|
| 109 | + ] |
|
| 110 | + ); |
|
| 111 | + } |
|
| 112 | 112 | } |
@@ -20,7 +20,7 @@ discard block |
||
| 20 | 20 | */ |
| 21 | 21 | $role = Role::updateOrInsert([ |
| 22 | 22 | 'name' => 'Admin', |
| 23 | - ],[ |
|
| 23 | + ], [ |
|
| 24 | 24 | 'created_at' => \DB::raw('NOW()'), |
| 25 | 25 | 'updated_at' => \DB::raw('NOW()') |
| 26 | 26 | ]); |
@@ -30,7 +30,7 @@ discard block |
||
| 30 | 30 | */ |
| 31 | 31 | AclUser::updateOrInsert([ |
| 32 | 32 | 'email' => '[email protected]', |
| 33 | - ],[ |
|
| 33 | + ], [ |
|
| 34 | 34 | 'name' => 'Admin', |
| 35 | 35 | 'password' => \Hash::make('123456'), |
| 36 | 36 | 'confirmed' => 1, |