/**
  * Stores new account
  *
  */
 public function save($bankAccountPublicId = false)
 {
     $account = Auth::user()->account;
     $bankId = Input::get('bank_id');
     $username = Input::get('bank_username');
     $rules = ['bank_id' => $bankAccountPublicId ? '' : 'required', 'bank_username' => 'required'];
     $validator = Validator::make(Input::all(), $rules);
     if ($validator->fails()) {
         return Redirect::to('bank_accounts/create')->withErrors($validator)->withInput();
     } else {
         if ($bankAccountPublicId) {
             $bankAccount = BankAccount::scope($bankAccountPublicId)->firstOrFail();
         } else {
             $bankAccount = BankAccount::createNew();
             $bankAccount->bank_id = $bankId;
         }
         if ($username != str_repeat('*', strlen($username))) {
             $bankAccount->username = Crypt::encrypt(trim($username));
         }
         if ($bankAccountPublicId) {
             $bankAccount->save();
             $message = trans('texts.updated_bank_account');
         } else {
             $account->bank_accounts()->save($bankAccount);
             $message = trans('texts.created_bank_account');
         }
         Session::flash('message', $message);
         return Redirect::to("bank_accounts/{$bankAccount->public_id}/edit");
     }
 }
 public function validateAccount()
 {
     $publicId = Input::get('public_id');
     $username = trim(Input::get('bank_username'));
     $password = trim(Input::get('bank_password'));
     if ($publicId) {
         $bankAccount = BankAccount::scope($publicId)->firstOrFail();
         if ($username != $bankAccount->username) {
             // TODO update username
         }
         $username = Crypt::decrypt($username);
         $bankId = $bankAccount->bank_id;
     } else {
         $bankId = Input::get('bank_id');
     }
     return json_encode($this->bankAccountService->loadBankAccounts($bankId, $username, $password, $publicId));
 }