| 1 |  |  | <?php namespace Distilleries\Expendable\Models; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | use Distilleries\Expendable\Contracts\LockableContract; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  | use Distilleries\Expendable\Helpers\UserUtils; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | use Distilleries\Expendable\Mails\ResetPasswordNotification; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | use Distilleries\PermissionUtil\Contracts\PermissionUtilContract; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | use Illuminate\Auth\Authenticatable; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | use Illuminate\Auth\Passwords\CanResetPassword; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  | use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  | use Illuminate\Contracts\Auth\CanResetPassword as CanResetPasswordContract; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  | use Illuminate\Foundation\Auth\Access\Authorizable; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  | use Illuminate\Notifications\Notifiable; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  | class User extends BaseModel implements AuthenticatableContract, CanResetPasswordContract, PermissionUtilContract, LockableContract { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |     use Authenticatable, Authorizable, CanResetPassword, \Distilleries\Expendable\Models\StatusTrait, LockableTrait; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                            
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |     use Notifiable; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |     protected $tabPermission = []; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |     protected $fillable = [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |         'email', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |         'password', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |         'status', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |         'role_id' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |     ]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |      * The attributes excluded from the model's JSON form. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |      * @var array | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |     protected $hidden = ['password', 'remember_token']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 | 146 |  |     public function role() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 | 146 |  |         return $this->belongsTo('Distilleries\Expendable\Models\Role'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 | 188 |  |     public static function boot() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 | 188 |  |         parent::boot(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 | 188 |  |         self::observe(new \Distilleries\Expendable\Observers\PasswordObserver); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 | 128 |  |     public function hasAccess($key) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 | 128 |  |         if (!empty($this->role->overide_permission)) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |         { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 | 126 |  |             return true; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 | 2 |  |         return UserUtils::hasAccess($key); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 56 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 57 | 10 |  |     public function getFirstRedirect($left) | 
            
                                                                        
                            
            
                                    
            
            
                | 58 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 59 | 10 |  |         foreach ($left as $item) | 
            
                                                                        
                            
            
                                    
            
            
                | 60 |  |  |         { | 
            
                                                                        
                            
            
                                    
            
            
                | 61 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 62 | 10 |  |             if (!empty($item['action']) && $this->hasAccess($item['action'])) | 
            
                                                                        
                            
            
                                    
            
            
                | 63 |  |  |             { | 
            
                                                                        
                            
            
                                    
            
            
                | 64 | 8 |  |                 return preg_replace('/\/index/i', '', action($item['action'])); | 
            
                                                                        
                            
            
                                    
            
            
                | 65 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 66 | 2 |  |             } else if (!empty($item['submenu'])) | 
            
                                                                        
                            
            
                                    
            
            
                | 67 |  |  |             { | 
            
                                                                        
                            
            
                                    
            
            
                | 68 | 2 |  |                 $redirect = $this->getFirstRedirect($item['submenu']); | 
            
                                                                        
                            
            
                                    
            
            
                | 69 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 70 | 2 |  |                 if (!empty($redirect)) | 
            
                                                                        
                            
            
                                    
            
            
                | 71 |  |  |                 { | 
            
                                                                        
                            
            
                                    
            
            
                | 72 |  |  |                     return $redirect; | 
            
                                                                        
                            
            
                                    
            
            
                | 73 |  |  |                 } | 
            
                                                                        
                            
            
                                    
            
            
                | 74 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 75 |  |  |             } | 
            
                                                                        
                            
            
                                    
            
            
                | 76 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 77 |  |  |         } | 
            
                                                                        
                            
            
                                    
            
            
                | 78 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 79 | 2 |  |         return ''; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  |      * Send the password reset notification. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  |      * @param  string  $token | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  |      * @return void | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 | 2 |  |     public function sendPasswordResetNotification($token) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 | 2 |  |         $this->notify(new ResetPasswordNotification($token)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  |  | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 94 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 95 |  |  |  |