/**
  * Update the specified resource in storage.
  *
  * @return Response
  */
 public function update()
 {
     $user = User::find(Auth::id());
     // If no user found
     if (!$user) {
         Redirect::route('dashboard');
     }
     // If user found
     $inputs = Input::all();
     $validator = User::validate($inputs);
     if ($validator->passes()) {
         $user->name = $inputs['name'];
         $user->email = $inputs['email'];
         if ($inputs['password']) {
             $user->password = Hash::make($inputs['password']);
         }
         //Pushbullet
         if (isset($inputs['pushbullet'])) {
             $pushbullet = new PHPushbullet($inputs['pushbullet_api_key']);
             // Verify API key
             try {
                 $devices = $pushbullet->devices();
             } catch (RequestException $e) {
                 // If error, redirect back with message
                 Session::flash('pushbullet_error', 'Could not connect to Pushbullet. Please verify your API key');
                 return Redirect::back()->withInput();
             }
             // If device defined
             if (isset($inputs['pushbullet_device'])) {
                 $user->pushbullet_device = $inputs['pushbullet_device'];
                 $user->pushbullet = true;
             }
         } else {
             $user->pushbullet = false;
             $user->pushbullet_device = null;
         }
         $user->pushbullet_api_key = $inputs['pushbullet_api_key'];
         $user->save();
         // If trying to enable pushbullet but no devices selected
         if (isset($inputs['pushbullet']) && !$user->pushbullet_device) {
             Session::flash('pushbullet_error', 'Please select device to send notifications');
             return Redirect::back()->withInput();
         } else {
             return Redirect::action('Admin\\AdminUserController@edit');
         }
     } else {
         return Redirect::back()->withInput()->withErrors($validator);
     }
 }
Beispiel #2
0
 /**
  * pushes a report from the given account to the devices
  * @param $reportTitle
  * @param $reportBody
  * @param $account
  */
 public function pushReport($reportTitle, $reportBody, $account)
 {
     $pushKeys = $this->getPushBulletKeys();
     foreach ($pushKeys as $pushKey) {
         if ($pushKey['accounts'] == null || in_array($account, $pushKey['accounts'])) {
             $pushBullet = new PHPushbullet($pushKey['key']);
             if ($pushKey['devices'] == null) {
                 // pushes to all of the devices
                 foreach ($pushBullet->devices() as $device) {
                     $pushBullet->device($device->iden)->note($reportTitle, $reportBody);
                 }
             } else {
                 // pushes to selected devices
                 foreach ($pushKey['devices'] as $device) {
                     $pushBullet->device($device)->note($reportTitle, $reportBody);
                 }
             }
         }
     }
 }