OATHRepository = $repository; $this->OATHUser = $user; } /** * Set the page title and add JavaScript RL modules * * @param HTMLForm $form */ public function alterForm( HTMLForm $form ) { $form->setMessagePrefix( 'oathauth' ); $form->setWrapperLegend( false ); $form->getOutput()->setPagetitle( $this->msg( 'oathauth-enable' ) ); $form->getOutput()->addModules( 'ext.oathauth' ); } /** * @return string */ protected function getDisplayFormat() { return 'vform'; } /** * @return bool */ public function requiresUnblock() { return false; } /** * Require users to be logged in * * @param User $user * * @return bool|void */ protected function checkExecutePermissions( User $user ) { parent::checkExecutePermissions( $user ); $this->requireLogin(); } /** * @return array[] */ protected function getFormFields() { $key = $this->getRequest()->getSessionData( 'oathauth_key' ); if ( $key === null ) { $key = OATHAuthKey::newFromRandom(); $this->getRequest()->setSessionData( 'oathauth_key', $key ); } $secret = $key->getSecret(); $this->getOutput()->addHTML( ResourceLoader::makeInlineScript( Xml::encodeJsCall( 'mw.loader.using', array( array( 'ext.oathauth' ), new XmlJsCode( 'function () {' . '$("#qrcode").qrcode("otpauth://totp/' . $this->OATHUser->getAccount() . '?secret=' . $secret. '");' . '}' ) ) ) ) ); return array( 'app' => array( 'type' => 'info', 'default' => $this->msg( 'oathauth-step1-test' )->escaped(), 'raw' => true, 'section' => 'step1', ), 'qrcode' => array( 'type' => 'info', 'default' => '
', 'raw' => true, 'section' => 'step2', ), 'manual' => array( 'type' => 'info', 'label-message' => 'oathauth-step2alt', 'default' => '' . $this->msg( 'oathauth-account' )->escaped() . '