Пример #1
0
 protected function auth($key)
 {
     if (!Session::has('user')) {
         return false;
     }
     $success = true;
     $uid = Session::get('user');
     $user = User::find($uid);
     $permissions = $user->userType->permissions;
     $perms = [];
     foreach ($permissions as $perm) {
         $perms[] = $perm->name;
     }
     if (is_array($key)) {
         foreach ($key as $k) {
             if (!in_array($k, $perms)) {
                 $success = false;
             }
         }
     } else {
         if (!in_array($key, $perms)) {
             $success = false;
         }
     }
     return $success;
 }
Пример #2
0
 public function doSaveProfile()
 {
     $input = Input::all();
     $user = User::find($input['id']);
     //cleanup input
     unset($input['_token']);
     unset($input['id']);
     $utype = UserType::find($input['userType']);
     unset($input['userType']);
     foreach ($input as $k => $v) {
         $user->{$k} = $v;
     }
     if ($user->userType->id != $utype->id) {
         $user->userType()->dissociate();
         $user->userType()->associate($utype);
     }
     $user->save();
     return redirect()->back();
 }
Пример #3
0
 /**
  *
  * Plugin Helper Functions
  *
  *    The functions below here are intended to make it easier for programmers to extend the Cmstwo framework.
  * They provide easy and secure access to the models, without exposing the model classes themselves.
  *
  */
 public static function getUser($id = null, $name = null)
 {
     if ($id == null && $name == null) {
         if (Session::has('user')) {
             $id = Session::get('user');
             $user = User::find($id);
         } else {
             return false;
         }
     }
     if ($id != null) {
         $user = User::find($id);
     } else {
         $user = User::where('username', $name)->first();
     }
     $out = new \stdClass();
     $out->name = $user->name;
     $out->email = $user->email;
     $out->data = $user->data;
     $out->type = $user->userType->name;
     $out->perms = $user->userType->permissions;
     return $out;
 }