Ejemplo n.º 1
0
 public function postTotpSettings(Request $request)
 {
     if (Totp::verify($request, false)) {
         if (!empty(Input::get('reset'))) {
             Auth::user()->set('totp_secret', false);
             Auth::user()->set('totp_enable', 0);
             return redirect('/auth/totp')->with('success', 'Secret key removed! Now you can re-enable 2FA with new one.');
         }
         Auth::user()->set('totp_enable', Input::get('totp_enable'));
         return redirect('/auth/totp')->with('success', 'Successfully saved!');
     } else {
         return Totp::error($request);
     }
 }
Ejemplo n.º 2
0
 public function postWithdrawal($wallet_id, Request $request)
 {
     if (Totp::configured()) {
         if (Totp::verify($request, false)) {
             $wallet = WalletsAddress::where('wallet_id', $wallet_id)->where('user_id', Auth::user()->id)->leftJoin('wallets', 'wallets.id', '=', 'wallet_id')->first();
             if ($wallet) {
                 if ($wallet->balance >= Input::get('balance')) {
                     $validate_address = $wallet->wallet->command('validateaddress', [Input::get('address')]);
                     if (!empty($validate_address->isvalid) && $validate_address->isvalid === true) {
                         $withdrawal = new WalletsWithdrawal();
                         $withdrawal->address = Input::get('address');
                         $withdrawal->amount = Input::get('balance');
                         $withdrawal->wallet_id = $wallet->wallet_id;
                         $withdrawal->user_id = $wallet->user_id;
                         $withdrawal->save();
                         $wallet->withdrawal(Input::get('balance'));
                         Cache::tags('user' . $wallet->user_id)->forget('wallets');
                         return redirect('/user/wallets')->with('success', 'Withdrawal successfully queued!');
                     } else {
                         if (!empty($validate_address->error)) {
                             Log::error('Wallet error #' . $wallet->wallet_id . ' - ' . $wallet->short, [$validate_address->error]);
                             return back()->withErrors('Please try again later!');
                         } else {
                             return back()->withErrors(Input::get('address') . ' is not valid ' . $wallet->title . ' address.');
                         }
                     }
                 } else {
                     return back()->withErrors('Not enough balace to withdrawal ' . Input::get('balance') . ' ' . $wallet->short);
                 }
             } else {
                 return back()->withErrors('Wallet not found');
             }
         } else {
             return Totp::error($request);
         }
     } else {
         return redirect('/auth/totp')->withErrors('Before withdrawal you must <a href="/auth/totp">configure One-Time password</a>!');
     }
 }