Ejemplo n.º 1
0
 /**
  * Saves/Edits an account
  *
  */
 public function postEdit($id = false)
 {
     if ($id !== false) {
         $account = CloudAccount::where('user_id', Auth::id())->findOrFail($id);
     }
     try {
         if (empty($account)) {
             $account = new CloudAccount();
         } else {
             if ($account->user_id !== Auth::id()) {
                 throw new Exception('general.access_denied');
             }
         }
         $account->name = Input::get('name');
         $account->cloudProvider = Input::get('cloudProvider');
         $account->credentials = json_encode(Input::get('credentials'));
         $account->user_id = Auth::id();
         // logged in user id
         $conStatus = CloudProvider::authenticate($account);
         if ($conStatus == 1) {
             Log::info('Credentials are encrypted before saving to DB.');
             CloudAccountHelper::save($account);
             return Redirect::intended('account')->with('success', Lang::get('account/account.account_updated'));
         } else {
             return Redirect::to('account')->with('error', Lang::get('account/account.account_auth_failed') . ' for ' . $account->cloudProvider);
         }
     } catch (Exception $e) {
         Log::error($e);
         return Redirect::to('account')->with('error', $e->getMessage());
     }
 }