twig = $twig; $this->environment = $environment; } /** * @param Request $request * * @return View_Response * * @throws API_Authorization_Exception * @throws API_Exception * @throws Account_Exception * @throws User_Not_Found_Exception */ public function show_offline_codes( Request $request ) { $user_id = $this->storage->get_user_storage()->get_user_id(); $user = $this->api_wrapper->get_integration_user_by_external_id( $user_id ); $user_storage = $this->storage->get_user_storage(); $offline_codes = $user_storage->get_offline_codes(); $data = array(); $data['quantity'] = isset( $offline_codes['quantity'] ) ? $offline_codes['quantity'] : 0; $data['date'] = isset( $offline_codes['time'] ) ? $offline_codes['time'] : null; $data['offline_codes_count'] = $user->getBackupCodesCount(); $data['active_tab'] = 'offline_codes'; $status_data = $this->get_user_status_data(); $data = array_merge( $data, $status_data ); $client = $this->api_wrapper->get_client(); $data['has_client_card'] = $client->hasCard(); $data['filename'] = '2FAS_offline_codes.txt'; return $this->render( Views::BACKUP_CODES, $data ); } /** * @param Request $request * * @return Redirection_Response * * @throws User_Not_Found_Exception */ public function enable( Request $request ) { $user_storage = $this->storage->get_user_storage(); $user_storage->enable_offline_codes(); $this->flash->add_message( 'success', 'offline-codes-enabled' ); return $this->redirect( Route::SUBMENU_CHANNEL, Route::ACTION_CONFIGURE_OFFLINE_CODES ); } /** * @param Request $request * * @return Redirection_Response * * @throws User_Not_Found_Exception */ public function disable( Request $request ) { $user_storage = $this->storage->get_user_storage(); $user_storage->disable_offline_codes(); $this->flash->add_message( 'success', 'offline-codes-disabled' ); return $this->redirect( Route::SUBMENU_CHANNEL, Route::ACTION_CONFIGURE_OFFLINE_CODES ); } /** * @param Request $request * * @return JSON_Response * * @throws API_Authorization_Exception * @throws API_Exception * @throws User_Not_Found_Exception */ public function generate( Request $request ) { $user_storage = $this->storage->get_user_storage(); $integration_user = $this->api_wrapper->get_integration_user_by_external_id( $user_storage->get_user_id() ); $backup_codes = $this->api_wrapper->regenerate_backup_codes( $integration_user ); $codes = $backup_codes->getCodes(); $offline_codes = array( 'quantity' => count( $codes ), 'time' => time(), ); $user_storage->set_offline_codes( $offline_codes ); $user_storage->enable_offline_codes(); return $this->json( array( 'codes' => $codes ), 201 ); } /** * @param Request $request */ public function print_codes( Request $request ) { $data = array(); $data['title'] = 'Print your 2FAS offline codes'; $data['app_name'] = $this->environment->get_wordpress_app_name(); $data['codes'] = $request->post( 'code' ); echo $this->twig->get_view( Views::PRINT_BACKUP_CODES, $data ); exit; } }