@@ -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 | } |
@@ -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 | } |
@@ -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 | } |
@@ -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 | } |
@@ -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 | }); |
@@ -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 | } |
@@ -6,27 +6,27 @@ |
||
| 6 | 6 | |
| 7 | 7 | class AssignRelationsSeeder extends Seeder |
| 8 | 8 | { |
| 9 | - /** |
|
| 10 | - * Run the database seeds. |
|
| 11 | - * |
|
| 12 | - * @return void |
|
| 13 | - */ |
|
| 14 | - public function run() |
|
| 15 | - { |
|
| 16 | - $adminRoleId = \DB::table('roles')->where('name', 'admin')->select('id')->first()->id; |
|
| 9 | + /** |
|
| 10 | + * Run the database seeds. |
|
| 11 | + * |
|
| 12 | + * @return void |
|
| 13 | + */ |
|
| 14 | + public function run() |
|
| 15 | + { |
|
| 16 | + $adminRoleId = \DB::table('roles')->where('name', 'admin')->select('id')->first()->id; |
|
| 17 | 17 | |
| 18 | - /** |
|
| 19 | - * Assign the permissions to the admin role. |
|
| 20 | - */ |
|
| 21 | - \DB::table('permissions')->orderBy('created_at', 'asc')->whereIn('model', ['user'])->each(function ($permission) use ($adminRoleId) { |
|
| 22 | - \DB::table('permission_role')->insert( |
|
| 23 | - [ |
|
| 24 | - 'permission_id' => $permission->id, |
|
| 25 | - 'role_id' => $adminRoleId, |
|
| 26 | - 'created_at' => \DB::raw('NOW()'), |
|
| 27 | - 'updated_at' => \DB::raw('NOW()') |
|
| 28 | - ] |
|
| 29 | - ); |
|
| 30 | - }); |
|
| 31 | - } |
|
| 18 | + /** |
|
| 19 | + * Assign the permissions to the admin role. |
|
| 20 | + */ |
|
| 21 | + \DB::table('permissions')->orderBy('created_at', 'asc')->whereIn('model', ['user'])->each(function ($permission) use ($adminRoleId) { |
|
| 22 | + \DB::table('permission_role')->insert( |
|
| 23 | + [ |
|
| 24 | + 'permission_id' => $permission->id, |
|
| 25 | + 'role_id' => $adminRoleId, |
|
| 26 | + 'created_at' => \DB::raw('NOW()'), |
|
| 27 | + 'updated_at' => \DB::raw('NOW()') |
|
| 28 | + ] |
|
| 29 | + ); |
|
| 30 | + }); |
|
| 31 | + } |
|
| 32 | 32 | } |
@@ -6,15 +6,15 @@ |
||
| 6 | 6 | |
| 7 | 7 | class ClearDataSeeder extends Seeder |
| 8 | 8 | { |
| 9 | - /** |
|
| 10 | - * Run the database seeds. |
|
| 11 | - * |
|
| 12 | - * @return void |
|
| 13 | - */ |
|
| 14 | - public function run() |
|
| 15 | - { |
|
| 16 | - $permissions = \DB::table('permissions')->whereIn('model', ['user']); |
|
| 17 | - \DB::table('permission_role')->whereIn('permission_id', $permissions->pluck('id'))->delete(); |
|
| 18 | - $permissions->delete(); |
|
| 19 | - } |
|
| 9 | + /** |
|
| 10 | + * Run the database seeds. |
|
| 11 | + * |
|
| 12 | + * @return void |
|
| 13 | + */ |
|
| 14 | + public function run() |
|
| 15 | + { |
|
| 16 | + $permissions = \DB::table('permissions')->whereIn('model', ['user']); |
|
| 17 | + \DB::table('permission_role')->whereIn('permission_id', $permissions->pluck('id'))->delete(); |
|
| 18 | + $permissions->delete(); |
|
| 19 | + } |
|
| 20 | 20 | } |
@@ -10,133 +10,133 @@ |
||
| 10 | 10 | class AclUser extends User |
| 11 | 11 | { |
| 12 | 12 | |
| 13 | - use SoftDeletes, HasApiTokens; |
|
| 14 | - protected $table = 'users'; |
|
| 15 | - protected $dates = ['created_at', 'updated_at', 'deleted_at']; |
|
| 16 | - protected $hidden = ['password', 'remember_token', 'deleted_at']; |
|
| 17 | - protected $guarded = ['id']; |
|
| 18 | - protected $fillable = ['profile_picture', 'name', 'email', 'password', 'locale', 'timezone']; |
|
| 19 | - public $searchable = ['name', 'email']; |
|
| 13 | + use SoftDeletes, HasApiTokens; |
|
| 14 | + protected $table = 'users'; |
|
| 15 | + protected $dates = ['created_at', 'updated_at', 'deleted_at']; |
|
| 16 | + protected $hidden = ['password', 'remember_token', 'deleted_at']; |
|
| 17 | + protected $guarded = ['id']; |
|
| 18 | + protected $fillable = ['profile_picture', 'name', 'email', 'password', 'locale', 'timezone']; |
|
| 19 | + public $searchable = ['name', 'email']; |
|
| 20 | 20 | |
| 21 | - public function getCreatedAtAttribute($value) |
|
| 22 | - { |
|
| 23 | - return \Carbon\Carbon::parse($value)->tz(\Session::get('time-zone'))->toDateTimeString(); |
|
| 24 | - } |
|
| 25 | - |
|
| 26 | - public function getUpdatedAtAttribute($value) |
|
| 27 | - { |
|
| 28 | - return \Carbon\Carbon::parse($value)->tz(\Session::get('time-zone'))->toDateTimeString(); |
|
| 29 | - } |
|
| 30 | - |
|
| 31 | - public function getDeletedAtAttribute($value) |
|
| 32 | - { |
|
| 33 | - return \Carbon\Carbon::parse($value)->tz(\Session::get('time-zone'))->toDateTimeString(); |
|
| 34 | - } |
|
| 35 | - |
|
| 36 | - /** |
|
| 37 | - * Get the profile picture url. |
|
| 38 | - * @return string |
|
| 39 | - */ |
|
| 40 | - public function getProfilePictureAttribute($value) |
|
| 41 | - { |
|
| 42 | - return url(\Storage::url($value)); |
|
| 43 | - } |
|
| 44 | - |
|
| 45 | - /** |
|
| 46 | - * Encrypt the password attribute before |
|
| 47 | - * saving it in the storage. |
|
| 48 | - * |
|
| 49 | - * @param string $value |
|
| 50 | - */ |
|
| 51 | - public function setPasswordAttribute($value) |
|
| 52 | - { |
|
| 53 | - $this->attributes['password'] = \Hash::make($value); |
|
| 54 | - } |
|
| 55 | - |
|
| 56 | - /** |
|
| 57 | - * Get the entity's notifications. |
|
| 58 | - */ |
|
| 59 | - public function notifications() |
|
| 60 | - { |
|
| 61 | - return $this->morphMany(Notification::class, 'notifiable')->orderBy('created_at', 'desc'); |
|
| 62 | - } |
|
| 63 | - |
|
| 64 | - /** |
|
| 65 | - * Get the entity's read notifications. |
|
| 66 | - */ |
|
| 67 | - public function readNotifications() |
|
| 68 | - { |
|
| 69 | - return $this->notifications()->whereNotNull('read_at'); |
|
| 70 | - } |
|
| 71 | - |
|
| 72 | - /** |
|
| 73 | - * Get the entity's unread notifications. |
|
| 74 | - */ |
|
| 75 | - public function unreadNotifications() |
|
| 76 | - { |
|
| 77 | - return $this->notifications()->whereNull('read_at'); |
|
| 78 | - } |
|
| 79 | - |
|
| 80 | - public function roles() |
|
| 81 | - { |
|
| 82 | - return $this->belongsToMany(Role::class, 'role_user', 'user_id', 'role_id')->whereNull('role_user.deleted_at')->withTimestamps(); |
|
| 83 | - } |
|
| 84 | - |
|
| 85 | - public function oauthClients() |
|
| 86 | - { |
|
| 87 | - return $this->hasMany(OauthClient::class, 'user_id'); |
|
| 88 | - } |
|
| 89 | - |
|
| 90 | - /** |
|
| 91 | - * Return fcm device tokens that will be used in sending fcm notifications. |
|
| 92 | - * |
|
| 93 | - * @return array |
|
| 94 | - */ |
|
| 95 | - public function routeNotificationForFCM() |
|
| 96 | - { |
|
| 97 | - $devices = \Core::pushNotificationDevices()->findBy(['user_id' => $this->id]); |
|
| 98 | - $tokens = []; |
|
| 99 | - |
|
| 100 | - foreach ($devices as $device) { |
|
| 101 | - if (\Core::oauthClients()->accessTokenExpiredOrRevoked($device->access_token)) { |
|
| 102 | - $device->forceDelete(); |
|
| 103 | - continue; |
|
| 104 | - } |
|
| 105 | - |
|
| 106 | - $tokens[] = $device->device_token; |
|
| 107 | - } |
|
| 108 | - |
|
| 109 | - return $tokens; |
|
| 110 | - } |
|
| 111 | - |
|
| 112 | - /** |
|
| 113 | - * The channels the user receives notification broadcasts on. |
|
| 114 | - * |
|
| 115 | - * @return string |
|
| 116 | - */ |
|
| 117 | - public function receivesBroadcastNotificationsOn() |
|
| 118 | - { |
|
| 119 | - return 'users.'.$this->id; |
|
| 120 | - } |
|
| 121 | - |
|
| 122 | - /** |
|
| 123 | - * Custom password validation. |
|
| 124 | - * |
|
| 125 | - * @param string $password |
|
| 126 | - * @return boolean |
|
| 127 | - */ |
|
| 128 | - public function validateForPassportPasswordGrant($password) |
|
| 129 | - { |
|
| 130 | - if ($password == config('skeleton.social_pass')) { |
|
| 131 | - return true; |
|
| 132 | - } |
|
| 133 | - |
|
| 134 | - return \Hash::check($password, $this->password); |
|
| 135 | - } |
|
| 21 | + public function getCreatedAtAttribute($value) |
|
| 22 | + { |
|
| 23 | + return \Carbon\Carbon::parse($value)->tz(\Session::get('time-zone'))->toDateTimeString(); |
|
| 24 | + } |
|
| 25 | + |
|
| 26 | + public function getUpdatedAtAttribute($value) |
|
| 27 | + { |
|
| 28 | + return \Carbon\Carbon::parse($value)->tz(\Session::get('time-zone'))->toDateTimeString(); |
|
| 29 | + } |
|
| 30 | + |
|
| 31 | + public function getDeletedAtAttribute($value) |
|
| 32 | + { |
|
| 33 | + return \Carbon\Carbon::parse($value)->tz(\Session::get('time-zone'))->toDateTimeString(); |
|
| 34 | + } |
|
| 35 | + |
|
| 36 | + /** |
|
| 37 | + * Get the profile picture url. |
|
| 38 | + * @return string |
|
| 39 | + */ |
|
| 40 | + public function getProfilePictureAttribute($value) |
|
| 41 | + { |
|
| 42 | + return url(\Storage::url($value)); |
|
| 43 | + } |
|
| 44 | + |
|
| 45 | + /** |
|
| 46 | + * Encrypt the password attribute before |
|
| 47 | + * saving it in the storage. |
|
| 48 | + * |
|
| 49 | + * @param string $value |
|
| 50 | + */ |
|
| 51 | + public function setPasswordAttribute($value) |
|
| 52 | + { |
|
| 53 | + $this->attributes['password'] = \Hash::make($value); |
|
| 54 | + } |
|
| 55 | + |
|
| 56 | + /** |
|
| 57 | + * Get the entity's notifications. |
|
| 58 | + */ |
|
| 59 | + public function notifications() |
|
| 60 | + { |
|
| 61 | + return $this->morphMany(Notification::class, 'notifiable')->orderBy('created_at', 'desc'); |
|
| 62 | + } |
|
| 63 | + |
|
| 64 | + /** |
|
| 65 | + * Get the entity's read notifications. |
|
| 66 | + */ |
|
| 67 | + public function readNotifications() |
|
| 68 | + { |
|
| 69 | + return $this->notifications()->whereNotNull('read_at'); |
|
| 70 | + } |
|
| 71 | + |
|
| 72 | + /** |
|
| 73 | + * Get the entity's unread notifications. |
|
| 74 | + */ |
|
| 75 | + public function unreadNotifications() |
|
| 76 | + { |
|
| 77 | + return $this->notifications()->whereNull('read_at'); |
|
| 78 | + } |
|
| 79 | + |
|
| 80 | + public function roles() |
|
| 81 | + { |
|
| 82 | + return $this->belongsToMany(Role::class, 'role_user', 'user_id', 'role_id')->whereNull('role_user.deleted_at')->withTimestamps(); |
|
| 83 | + } |
|
| 84 | + |
|
| 85 | + public function oauthClients() |
|
| 86 | + { |
|
| 87 | + return $this->hasMany(OauthClient::class, 'user_id'); |
|
| 88 | + } |
|
| 89 | + |
|
| 90 | + /** |
|
| 91 | + * Return fcm device tokens that will be used in sending fcm notifications. |
|
| 92 | + * |
|
| 93 | + * @return array |
|
| 94 | + */ |
|
| 95 | + public function routeNotificationForFCM() |
|
| 96 | + { |
|
| 97 | + $devices = \Core::pushNotificationDevices()->findBy(['user_id' => $this->id]); |
|
| 98 | + $tokens = []; |
|
| 99 | + |
|
| 100 | + foreach ($devices as $device) { |
|
| 101 | + if (\Core::oauthClients()->accessTokenExpiredOrRevoked($device->access_token)) { |
|
| 102 | + $device->forceDelete(); |
|
| 103 | + continue; |
|
| 104 | + } |
|
| 105 | + |
|
| 106 | + $tokens[] = $device->device_token; |
|
| 107 | + } |
|
| 108 | + |
|
| 109 | + return $tokens; |
|
| 110 | + } |
|
| 111 | + |
|
| 112 | + /** |
|
| 113 | + * The channels the user receives notification broadcasts on. |
|
| 114 | + * |
|
| 115 | + * @return string |
|
| 116 | + */ |
|
| 117 | + public function receivesBroadcastNotificationsOn() |
|
| 118 | + { |
|
| 119 | + return 'users.'.$this->id; |
|
| 120 | + } |
|
| 121 | + |
|
| 122 | + /** |
|
| 123 | + * Custom password validation. |
|
| 124 | + * |
|
| 125 | + * @param string $password |
|
| 126 | + * @return boolean |
|
| 127 | + */ |
|
| 128 | + public function validateForPassportPasswordGrant($password) |
|
| 129 | + { |
|
| 130 | + if ($password == config('skeleton.social_pass')) { |
|
| 131 | + return true; |
|
| 132 | + } |
|
| 133 | + |
|
| 134 | + return \Hash::check($password, $this->password); |
|
| 135 | + } |
|
| 136 | 136 | |
| 137 | - public static function boot() |
|
| 138 | - { |
|
| 139 | - parent::boot(); |
|
| 140 | - AclUser::observe(\App::make('App\Modules\Users\ModelObservers\AclUserObserver')); |
|
| 141 | - } |
|
| 137 | + public static function boot() |
|
| 138 | + { |
|
| 139 | + parent::boot(); |
|
| 140 | + AclUser::observe(\App::make('App\Modules\Users\ModelObservers\AclUserObserver')); |
|
| 141 | + } |
|
| 142 | 142 | } |