@@ -10,41 +10,41 @@ |
||
| 10 | 10 | |
| 11 | 11 | class ResetPassword extends Notification implements ShouldQueue |
| 12 | 12 | { |
| 13 | - use Queueable; |
|
| 13 | + use Queueable; |
|
| 14 | 14 | |
| 15 | - protected $token; |
|
| 15 | + protected $token; |
|
| 16 | 16 | |
| 17 | - /** |
|
| 18 | - * Create a new notification instance. |
|
| 19 | - */ |
|
| 20 | - public function __construct($token) |
|
| 21 | - { |
|
| 22 | - $this->token = $token; |
|
| 23 | - } |
|
| 17 | + /** |
|
| 18 | + * Create a new notification instance. |
|
| 19 | + */ |
|
| 20 | + public function __construct($token) |
|
| 21 | + { |
|
| 22 | + $this->token = $token; |
|
| 23 | + } |
|
| 24 | 24 | |
| 25 | - /** |
|
| 26 | - * Get the notification's delivery channels. |
|
| 27 | - * |
|
| 28 | - * @param mixed $notifiable |
|
| 29 | - * @return array |
|
| 30 | - */ |
|
| 31 | - public function via($notifiable) |
|
| 32 | - { |
|
| 33 | - return ['mail']; |
|
| 34 | - } |
|
| 25 | + /** |
|
| 26 | + * Get the notification's delivery channels. |
|
| 27 | + * |
|
| 28 | + * @param mixed $notifiable |
|
| 29 | + * @return array |
|
| 30 | + */ |
|
| 31 | + public function via($notifiable) |
|
| 32 | + { |
|
| 33 | + return ['mail']; |
|
| 34 | + } |
|
| 35 | 35 | |
| 36 | - /** |
|
| 37 | - * Get the mail representation of the notification. |
|
| 38 | - * |
|
| 39 | - * @param mixed $notifiable |
|
| 40 | - * @return \Illuminate\Notifications\Messages\MailMessage |
|
| 41 | - */ |
|
| 42 | - public function toMail($notifiable) |
|
| 43 | - { |
|
| 44 | - return (new MailMessage) |
|
| 45 | - ->subject('Reset passowrd') |
|
| 46 | - ->line('Reset passowrd') |
|
| 47 | - ->line('To reset your password click on the button below') |
|
| 48 | - ->action('Reset password', config('skeleton.reset_password_url') . '/' . $this->token); |
|
| 49 | - } |
|
| 36 | + /** |
|
| 37 | + * Get the mail representation of the notification. |
|
| 38 | + * |
|
| 39 | + * @param mixed $notifiable |
|
| 40 | + * @return \Illuminate\Notifications\Messages\MailMessage |
|
| 41 | + */ |
|
| 42 | + public function toMail($notifiable) |
|
| 43 | + { |
|
| 44 | + return (new MailMessage) |
|
| 45 | + ->subject('Reset passowrd') |
|
| 46 | + ->line('Reset passowrd') |
|
| 47 | + ->line('To reset your password click on the button below') |
|
| 48 | + ->action('Reset password', config('skeleton.reset_password_url') . '/' . $this->token); |
|
| 49 | + } |
|
| 50 | 50 | } |
| 51 | 51 | \ No newline at end of file |
@@ -10,39 +10,39 @@ |
||
| 10 | 10 | |
| 11 | 11 | class ConfirmEmail extends Notification implements ShouldQueue |
| 12 | 12 | { |
| 13 | - use Queueable; |
|
| 13 | + use Queueable; |
|
| 14 | 14 | |
| 15 | - /** |
|
| 16 | - * Create a new notification instance. |
|
| 17 | - */ |
|
| 18 | - public function __construct() |
|
| 19 | - { |
|
| 20 | - // |
|
| 21 | - } |
|
| 15 | + /** |
|
| 16 | + * Create a new notification instance. |
|
| 17 | + */ |
|
| 18 | + public function __construct() |
|
| 19 | + { |
|
| 20 | + // |
|
| 21 | + } |
|
| 22 | 22 | |
| 23 | - /** |
|
| 24 | - * Get the notification's delivery channels. |
|
| 25 | - * |
|
| 26 | - * @param mixed $notifiable |
|
| 27 | - * @return array |
|
| 28 | - */ |
|
| 29 | - public function via($notifiable) |
|
| 30 | - { |
|
| 31 | - return ['mail']; |
|
| 32 | - } |
|
| 23 | + /** |
|
| 24 | + * Get the notification's delivery channels. |
|
| 25 | + * |
|
| 26 | + * @param mixed $notifiable |
|
| 27 | + * @return array |
|
| 28 | + */ |
|
| 29 | + public function via($notifiable) |
|
| 30 | + { |
|
| 31 | + return ['mail']; |
|
| 32 | + } |
|
| 33 | 33 | |
| 34 | - /** |
|
| 35 | - * Get the mail representation of the notification. |
|
| 36 | - * |
|
| 37 | - * @param mixed $notifiable |
|
| 38 | - * @return \Illuminate\Notifications\Messages\MailMessage |
|
| 39 | - */ |
|
| 40 | - public function toMail($notifiable) |
|
| 41 | - { |
|
| 42 | - return (new MailMessage) |
|
| 43 | - ->subject('Email verification') |
|
| 44 | - ->line('Email verification') |
|
| 45 | - ->line('To validate your email click on the button below') |
|
| 46 | - ->action('Verify your email', config('skeleton.confrim_email_url') . '/' . $notifiable->confirmation_code); |
|
| 47 | - } |
|
| 34 | + /** |
|
| 35 | + * Get the mail representation of the notification. |
|
| 36 | + * |
|
| 37 | + * @param mixed $notifiable |
|
| 38 | + * @return \Illuminate\Notifications\Messages\MailMessage |
|
| 39 | + */ |
|
| 40 | + public function toMail($notifiable) |
|
| 41 | + { |
|
| 42 | + return (new MailMessage) |
|
| 43 | + ->subject('Email verification') |
|
| 44 | + ->line('Email verification') |
|
| 45 | + ->line('To validate your email click on the button below') |
|
| 46 | + ->action('Verify your email', config('skeleton.confrim_email_url') . '/' . $notifiable->confirmation_code); |
|
| 47 | + } |
|
| 48 | 48 | } |
| 49 | 49 | \ No newline at end of file |
@@ -5,48 +5,48 @@ |
||
| 5 | 5 | |
| 6 | 6 | class PushNotificationDevice extends Model{ |
| 7 | 7 | |
| 8 | - use SoftDeletes; |
|
| 9 | - protected $table = 'push_notifications_devices'; |
|
| 10 | - protected $dates = ['created_at', 'updated_at', 'deleted_at']; |
|
| 11 | - protected $hidden = ['deleted_at', 'access_token']; |
|
| 12 | - protected $guarded = ['id']; |
|
| 13 | - protected $fillable = ['device_token', 'user_id', 'access_token']; |
|
| 14 | - public $searchable = ['device_token']; |
|
| 15 | - |
|
| 16 | - public function getCreatedAtAttribute($value) |
|
| 17 | - { |
|
| 18 | - return \Carbon\Carbon::parse($value)->tz(\Session::get('time-zone'))->toDateTimeString(); |
|
| 19 | - } |
|
| 20 | - |
|
| 21 | - public function getUpdatedAtAttribute($value) |
|
| 22 | - { |
|
| 23 | - return \Carbon\Carbon::parse($value)->tz(\Session::get('time-zone'))->toDateTimeString(); |
|
| 24 | - } |
|
| 25 | - |
|
| 26 | - public function getDeletedAtAttribute($value) |
|
| 27 | - { |
|
| 28 | - return \Carbon\Carbon::parse($value)->tz(\Session::get('time-zone'))->toDateTimeString(); |
|
| 29 | - } |
|
| 8 | + use SoftDeletes; |
|
| 9 | + protected $table = 'push_notifications_devices'; |
|
| 10 | + protected $dates = ['created_at', 'updated_at', 'deleted_at']; |
|
| 11 | + protected $hidden = ['deleted_at', 'access_token']; |
|
| 12 | + protected $guarded = ['id']; |
|
| 13 | + protected $fillable = ['device_token', 'user_id', 'access_token']; |
|
| 14 | + public $searchable = ['device_token']; |
|
| 15 | + |
|
| 16 | + public function getCreatedAtAttribute($value) |
|
| 17 | + { |
|
| 18 | + return \Carbon\Carbon::parse($value)->tz(\Session::get('time-zone'))->toDateTimeString(); |
|
| 19 | + } |
|
| 20 | + |
|
| 21 | + public function getUpdatedAtAttribute($value) |
|
| 22 | + { |
|
| 23 | + return \Carbon\Carbon::parse($value)->tz(\Session::get('time-zone'))->toDateTimeString(); |
|
| 24 | + } |
|
| 25 | + |
|
| 26 | + public function getDeletedAtAttribute($value) |
|
| 27 | + { |
|
| 28 | + return \Carbon\Carbon::parse($value)->tz(\Session::get('time-zone'))->toDateTimeString(); |
|
| 29 | + } |
|
| 30 | 30 | |
| 31 | - public function user() |
|
| 32 | - { |
|
| 33 | - return $this->belongsTo('App\Modules\Acl\AclUser'); |
|
| 34 | - } |
|
| 35 | - |
|
| 36 | - /** |
|
| 37 | - * Encrypt the access_token attribute before |
|
| 38 | - * saving it in the storage. |
|
| 39 | - * |
|
| 40 | - * @param string $value |
|
| 41 | - */ |
|
| 42 | - public function setLoginTokenAttribute($value) |
|
| 43 | - { |
|
| 44 | - $this->attributes['access_token'] = encrypt($value); |
|
| 45 | - } |
|
| 46 | - |
|
| 47 | - public static function boot() |
|
| 48 | - { |
|
| 49 | - parent::boot(); |
|
| 50 | - $this->observe(\App::make('App\Modules\Notifications\ModelObservers\PushNotificationDeviceObserver')); |
|
| 51 | - } |
|
| 31 | + public function user() |
|
| 32 | + { |
|
| 33 | + return $this->belongsTo('App\Modules\Acl\AclUser'); |
|
| 34 | + } |
|
| 35 | + |
|
| 36 | + /** |
|
| 37 | + * Encrypt the access_token attribute before |
|
| 38 | + * saving it in the storage. |
|
| 39 | + * |
|
| 40 | + * @param string $value |
|
| 41 | + */ |
|
| 42 | + public function setLoginTokenAttribute($value) |
|
| 43 | + { |
|
| 44 | + $this->attributes['access_token'] = encrypt($value); |
|
| 45 | + } |
|
| 46 | + |
|
| 47 | + public static function boot() |
|
| 48 | + { |
|
| 49 | + parent::boot(); |
|
| 50 | + $this->observe(\App::make('App\Modules\Notifications\ModelObservers\PushNotificationDeviceObserver')); |
|
| 51 | + } |
|
| 52 | 52 | } |
@@ -7,56 +7,56 @@ |
||
| 7 | 7 | |
| 8 | 8 | class PushNotificationDeviceRepository extends AbstractRepository |
| 9 | 9 | { |
| 10 | - /** |
|
| 11 | - * Return the model full namespace. |
|
| 12 | - * |
|
| 13 | - * @return string |
|
| 14 | - */ |
|
| 15 | - protected function getModel() |
|
| 16 | - { |
|
| 17 | - return 'App\Modules\Notifications\PushNotificationDevice'; |
|
| 18 | - } |
|
| 19 | - |
|
| 20 | - /** |
|
| 21 | - * Register the given device to the logged in user. |
|
| 22 | - * |
|
| 23 | - * @param array $data |
|
| 24 | - * @return void |
|
| 25 | - */ |
|
| 26 | - public function registerDevice($data) |
|
| 27 | - { |
|
| 28 | - $data['access_token'] = \Auth::user()->token(); |
|
| 29 | - $data['user_id'] = \Auth::id(); |
|
| 30 | - if ($device = $this->model->where('device_token', $data['device_token'])->where('user_id', $data['user_id'])->first()) |
|
| 31 | - { |
|
| 32 | - $data['id'] = $device->id; |
|
| 33 | - } |
|
| 34 | - |
|
| 35 | - return $this->save($data); |
|
| 36 | - } |
|
| 37 | - |
|
| 38 | - /** |
|
| 39 | - * Generate the given message data. |
|
| 40 | - * |
|
| 41 | - * @param string $title |
|
| 42 | - * @param string $message |
|
| 43 | - * @param string $data |
|
| 44 | - * @return void |
|
| 45 | - */ |
|
| 46 | - public function generateMessageData($title, $message, $data = []) |
|
| 47 | - { |
|
| 48 | - $optionBuilder = new OptionsBuilder(); |
|
| 49 | - $notificationBuilder = new PayloadNotificationBuilder($title); |
|
| 50 | - $dataBuilder = new PayloadDataBuilder(); |
|
| 51 | - |
|
| 52 | - $optionBuilder->setTimeToLive(60*20); |
|
| 53 | - $notificationBuilder->setBody($message); |
|
| 54 | - $dataBuilder->addData($data); |
|
| 55 | - |
|
| 56 | - $options = $optionBuilder->build(); |
|
| 57 | - $notification = $notificationBuilder->build(); |
|
| 58 | - $data = $dataBuilder->build(); |
|
| 59 | - |
|
| 60 | - return compact('options', 'notification', 'data'); |
|
| 61 | - } |
|
| 10 | + /** |
|
| 11 | + * Return the model full namespace. |
|
| 12 | + * |
|
| 13 | + * @return string |
|
| 14 | + */ |
|
| 15 | + protected function getModel() |
|
| 16 | + { |
|
| 17 | + return 'App\Modules\Notifications\PushNotificationDevice'; |
|
| 18 | + } |
|
| 19 | + |
|
| 20 | + /** |
|
| 21 | + * Register the given device to the logged in user. |
|
| 22 | + * |
|
| 23 | + * @param array $data |
|
| 24 | + * @return void |
|
| 25 | + */ |
|
| 26 | + public function registerDevice($data) |
|
| 27 | + { |
|
| 28 | + $data['access_token'] = \Auth::user()->token(); |
|
| 29 | + $data['user_id'] = \Auth::id(); |
|
| 30 | + if ($device = $this->model->where('device_token', $data['device_token'])->where('user_id', $data['user_id'])->first()) |
|
| 31 | + { |
|
| 32 | + $data['id'] = $device->id; |
|
| 33 | + } |
|
| 34 | + |
|
| 35 | + return $this->save($data); |
|
| 36 | + } |
|
| 37 | + |
|
| 38 | + /** |
|
| 39 | + * Generate the given message data. |
|
| 40 | + * |
|
| 41 | + * @param string $title |
|
| 42 | + * @param string $message |
|
| 43 | + * @param string $data |
|
| 44 | + * @return void |
|
| 45 | + */ |
|
| 46 | + public function generateMessageData($title, $message, $data = []) |
|
| 47 | + { |
|
| 48 | + $optionBuilder = new OptionsBuilder(); |
|
| 49 | + $notificationBuilder = new PayloadNotificationBuilder($title); |
|
| 50 | + $dataBuilder = new PayloadDataBuilder(); |
|
| 51 | + |
|
| 52 | + $optionBuilder->setTimeToLive(60*20); |
|
| 53 | + $notificationBuilder->setBody($message); |
|
| 54 | + $dataBuilder->addData($data); |
|
| 55 | + |
|
| 56 | + $options = $optionBuilder->build(); |
|
| 57 | + $notification = $notificationBuilder->build(); |
|
| 58 | + $data = $dataBuilder->build(); |
|
| 59 | + |
|
| 60 | + return compact('options', 'notification', 'data'); |
|
| 61 | + } |
|
| 62 | 62 | } |
@@ -4,67 +4,67 @@ |
||
| 4 | 4 | |
| 5 | 5 | class ReportRepository extends AbstractRepository |
| 6 | 6 | { |
| 7 | - /** |
|
| 8 | - * Return the model full namespace. |
|
| 9 | - * |
|
| 10 | - * @return string |
|
| 11 | - */ |
|
| 12 | - protected function getModel() |
|
| 13 | - { |
|
| 14 | - return 'App\Modules\Reporting\Report'; |
|
| 15 | - } |
|
| 7 | + /** |
|
| 8 | + * Return the model full namespace. |
|
| 9 | + * |
|
| 10 | + * @return string |
|
| 11 | + */ |
|
| 12 | + protected function getModel() |
|
| 13 | + { |
|
| 14 | + return 'App\Modules\Reporting\Report'; |
|
| 15 | + } |
|
| 16 | 16 | |
| 17 | - /** |
|
| 18 | - * Render the given report db view based on the given |
|
| 19 | - * condition. |
|
| 20 | - * |
|
| 21 | - * @param string $reportName |
|
| 22 | - * @param array $conditions |
|
| 23 | - * @param integer $perPage |
|
| 24 | - * @param array $relations |
|
| 25 | - * @param boolean $skipPermission |
|
| 26 | - * @return object |
|
| 27 | - */ |
|
| 28 | - public function getReport($reportName, $conditions = [], $perPage = 0, $relations = [], $skipPermission = false) |
|
| 29 | - { |
|
| 30 | - /** |
|
| 31 | - * Fetch the report from db. |
|
| 32 | - */ |
|
| 33 | - $reportConditions = $this->constructConditions(['report_name' => $reportName], $this->model); |
|
| 34 | - $report = call_user_func_array("{$this->getModel()}::with", array($relations))->whereRaw($reportConditions['conditionString'], $reportConditions['conditionValues'])->first(); |
|
| 17 | + /** |
|
| 18 | + * Render the given report db view based on the given |
|
| 19 | + * condition. |
|
| 20 | + * |
|
| 21 | + * @param string $reportName |
|
| 22 | + * @param array $conditions |
|
| 23 | + * @param integer $perPage |
|
| 24 | + * @param array $relations |
|
| 25 | + * @param boolean $skipPermission |
|
| 26 | + * @return object |
|
| 27 | + */ |
|
| 28 | + public function getReport($reportName, $conditions = [], $perPage = 0, $relations = [], $skipPermission = false) |
|
| 29 | + { |
|
| 30 | + /** |
|
| 31 | + * Fetch the report from db. |
|
| 32 | + */ |
|
| 33 | + $reportConditions = $this->constructConditions(['report_name' => $reportName], $this->model); |
|
| 34 | + $report = call_user_func_array("{$this->getModel()}::with", array($relations))->whereRaw($reportConditions['conditionString'], $reportConditions['conditionValues'])->first(); |
|
| 35 | 35 | |
| 36 | - /** |
|
| 37 | - * Check report existance and permission. |
|
| 38 | - */ |
|
| 39 | - if ( ! $report) |
|
| 40 | - { |
|
| 41 | - \ErrorHandler::notFound('report'); |
|
| 42 | - } |
|
| 43 | - else if (! $skipPermission && ! \Core::users()->can($report->view_name, 'reports')) |
|
| 44 | - { |
|
| 45 | - \ErrorHandler::noPermissions(); |
|
| 46 | - } |
|
| 36 | + /** |
|
| 37 | + * Check report existance and permission. |
|
| 38 | + */ |
|
| 39 | + if ( ! $report) |
|
| 40 | + { |
|
| 41 | + \ErrorHandler::notFound('report'); |
|
| 42 | + } |
|
| 43 | + else if (! $skipPermission && ! \Core::users()->can($report->view_name, 'reports')) |
|
| 44 | + { |
|
| 45 | + \ErrorHandler::noPermissions(); |
|
| 46 | + } |
|
| 47 | 47 | |
| 48 | - /** |
|
| 49 | - * Fetch data from the report based on the given conditions. |
|
| 50 | - */ |
|
| 51 | - $report = \DB::table($report->view_name); |
|
| 52 | - unset($conditions['page']); |
|
| 53 | - if (count($conditions)) |
|
| 54 | - { |
|
| 55 | - $conditions = $this->constructConditions($conditions, $this->model); |
|
| 56 | - $report->whereRaw($conditions['conditionString'], $conditions['conditionValues']); |
|
| 57 | - } |
|
| 58 | - /** |
|
| 59 | - * Paginate or all data. |
|
| 60 | - */ |
|
| 61 | - if ($perPage) |
|
| 62 | - { |
|
| 63 | - return $report->paginate($perPage); |
|
| 64 | - } |
|
| 65 | - else |
|
| 66 | - { |
|
| 67 | - return $report->get(); |
|
| 68 | - } |
|
| 69 | - } |
|
| 48 | + /** |
|
| 49 | + * Fetch data from the report based on the given conditions. |
|
| 50 | + */ |
|
| 51 | + $report = \DB::table($report->view_name); |
|
| 52 | + unset($conditions['page']); |
|
| 53 | + if (count($conditions)) |
|
| 54 | + { |
|
| 55 | + $conditions = $this->constructConditions($conditions, $this->model); |
|
| 56 | + $report->whereRaw($conditions['conditionString'], $conditions['conditionValues']); |
|
| 57 | + } |
|
| 58 | + /** |
|
| 59 | + * Paginate or all data. |
|
| 60 | + */ |
|
| 61 | + if ($perPage) |
|
| 62 | + { |
|
| 63 | + return $report->paginate($perPage); |
|
| 64 | + } |
|
| 65 | + else |
|
| 66 | + { |
|
| 67 | + return $report->get(); |
|
| 68 | + } |
|
| 69 | + } |
|
| 70 | 70 | } |
@@ -5,32 +5,32 @@ |
||
| 5 | 5 | |
| 6 | 6 | class Report extends Model{ |
| 7 | 7 | |
| 8 | - use SoftDeletes; |
|
| 8 | + use SoftDeletes; |
|
| 9 | 9 | protected $table = 'reports'; |
| 10 | 10 | protected $dates = ['created_at', 'updated_at', 'deleted_at']; |
| 11 | 11 | protected $hidden = ['deleted_at']; |
| 12 | 12 | protected $guarded = ['id']; |
| 13 | 13 | protected $fillable = ['report_name', 'view_name']; |
| 14 | - public $searchable = ['report_name', 'view_name']; |
|
| 14 | + public $searchable = ['report_name', 'view_name']; |
|
| 15 | 15 | |
| 16 | 16 | public function getCreatedAtAttribute($value) |
| 17 | - { |
|
| 18 | - return \Carbon\Carbon::parse($value)->tz(\Session::get('time-zone'))->toDateTimeString(); |
|
| 19 | - } |
|
| 17 | + { |
|
| 18 | + return \Carbon\Carbon::parse($value)->tz(\Session::get('time-zone'))->toDateTimeString(); |
|
| 19 | + } |
|
| 20 | 20 | |
| 21 | - public function getUpdatedAtAttribute($value) |
|
| 22 | - { |
|
| 23 | - return \Carbon\Carbon::parse($value)->tz(\Session::get('time-zone'))->toDateTimeString(); |
|
| 24 | - } |
|
| 21 | + public function getUpdatedAtAttribute($value) |
|
| 22 | + { |
|
| 23 | + return \Carbon\Carbon::parse($value)->tz(\Session::get('time-zone'))->toDateTimeString(); |
|
| 24 | + } |
|
| 25 | 25 | |
| 26 | - public function getDeletedAtAttribute($value) |
|
| 27 | - { |
|
| 28 | - return \Carbon\Carbon::parse($value)->tz(\Session::get('time-zone'))->toDateTimeString(); |
|
| 29 | - } |
|
| 26 | + public function getDeletedAtAttribute($value) |
|
| 27 | + { |
|
| 28 | + return \Carbon\Carbon::parse($value)->tz(\Session::get('time-zone'))->toDateTimeString(); |
|
| 29 | + } |
|
| 30 | 30 | |
| 31 | - public static function boot() |
|
| 32 | - { |
|
| 33 | - parent::boot(); |
|
| 34 | - $this->observe(\App::make('App\Modules\Reporting\ModelObservers\ReprotObserver')); |
|
| 35 | - } |
|
| 31 | + public static function boot() |
|
| 32 | + { |
|
| 33 | + parent::boot(); |
|
| 34 | + $this->observe(\App::make('App\Modules\Reporting\ModelObservers\ReprotObserver')); |
|
| 35 | + } |
|
| 36 | 36 | } |
@@ -8,282 +8,282 @@ |
||
| 8 | 8 | |
| 9 | 9 | class UsersController extends BaseApiController |
| 10 | 10 | { |
| 11 | - /** |
|
| 12 | - * The name of the model that is used by the base api controller |
|
| 13 | - * to preform actions like (add, edit ... etc). |
|
| 14 | - * @var string |
|
| 15 | - */ |
|
| 16 | - protected $model = 'users'; |
|
| 17 | - |
|
| 18 | - /** |
|
| 19 | - * List of all route actions that the base api controller |
|
| 20 | - * will skip permissions check for them. |
|
| 21 | - * @var array |
|
| 22 | - */ |
|
| 23 | - protected $skipPermissionCheck = ['account', 'logout', 'changePassword', 'saveProfile', 'account']; |
|
| 24 | - |
|
| 25 | - /** |
|
| 26 | - * List of all route actions that the base api controller |
|
| 27 | - * will skip login check for them. |
|
| 28 | - * @var array |
|
| 29 | - */ |
|
| 30 | - protected $skipLoginCheck = ['login', 'loginSocial', 'register', 'sendreset', 'resetpassword', 'refreshtoken', 'confirmEmail', 'resendEmailConfirmation']; |
|
| 31 | - |
|
| 32 | - /** |
|
| 33 | - * The validations rules used by the base api controller |
|
| 34 | - * to check before add. |
|
| 35 | - * @var array |
|
| 36 | - */ |
|
| 37 | - protected $validationRules = [ |
|
| 38 | - 'name' => 'nullable|string', |
|
| 39 | - 'email' => 'required|email|unique:users,email,{id}', |
|
| 40 | - 'password' => 'nullable|min:6' |
|
| 41 | - ]; |
|
| 42 | - |
|
| 43 | - /** |
|
| 44 | - * The loginProxy implementation. |
|
| 45 | - * |
|
| 46 | - * @var \App\Modules\Acl\Proxy\LoginProxy |
|
| 47 | - */ |
|
| 48 | - protected $loginProxy; |
|
| 49 | - |
|
| 50 | - public function __construct(LoginProxy $loginProxy) |
|
| 51 | - { |
|
| 52 | - $this->loginProxy = $loginProxy; |
|
| 53 | - parent::__construct(); |
|
| 54 | - } |
|
| 55 | - |
|
| 56 | - /** |
|
| 57 | - * Return the logged in user account. |
|
| 58 | - * |
|
| 59 | - * @return \Illuminate\Http\Response |
|
| 60 | - */ |
|
| 61 | - public function account() |
|
| 62 | - { |
|
| 63 | - return \Response::json($this->repo->account($this->relations), 200); |
|
| 64 | - } |
|
| 65 | - |
|
| 66 | - /** |
|
| 67 | - * Block the user. |
|
| 68 | - * |
|
| 69 | - * @param integer $id Id of the user. |
|
| 70 | - * @return \Illuminate\Http\Response |
|
| 71 | - */ |
|
| 72 | - public function block($id) |
|
| 73 | - { |
|
| 74 | - return \Response::json($this->repo->block($id), 200); |
|
| 75 | - } |
|
| 76 | - |
|
| 77 | - /** |
|
| 78 | - * Unblock the user. |
|
| 79 | - * |
|
| 80 | - * @param integer $id Id of the user. |
|
| 81 | - * @return \Illuminate\Http\Response |
|
| 82 | - */ |
|
| 83 | - public function unblock($id) |
|
| 84 | - { |
|
| 85 | - return \Response::json($this->repo->unblock($id), 200); |
|
| 86 | - } |
|
| 87 | - |
|
| 88 | - /** |
|
| 89 | - * Logout the user. |
|
| 90 | - * |
|
| 91 | - * @return \Illuminate\Http\Response |
|
| 92 | - */ |
|
| 93 | - public function logout() |
|
| 94 | - { |
|
| 95 | - return \Response::json($this->loginProxy->logout(), 200); |
|
| 96 | - } |
|
| 97 | - |
|
| 98 | - /** |
|
| 99 | - * Handle a registration request. |
|
| 100 | - * |
|
| 101 | - * @param \Illuminate\Http\Request $request |
|
| 102 | - * @return \Illuminate\Http\Response |
|
| 103 | - */ |
|
| 104 | - public function register(Request $request) |
|
| 105 | - { |
|
| 106 | - $this->validate($request, [ |
|
| 107 | - 'name' => 'nullable|string', |
|
| 108 | - 'email' => 'required|email|unique:users,email,{id}', |
|
| 109 | - 'password' => 'required|min:6' |
|
| 110 | - ]); |
|
| 111 | - |
|
| 112 | - return \Response::json($this->repo->register($request->only('name', 'email', 'password')), 200); |
|
| 113 | - } |
|
| 114 | - |
|
| 115 | - /** |
|
| 116 | - * Handle a login request to the application. |
|
| 117 | - * |
|
| 118 | - * @param \Illuminate\Http\Request $request |
|
| 119 | - * @return \Illuminate\Http\Response |
|
| 120 | - */ |
|
| 121 | - public function login(Request $request) |
|
| 122 | - { |
|
| 123 | - $this->validate($request, [ |
|
| 124 | - 'email' => 'required|email', |
|
| 125 | - 'password' => 'required|min:6', |
|
| 126 | - 'admin' => 'nullable|boolean' |
|
| 127 | - ]); |
|
| 128 | - |
|
| 129 | - return \Response::json($this->loginProxy->login($request->only('email', 'password'), $request->get('admin')), 200); |
|
| 130 | - } |
|
| 131 | - |
|
| 132 | - /** |
|
| 133 | - * Handle a social login request of the none admin to the application. |
|
| 134 | - * |
|
| 135 | - * @param \Illuminate\Http\Request $request |
|
| 136 | - * @return \Illuminate\Http\Response |
|
| 137 | - */ |
|
| 138 | - public function loginSocial(Request $request) |
|
| 139 | - { |
|
| 140 | - $this->validate($request, [ |
|
| 141 | - 'auth_code' => 'required_without:access_token', |
|
| 142 | - 'access_token' => 'required_without:auth_code', |
|
| 143 | - 'type' => 'required|in:facebook,google' |
|
| 144 | - ]); |
|
| 145 | - |
|
| 146 | - return \Response::json($this->repo->loginSocial($request->get('auth_code'), $request->get('access_token'), $request->get('type')), 200); |
|
| 147 | - } |
|
| 148 | - |
|
| 149 | - /** |
|
| 150 | - * Assign the given groups to the given user. |
|
| 151 | - * |
|
| 152 | - * @param \Illuminate\Http\Request $request |
|
| 153 | - * @return \Illuminate\Http\Response |
|
| 154 | - */ |
|
| 155 | - public function assigngroups(Request $request) |
|
| 156 | - { |
|
| 157 | - $this->validate($request, [ |
|
| 158 | - 'group_ids' => 'required|exists:groups,id', |
|
| 159 | - 'user_id' => 'required|exists:users,id' |
|
| 160 | - ]); |
|
| 161 | - |
|
| 162 | - return \Response::json($this->repo->assignGroups($request->get('user_id'), $request->get('group_ids')), 200); |
|
| 163 | - } |
|
| 164 | - |
|
| 165 | - /** |
|
| 166 | - * Send a reset link to the given user. |
|
| 167 | - * |
|
| 168 | - * @param \Illuminate\Http\Request $request |
|
| 169 | - * @return \Illuminate\Http\Response |
|
| 170 | - */ |
|
| 171 | - public function sendreset(Request $request) |
|
| 172 | - { |
|
| 173 | - $this->validate($request, ['email' => 'required|email']); |
|
| 174 | - |
|
| 175 | - return \Response::json($this->repo->sendReset($request->get('email')), 200); |
|
| 176 | - } |
|
| 177 | - |
|
| 178 | - /** |
|
| 179 | - * Reset the given user's password. |
|
| 180 | - * |
|
| 181 | - * @param \Illuminate\Http\Request $request |
|
| 182 | - * @return \Illuminate\Http\Response |
|
| 183 | - */ |
|
| 184 | - public function resetpassword(Request $request) |
|
| 185 | - { |
|
| 186 | - $this->validate($request, [ |
|
| 187 | - 'token' => 'required', |
|
| 188 | - 'email' => 'required|email', |
|
| 189 | - 'password' => 'required|confirmed|min:6', |
|
| 190 | - 'password_confirmation' => 'required', |
|
| 191 | - ]); |
|
| 192 | - |
|
| 193 | - return \Response::json($this->repo->resetPassword($request->only('email', 'password', 'password_confirmation', 'token')), 200); |
|
| 194 | - } |
|
| 195 | - |
|
| 196 | - /** |
|
| 197 | - * Change the logged in user password. |
|
| 198 | - * |
|
| 199 | - * @param \Illuminate\Http\Request $request |
|
| 200 | - * @return \Illuminate\Http\Response |
|
| 201 | - */ |
|
| 202 | - public function changePassword(Request $request) |
|
| 203 | - { |
|
| 204 | - $this->validate($request, [ |
|
| 205 | - 'old_password' => 'required', |
|
| 206 | - 'password' => 'required|confirmed|min:6', |
|
| 207 | - 'password_confirmation' => 'required', |
|
| 208 | - ]); |
|
| 209 | - |
|
| 210 | - return \Response::json($this->repo->changePassword($request->only('old_password', 'password', 'password_confirmation')), 200); |
|
| 211 | - } |
|
| 212 | - |
|
| 213 | - /** |
|
| 214 | - * Confirm email using the confirmation code. |
|
| 215 | - * |
|
| 216 | - * @param \Illuminate\Http\Request $request |
|
| 217 | - * @return \Illuminate\Http\Response |
|
| 218 | - */ |
|
| 219 | - public function confirmEmail(Request $request) |
|
| 220 | - { |
|
| 221 | - $this->validate($request, [ |
|
| 222 | - 'confirmation_code' => 'required|string|exists:users,confirmation_code' |
|
| 223 | - ]); |
|
| 224 | - |
|
| 225 | - return \Response::json($this->repo->confirmEmail($request->only('confirmation_code')), 200); |
|
| 226 | - } |
|
| 227 | - |
|
| 228 | - /** |
|
| 229 | - * Resend the email confirmation mail. |
|
| 230 | - * |
|
| 231 | - * @param \Illuminate\Http\Request $request |
|
| 232 | - * @return \Illuminate\Http\Response |
|
| 233 | - */ |
|
| 234 | - public function resendEmailConfirmation(Request $request) |
|
| 235 | - { |
|
| 236 | - $this->validate($request, [ |
|
| 237 | - 'email' => 'required|exists:users,email' |
|
| 238 | - ]); |
|
| 239 | - |
|
| 240 | - return \Response::json($this->repo->sendConfirmationEmail($request->get('email')), 200); |
|
| 241 | - } |
|
| 242 | - |
|
| 243 | - /** |
|
| 244 | - * Refresh the expired login token. |
|
| 245 | - * |
|
| 246 | - * @param \Illuminate\Http\Request $request |
|
| 247 | - * @return \Illuminate\Http\Response |
|
| 248 | - */ |
|
| 249 | - public function refreshtoken(Request $request) |
|
| 250 | - { |
|
| 251 | - $this->validate($request, [ |
|
| 252 | - 'refreshtoken' => 'required', |
|
| 253 | - ]); |
|
| 254 | - |
|
| 255 | - return \Response::json($this->loginProxy->refreshtoken($request->get('refreshtoken')), 200); |
|
| 256 | - } |
|
| 257 | - |
|
| 258 | - /** |
|
| 259 | - * Paginate all users with in the given group. |
|
| 260 | - * |
|
| 261 | - * @param \Illuminate\Http\Request $request |
|
| 262 | - * @param string $groupName The name of the requested group. |
|
| 263 | - * @param integer $perPage Number of rows per page default 15. |
|
| 264 | - * @param string $sortBy The name of the column to sort by. |
|
| 265 | - * @param boolean $desc Sort ascending or descinding (1: desc, 0: asc). |
|
| 266 | - * @return \Illuminate\Http\Response |
|
| 267 | - */ |
|
| 268 | - public function group(Request $request, $groupName, $perPage = false, $sortBy = 'created_at', $desc = 1) |
|
| 269 | - { |
|
| 270 | - return \Response::json($this->repo->group($request->all(), $groupName, $this->relations, $perPage, $sortBy, $desc), 200); |
|
| 271 | - } |
|
| 272 | - |
|
| 273 | - /** |
|
| 274 | - * Save the given data to the logged in user. |
|
| 275 | - * |
|
| 276 | - * @param \Illuminate\Http\Request $request |
|
| 277 | - * @return \Illuminate\Http\Response |
|
| 278 | - */ |
|
| 279 | - public function saveProfile(Request $request) |
|
| 280 | - { |
|
| 281 | - $this->validate($request, [ |
|
| 282 | - 'profile_picture' => 'nullable|string', |
|
| 283 | - 'name' => 'nullable|string', |
|
| 284 | - 'email' => 'required|email|unique:users,email,' . \Auth::id() |
|
| 285 | - ]); |
|
| 286 | - |
|
| 287 | - return \Response::json($this->repo->saveProfile($request->only('name', 'email', 'profile_picture')), 200); |
|
| 288 | - } |
|
| 11 | + /** |
|
| 12 | + * The name of the model that is used by the base api controller |
|
| 13 | + * to preform actions like (add, edit ... etc). |
|
| 14 | + * @var string |
|
| 15 | + */ |
|
| 16 | + protected $model = 'users'; |
|
| 17 | + |
|
| 18 | + /** |
|
| 19 | + * List of all route actions that the base api controller |
|
| 20 | + * will skip permissions check for them. |
|
| 21 | + * @var array |
|
| 22 | + */ |
|
| 23 | + protected $skipPermissionCheck = ['account', 'logout', 'changePassword', 'saveProfile', 'account']; |
|
| 24 | + |
|
| 25 | + /** |
|
| 26 | + * List of all route actions that the base api controller |
|
| 27 | + * will skip login check for them. |
|
| 28 | + * @var array |
|
| 29 | + */ |
|
| 30 | + protected $skipLoginCheck = ['login', 'loginSocial', 'register', 'sendreset', 'resetpassword', 'refreshtoken', 'confirmEmail', 'resendEmailConfirmation']; |
|
| 31 | + |
|
| 32 | + /** |
|
| 33 | + * The validations rules used by the base api controller |
|
| 34 | + * to check before add. |
|
| 35 | + * @var array |
|
| 36 | + */ |
|
| 37 | + protected $validationRules = [ |
|
| 38 | + 'name' => 'nullable|string', |
|
| 39 | + 'email' => 'required|email|unique:users,email,{id}', |
|
| 40 | + 'password' => 'nullable|min:6' |
|
| 41 | + ]; |
|
| 42 | + |
|
| 43 | + /** |
|
| 44 | + * The loginProxy implementation. |
|
| 45 | + * |
|
| 46 | + * @var \App\Modules\Acl\Proxy\LoginProxy |
|
| 47 | + */ |
|
| 48 | + protected $loginProxy; |
|
| 49 | + |
|
| 50 | + public function __construct(LoginProxy $loginProxy) |
|
| 51 | + { |
|
| 52 | + $this->loginProxy = $loginProxy; |
|
| 53 | + parent::__construct(); |
|
| 54 | + } |
|
| 55 | + |
|
| 56 | + /** |
|
| 57 | + * Return the logged in user account. |
|
| 58 | + * |
|
| 59 | + * @return \Illuminate\Http\Response |
|
| 60 | + */ |
|
| 61 | + public function account() |
|
| 62 | + { |
|
| 63 | + return \Response::json($this->repo->account($this->relations), 200); |
|
| 64 | + } |
|
| 65 | + |
|
| 66 | + /** |
|
| 67 | + * Block the user. |
|
| 68 | + * |
|
| 69 | + * @param integer $id Id of the user. |
|
| 70 | + * @return \Illuminate\Http\Response |
|
| 71 | + */ |
|
| 72 | + public function block($id) |
|
| 73 | + { |
|
| 74 | + return \Response::json($this->repo->block($id), 200); |
|
| 75 | + } |
|
| 76 | + |
|
| 77 | + /** |
|
| 78 | + * Unblock the user. |
|
| 79 | + * |
|
| 80 | + * @param integer $id Id of the user. |
|
| 81 | + * @return \Illuminate\Http\Response |
|
| 82 | + */ |
|
| 83 | + public function unblock($id) |
|
| 84 | + { |
|
| 85 | + return \Response::json($this->repo->unblock($id), 200); |
|
| 86 | + } |
|
| 87 | + |
|
| 88 | + /** |
|
| 89 | + * Logout the user. |
|
| 90 | + * |
|
| 91 | + * @return \Illuminate\Http\Response |
|
| 92 | + */ |
|
| 93 | + public function logout() |
|
| 94 | + { |
|
| 95 | + return \Response::json($this->loginProxy->logout(), 200); |
|
| 96 | + } |
|
| 97 | + |
|
| 98 | + /** |
|
| 99 | + * Handle a registration request. |
|
| 100 | + * |
|
| 101 | + * @param \Illuminate\Http\Request $request |
|
| 102 | + * @return \Illuminate\Http\Response |
|
| 103 | + */ |
|
| 104 | + public function register(Request $request) |
|
| 105 | + { |
|
| 106 | + $this->validate($request, [ |
|
| 107 | + 'name' => 'nullable|string', |
|
| 108 | + 'email' => 'required|email|unique:users,email,{id}', |
|
| 109 | + 'password' => 'required|min:6' |
|
| 110 | + ]); |
|
| 111 | + |
|
| 112 | + return \Response::json($this->repo->register($request->only('name', 'email', 'password')), 200); |
|
| 113 | + } |
|
| 114 | + |
|
| 115 | + /** |
|
| 116 | + * Handle a login request to the application. |
|
| 117 | + * |
|
| 118 | + * @param \Illuminate\Http\Request $request |
|
| 119 | + * @return \Illuminate\Http\Response |
|
| 120 | + */ |
|
| 121 | + public function login(Request $request) |
|
| 122 | + { |
|
| 123 | + $this->validate($request, [ |
|
| 124 | + 'email' => 'required|email', |
|
| 125 | + 'password' => 'required|min:6', |
|
| 126 | + 'admin' => 'nullable|boolean' |
|
| 127 | + ]); |
|
| 128 | + |
|
| 129 | + return \Response::json($this->loginProxy->login($request->only('email', 'password'), $request->get('admin')), 200); |
|
| 130 | + } |
|
| 131 | + |
|
| 132 | + /** |
|
| 133 | + * Handle a social login request of the none admin to the application. |
|
| 134 | + * |
|
| 135 | + * @param \Illuminate\Http\Request $request |
|
| 136 | + * @return \Illuminate\Http\Response |
|
| 137 | + */ |
|
| 138 | + public function loginSocial(Request $request) |
|
| 139 | + { |
|
| 140 | + $this->validate($request, [ |
|
| 141 | + 'auth_code' => 'required_without:access_token', |
|
| 142 | + 'access_token' => 'required_without:auth_code', |
|
| 143 | + 'type' => 'required|in:facebook,google' |
|
| 144 | + ]); |
|
| 145 | + |
|
| 146 | + return \Response::json($this->repo->loginSocial($request->get('auth_code'), $request->get('access_token'), $request->get('type')), 200); |
|
| 147 | + } |
|
| 148 | + |
|
| 149 | + /** |
|
| 150 | + * Assign the given groups to the given user. |
|
| 151 | + * |
|
| 152 | + * @param \Illuminate\Http\Request $request |
|
| 153 | + * @return \Illuminate\Http\Response |
|
| 154 | + */ |
|
| 155 | + public function assigngroups(Request $request) |
|
| 156 | + { |
|
| 157 | + $this->validate($request, [ |
|
| 158 | + 'group_ids' => 'required|exists:groups,id', |
|
| 159 | + 'user_id' => 'required|exists:users,id' |
|
| 160 | + ]); |
|
| 161 | + |
|
| 162 | + return \Response::json($this->repo->assignGroups($request->get('user_id'), $request->get('group_ids')), 200); |
|
| 163 | + } |
|
| 164 | + |
|
| 165 | + /** |
|
| 166 | + * Send a reset link to the given user. |
|
| 167 | + * |
|
| 168 | + * @param \Illuminate\Http\Request $request |
|
| 169 | + * @return \Illuminate\Http\Response |
|
| 170 | + */ |
|
| 171 | + public function sendreset(Request $request) |
|
| 172 | + { |
|
| 173 | + $this->validate($request, ['email' => 'required|email']); |
|
| 174 | + |
|
| 175 | + return \Response::json($this->repo->sendReset($request->get('email')), 200); |
|
| 176 | + } |
|
| 177 | + |
|
| 178 | + /** |
|
| 179 | + * Reset the given user's password. |
|
| 180 | + * |
|
| 181 | + * @param \Illuminate\Http\Request $request |
|
| 182 | + * @return \Illuminate\Http\Response |
|
| 183 | + */ |
|
| 184 | + public function resetpassword(Request $request) |
|
| 185 | + { |
|
| 186 | + $this->validate($request, [ |
|
| 187 | + 'token' => 'required', |
|
| 188 | + 'email' => 'required|email', |
|
| 189 | + 'password' => 'required|confirmed|min:6', |
|
| 190 | + 'password_confirmation' => 'required', |
|
| 191 | + ]); |
|
| 192 | + |
|
| 193 | + return \Response::json($this->repo->resetPassword($request->only('email', 'password', 'password_confirmation', 'token')), 200); |
|
| 194 | + } |
|
| 195 | + |
|
| 196 | + /** |
|
| 197 | + * Change the logged in user password. |
|
| 198 | + * |
|
| 199 | + * @param \Illuminate\Http\Request $request |
|
| 200 | + * @return \Illuminate\Http\Response |
|
| 201 | + */ |
|
| 202 | + public function changePassword(Request $request) |
|
| 203 | + { |
|
| 204 | + $this->validate($request, [ |
|
| 205 | + 'old_password' => 'required', |
|
| 206 | + 'password' => 'required|confirmed|min:6', |
|
| 207 | + 'password_confirmation' => 'required', |
|
| 208 | + ]); |
|
| 209 | + |
|
| 210 | + return \Response::json($this->repo->changePassword($request->only('old_password', 'password', 'password_confirmation')), 200); |
|
| 211 | + } |
|
| 212 | + |
|
| 213 | + /** |
|
| 214 | + * Confirm email using the confirmation code. |
|
| 215 | + * |
|
| 216 | + * @param \Illuminate\Http\Request $request |
|
| 217 | + * @return \Illuminate\Http\Response |
|
| 218 | + */ |
|
| 219 | + public function confirmEmail(Request $request) |
|
| 220 | + { |
|
| 221 | + $this->validate($request, [ |
|
| 222 | + 'confirmation_code' => 'required|string|exists:users,confirmation_code' |
|
| 223 | + ]); |
|
| 224 | + |
|
| 225 | + return \Response::json($this->repo->confirmEmail($request->only('confirmation_code')), 200); |
|
| 226 | + } |
|
| 227 | + |
|
| 228 | + /** |
|
| 229 | + * Resend the email confirmation mail. |
|
| 230 | + * |
|
| 231 | + * @param \Illuminate\Http\Request $request |
|
| 232 | + * @return \Illuminate\Http\Response |
|
| 233 | + */ |
|
| 234 | + public function resendEmailConfirmation(Request $request) |
|
| 235 | + { |
|
| 236 | + $this->validate($request, [ |
|
| 237 | + 'email' => 'required|exists:users,email' |
|
| 238 | + ]); |
|
| 239 | + |
|
| 240 | + return \Response::json($this->repo->sendConfirmationEmail($request->get('email')), 200); |
|
| 241 | + } |
|
| 242 | + |
|
| 243 | + /** |
|
| 244 | + * Refresh the expired login token. |
|
| 245 | + * |
|
| 246 | + * @param \Illuminate\Http\Request $request |
|
| 247 | + * @return \Illuminate\Http\Response |
|
| 248 | + */ |
|
| 249 | + public function refreshtoken(Request $request) |
|
| 250 | + { |
|
| 251 | + $this->validate($request, [ |
|
| 252 | + 'refreshtoken' => 'required', |
|
| 253 | + ]); |
|
| 254 | + |
|
| 255 | + return \Response::json($this->loginProxy->refreshtoken($request->get('refreshtoken')), 200); |
|
| 256 | + } |
|
| 257 | + |
|
| 258 | + /** |
|
| 259 | + * Paginate all users with in the given group. |
|
| 260 | + * |
|
| 261 | + * @param \Illuminate\Http\Request $request |
|
| 262 | + * @param string $groupName The name of the requested group. |
|
| 263 | + * @param integer $perPage Number of rows per page default 15. |
|
| 264 | + * @param string $sortBy The name of the column to sort by. |
|
| 265 | + * @param boolean $desc Sort ascending or descinding (1: desc, 0: asc). |
|
| 266 | + * @return \Illuminate\Http\Response |
|
| 267 | + */ |
|
| 268 | + public function group(Request $request, $groupName, $perPage = false, $sortBy = 'created_at', $desc = 1) |
|
| 269 | + { |
|
| 270 | + return \Response::json($this->repo->group($request->all(), $groupName, $this->relations, $perPage, $sortBy, $desc), 200); |
|
| 271 | + } |
|
| 272 | + |
|
| 273 | + /** |
|
| 274 | + * Save the given data to the logged in user. |
|
| 275 | + * |
|
| 276 | + * @param \Illuminate\Http\Request $request |
|
| 277 | + * @return \Illuminate\Http\Response |
|
| 278 | + */ |
|
| 279 | + public function saveProfile(Request $request) |
|
| 280 | + { |
|
| 281 | + $this->validate($request, [ |
|
| 282 | + 'profile_picture' => 'nullable|string', |
|
| 283 | + 'name' => 'nullable|string', |
|
| 284 | + 'email' => 'required|email|unique:users,email,' . \Auth::id() |
|
| 285 | + ]); |
|
| 286 | + |
|
| 287 | + return \Response::json($this->repo->saveProfile($request->only('name', 'email', 'profile_picture')), 200); |
|
| 288 | + } |
|
| 289 | 289 | } |
@@ -5,42 +5,42 @@ |
||
| 5 | 5 | |
| 6 | 6 | class AclGroup extends Model{ |
| 7 | 7 | |
| 8 | - use SoftDeletes; |
|
| 9 | - protected $table = 'groups'; |
|
| 10 | - protected $dates = ['created_at', 'updated_at', 'deleted_at']; |
|
| 11 | - protected $hidden = ['deleted_at']; |
|
| 12 | - protected $guarded = ['id']; |
|
| 13 | - protected $fillable = ['name']; |
|
| 14 | - public $searchable = ['name']; |
|
| 15 | - |
|
| 16 | - public function getCreatedAtAttribute($value) |
|
| 17 | - { |
|
| 18 | - return \Carbon\Carbon::parse($value)->tz(\Session::get('time-zone'))->toDateTimeString(); |
|
| 19 | - } |
|
| 20 | - |
|
| 21 | - public function getUpdatedAtAttribute($value) |
|
| 22 | - { |
|
| 23 | - return \Carbon\Carbon::parse($value)->tz(\Session::get('time-zone'))->toDateTimeString(); |
|
| 24 | - } |
|
| 25 | - |
|
| 26 | - public function getDeletedAtAttribute($value) |
|
| 27 | - { |
|
| 28 | - return \Carbon\Carbon::parse($value)->tz(\Session::get('time-zone'))->toDateTimeString(); |
|
| 29 | - } |
|
| 30 | - |
|
| 31 | - public function users() |
|
| 32 | - { |
|
| 33 | - return $this->belongsToMany('\App\Modules\Acl\AclUser','users_groups','group_id','user_id')->whereNull('users_groups.deleted_at')->withTimestamps(); |
|
| 34 | - } |
|
| 35 | - |
|
| 36 | - public function permissions() |
|
| 37 | - { |
|
| 38 | - return $this->belongsToMany('\App\Modules\Acl\AclPermission','groups_permissions','group_id','permission_id')->whereNull('groups_permissions.deleted_at')->withTimestamps(); |
|
| 39 | - } |
|
| 40 | - |
|
| 41 | - public static function boot() |
|
| 42 | - { |
|
| 43 | - parent::boot(); |
|
| 44 | - $this->observe(\App::make('App\Modules\Acl\ModelObservers\AclGroupObserver')); |
|
| 45 | - } |
|
| 8 | + use SoftDeletes; |
|
| 9 | + protected $table = 'groups'; |
|
| 10 | + protected $dates = ['created_at', 'updated_at', 'deleted_at']; |
|
| 11 | + protected $hidden = ['deleted_at']; |
|
| 12 | + protected $guarded = ['id']; |
|
| 13 | + protected $fillable = ['name']; |
|
| 14 | + public $searchable = ['name']; |
|
| 15 | + |
|
| 16 | + public function getCreatedAtAttribute($value) |
|
| 17 | + { |
|
| 18 | + return \Carbon\Carbon::parse($value)->tz(\Session::get('time-zone'))->toDateTimeString(); |
|
| 19 | + } |
|
| 20 | + |
|
| 21 | + public function getUpdatedAtAttribute($value) |
|
| 22 | + { |
|
| 23 | + return \Carbon\Carbon::parse($value)->tz(\Session::get('time-zone'))->toDateTimeString(); |
|
| 24 | + } |
|
| 25 | + |
|
| 26 | + public function getDeletedAtAttribute($value) |
|
| 27 | + { |
|
| 28 | + return \Carbon\Carbon::parse($value)->tz(\Session::get('time-zone'))->toDateTimeString(); |
|
| 29 | + } |
|
| 30 | + |
|
| 31 | + public function users() |
|
| 32 | + { |
|
| 33 | + return $this->belongsToMany('\App\Modules\Acl\AclUser','users_groups','group_id','user_id')->whereNull('users_groups.deleted_at')->withTimestamps(); |
|
| 34 | + } |
|
| 35 | + |
|
| 36 | + public function permissions() |
|
| 37 | + { |
|
| 38 | + return $this->belongsToMany('\App\Modules\Acl\AclPermission','groups_permissions','group_id','permission_id')->whereNull('groups_permissions.deleted_at')->withTimestamps(); |
|
| 39 | + } |
|
| 40 | + |
|
| 41 | + public static function boot() |
|
| 42 | + { |
|
| 43 | + parent::boot(); |
|
| 44 | + $this->observe(\App::make('App\Modules\Acl\ModelObservers\AclGroupObserver')); |
|
| 45 | + } |
|
| 46 | 46 | } |
@@ -7,135 +7,135 @@ |
||
| 7 | 7 | |
| 8 | 8 | class AclUser extends User { |
| 9 | 9 | |
| 10 | - use SoftDeletes, HasApiTokens; |
|
| 11 | - protected $table = 'users'; |
|
| 12 | - protected $dates = ['created_at', 'updated_at', 'deleted_at']; |
|
| 13 | - protected $hidden = ['password', 'remember_token','deleted_at']; |
|
| 14 | - protected $guarded = ['id']; |
|
| 15 | - protected $fillable = ['profile_picture', 'name', 'email', 'password']; |
|
| 16 | - public $searchable = ['name', 'email']; |
|
| 10 | + use SoftDeletes, HasApiTokens; |
|
| 11 | + protected $table = 'users'; |
|
| 12 | + protected $dates = ['created_at', 'updated_at', 'deleted_at']; |
|
| 13 | + protected $hidden = ['password', 'remember_token','deleted_at']; |
|
| 14 | + protected $guarded = ['id']; |
|
| 15 | + protected $fillable = ['profile_picture', 'name', 'email', 'password']; |
|
| 16 | + public $searchable = ['name', 'email']; |
|
| 17 | 17 | |
| 18 | - public function getCreatedAtAttribute($value) |
|
| 19 | - { |
|
| 20 | - return \Carbon\Carbon::parse($value)->tz(\Session::get('time-zone'))->toDateTimeString(); |
|
| 21 | - } |
|
| 22 | - |
|
| 23 | - public function getUpdatedAtAttribute($value) |
|
| 24 | - { |
|
| 25 | - return \Carbon\Carbon::parse($value)->tz(\Session::get('time-zone'))->toDateTimeString(); |
|
| 26 | - } |
|
| 27 | - |
|
| 28 | - public function getDeletedAtAttribute($value) |
|
| 29 | - { |
|
| 30 | - return \Carbon\Carbon::parse($value)->tz(\Session::get('time-zone'))->toDateTimeString(); |
|
| 31 | - } |
|
| 32 | - |
|
| 33 | - /** |
|
| 34 | - * Encrypt the password attribute before |
|
| 35 | - * saving it in the storage. |
|
| 36 | - * |
|
| 37 | - * @param string $value |
|
| 38 | - */ |
|
| 39 | - public function setPasswordAttribute($value) |
|
| 40 | - { |
|
| 41 | - $this->attributes['password'] = bcrypt($value); |
|
| 42 | - } |
|
| 43 | - |
|
| 44 | - /** |
|
| 45 | - * Get the entity's notifications. |
|
| 46 | - */ |
|
| 47 | - public function notifications() |
|
| 48 | - { |
|
| 49 | - return $this->morphMany('\App\Modules\Notifications\Notification', 'notifiable')->orderBy('created_at', 'desc'); |
|
| 50 | - } |
|
| 51 | - |
|
| 52 | - /** |
|
| 53 | - * Get the entity's read notifications. |
|
| 54 | - */ |
|
| 55 | - public function readNotifications() |
|
| 56 | - { |
|
| 57 | - return $this->notifications()->whereNotNull('read_at'); |
|
| 58 | - } |
|
| 59 | - |
|
| 60 | - /** |
|
| 61 | - * Get the entity's unread notifications. |
|
| 62 | - */ |
|
| 63 | - public function unreadNotifications() |
|
| 64 | - { |
|
| 65 | - return $this->notifications()->whereNull('read_at'); |
|
| 66 | - } |
|
| 67 | - |
|
| 68 | - public function groups() |
|
| 69 | - { |
|
| 70 | - return $this->belongsToMany('\App\Modules\Acl\AclGroup','users_groups','user_id','group_id')->whereNull('users_groups.deleted_at')->withTimestamps(); |
|
| 71 | - } |
|
| 72 | - |
|
| 73 | - public function oauthClients() |
|
| 74 | - { |
|
| 75 | - return $this->hasMany('App\Modules\Acl\OauthClient', 'user_id'); |
|
| 76 | - } |
|
| 77 | - |
|
| 78 | - /** |
|
| 79 | - * Return fcm device tokens that will be used in sending fcm notifications. |
|
| 80 | - * |
|
| 81 | - * @return array |
|
| 82 | - */ |
|
| 83 | - public function routeNotificationForFCM() |
|
| 84 | - { |
|
| 85 | - $devices = \Core::pushNotificationsDevices()->findBy(['user_id' => $this->id]); |
|
| 86 | - $tokens = []; |
|
| 87 | - |
|
| 88 | - foreach ($devices as $device) |
|
| 89 | - { |
|
| 90 | - $accessToken = decrypt($device->access_token); |
|
| 91 | - |
|
| 92 | - try |
|
| 93 | - { |
|
| 94 | - if (\Core::users()->accessTokenExpiredOrRevoked($accessToken)) |
|
| 95 | - { |
|
| 96 | - continue; |
|
| 97 | - } |
|
| 98 | - |
|
| 99 | - $tokens[] = $device->device_token; |
|
| 100 | - } |
|
| 101 | - catch (\Exception $e) |
|
| 102 | - { |
|
| 103 | - $device->forceDelete(); |
|
| 104 | - } |
|
| 105 | - } |
|
| 106 | - |
|
| 107 | - return $tokens; |
|
| 108 | - } |
|
| 109 | - |
|
| 110 | - /** |
|
| 111 | - * The channels the user receives notification broadcasts on. |
|
| 112 | - * |
|
| 113 | - * @return string |
|
| 114 | - */ |
|
| 115 | - public function receivesBroadcastNotificationsOn() |
|
| 116 | - { |
|
| 117 | - return 'users.' . $this->id; |
|
| 118 | - } |
|
| 119 | - |
|
| 120 | - /** |
|
| 121 | - * Custom password validation. |
|
| 122 | - * |
|
| 123 | - * @param string $password |
|
| 124 | - * @return boolean |
|
| 125 | - */ |
|
| 126 | - public function validateForPassportPasswordGrant($password) |
|
| 127 | - { |
|
| 128 | - if ($password == config('skeleton.social_pass')) |
|
| 129 | - { |
|
| 130 | - return true; |
|
| 131 | - } |
|
| 132 | - |
|
| 133 | - return \Hash::check($password, $this->password); |
|
| 134 | - } |
|
| 18 | + public function getCreatedAtAttribute($value) |
|
| 19 | + { |
|
| 20 | + return \Carbon\Carbon::parse($value)->tz(\Session::get('time-zone'))->toDateTimeString(); |
|
| 21 | + } |
|
| 22 | + |
|
| 23 | + public function getUpdatedAtAttribute($value) |
|
| 24 | + { |
|
| 25 | + return \Carbon\Carbon::parse($value)->tz(\Session::get('time-zone'))->toDateTimeString(); |
|
| 26 | + } |
|
| 27 | + |
|
| 28 | + public function getDeletedAtAttribute($value) |
|
| 29 | + { |
|
| 30 | + return \Carbon\Carbon::parse($value)->tz(\Session::get('time-zone'))->toDateTimeString(); |
|
| 31 | + } |
|
| 32 | + |
|
| 33 | + /** |
|
| 34 | + * Encrypt the password attribute before |
|
| 35 | + * saving it in the storage. |
|
| 36 | + * |
|
| 37 | + * @param string $value |
|
| 38 | + */ |
|
| 39 | + public function setPasswordAttribute($value) |
|
| 40 | + { |
|
| 41 | + $this->attributes['password'] = bcrypt($value); |
|
| 42 | + } |
|
| 43 | + |
|
| 44 | + /** |
|
| 45 | + * Get the entity's notifications. |
|
| 46 | + */ |
|
| 47 | + public function notifications() |
|
| 48 | + { |
|
| 49 | + return $this->morphMany('\App\Modules\Notifications\Notification', 'notifiable')->orderBy('created_at', 'desc'); |
|
| 50 | + } |
|
| 51 | + |
|
| 52 | + /** |
|
| 53 | + * Get the entity's read notifications. |
|
| 54 | + */ |
|
| 55 | + public function readNotifications() |
|
| 56 | + { |
|
| 57 | + return $this->notifications()->whereNotNull('read_at'); |
|
| 58 | + } |
|
| 59 | + |
|
| 60 | + /** |
|
| 61 | + * Get the entity's unread notifications. |
|
| 62 | + */ |
|
| 63 | + public function unreadNotifications() |
|
| 64 | + { |
|
| 65 | + return $this->notifications()->whereNull('read_at'); |
|
| 66 | + } |
|
| 67 | + |
|
| 68 | + public function groups() |
|
| 69 | + { |
|
| 70 | + return $this->belongsToMany('\App\Modules\Acl\AclGroup','users_groups','user_id','group_id')->whereNull('users_groups.deleted_at')->withTimestamps(); |
|
| 71 | + } |
|
| 72 | + |
|
| 73 | + public function oauthClients() |
|
| 74 | + { |
|
| 75 | + return $this->hasMany('App\Modules\Acl\OauthClient', 'user_id'); |
|
| 76 | + } |
|
| 77 | + |
|
| 78 | + /** |
|
| 79 | + * Return fcm device tokens that will be used in sending fcm notifications. |
|
| 80 | + * |
|
| 81 | + * @return array |
|
| 82 | + */ |
|
| 83 | + public function routeNotificationForFCM() |
|
| 84 | + { |
|
| 85 | + $devices = \Core::pushNotificationsDevices()->findBy(['user_id' => $this->id]); |
|
| 86 | + $tokens = []; |
|
| 87 | + |
|
| 88 | + foreach ($devices as $device) |
|
| 89 | + { |
|
| 90 | + $accessToken = decrypt($device->access_token); |
|
| 91 | + |
|
| 92 | + try |
|
| 93 | + { |
|
| 94 | + if (\Core::users()->accessTokenExpiredOrRevoked($accessToken)) |
|
| 95 | + { |
|
| 96 | + continue; |
|
| 97 | + } |
|
| 98 | + |
|
| 99 | + $tokens[] = $device->device_token; |
|
| 100 | + } |
|
| 101 | + catch (\Exception $e) |
|
| 102 | + { |
|
| 103 | + $device->forceDelete(); |
|
| 104 | + } |
|
| 105 | + } |
|
| 106 | + |
|
| 107 | + return $tokens; |
|
| 108 | + } |
|
| 109 | + |
|
| 110 | + /** |
|
| 111 | + * The channels the user receives notification broadcasts on. |
|
| 112 | + * |
|
| 113 | + * @return string |
|
| 114 | + */ |
|
| 115 | + public function receivesBroadcastNotificationsOn() |
|
| 116 | + { |
|
| 117 | + return 'users.' . $this->id; |
|
| 118 | + } |
|
| 119 | + |
|
| 120 | + /** |
|
| 121 | + * Custom password validation. |
|
| 122 | + * |
|
| 123 | + * @param string $password |
|
| 124 | + * @return boolean |
|
| 125 | + */ |
|
| 126 | + public function validateForPassportPasswordGrant($password) |
|
| 127 | + { |
|
| 128 | + if ($password == config('skeleton.social_pass')) |
|
| 129 | + { |
|
| 130 | + return true; |
|
| 131 | + } |
|
| 132 | + |
|
| 133 | + return \Hash::check($password, $this->password); |
|
| 134 | + } |
|
| 135 | 135 | |
| 136 | - public static function boot() |
|
| 137 | - { |
|
| 138 | - parent::boot(); |
|
| 139 | - $this->observe(\App::make('App\Modules\Acl\ModelObservers\AclUserObserver')); |
|
| 140 | - } |
|
| 136 | + public static function boot() |
|
| 137 | + { |
|
| 138 | + parent::boot(); |
|
| 139 | + $this->observe(\App::make('App\Modules\Acl\ModelObservers\AclUserObserver')); |
|
| 140 | + } |
|
| 141 | 141 | } |