@@ -232,6 +232,16 @@ abstract protected function newResultFromChallengeResponse(
232
232
final protected function newAutomaticControl (
233
233
PhabricatorAuthFactorResult $ result ) {
234
234
235
+ $ is_error = $ result ->getIsError ();
236
+ if ($ is_error ) {
237
+ return $ this ->newErrorControl ($ result );
238
+ }
239
+
240
+ $ is_continue = $ result ->getIsContinue ();
241
+ if ($ is_continue ) {
242
+ return $ this ->newContinueControl ($ result );
243
+ }
244
+
235
245
$ is_answered = (bool )$ result ->getAnsweredChallenge ();
236
246
if ($ is_answered ) {
237
247
return $ this ->newAnsweredControl ($ result );
@@ -271,6 +281,34 @@ private function newAnsweredControl(
271
281
pht ('You responded to this challenge correctly. ' ));
272
282
}
273
283
284
+ private function newErrorControl (
285
+ PhabricatorAuthFactorResult $ result ) {
286
+
287
+ $ error = $ result ->getErrorMessage ();
288
+
289
+ $ icon = id (new PHUIIconView ())
290
+ ->setIcon ('fa-times ' , 'red ' );
291
+
292
+ return id (new PHUIFormTimerControl ())
293
+ ->setIcon ($ icon )
294
+ ->appendChild ($ error )
295
+ ->setError (pht ('Error ' ));
296
+ }
297
+
298
+ private function newContinueControl (
299
+ PhabricatorAuthFactorResult $ result ) {
300
+
301
+ $ error = $ result ->getErrorMessage ();
302
+
303
+ $ icon = id (new PHUIIconView ())
304
+ ->setIcon ('fa-commenting ' , 'green ' );
305
+
306
+ return id (new PHUIFormTimerControl ())
307
+ ->setIcon ($ icon )
308
+ ->appendChild ($ error );
309
+ }
310
+
311
+
274
312
275
313
/* -( Synchronizing New Factors )------------------------------------------ */
276
314
@@ -400,4 +438,86 @@ final protected function getChallengeForCurrentContext(
400
438
return null ;
401
439
}
402
440
441
+
442
+ /**
443
+ * @phutil-external-symbol class QRcode
444
+ */
445
+ final protected function newQRCode ($ uri ) {
446
+ $ root = dirname (phutil_get_library_root ('phabricator ' ));
447
+ require_once $ root .'/externals/phpqrcode/phpqrcode.php ' ;
448
+
449
+ $ lines = QRcode::text ($ uri );
450
+
451
+ $ total_width = 240 ;
452
+ $ cell_size = floor ($ total_width / count ($ lines ));
453
+
454
+ $ rows = array ();
455
+ foreach ($ lines as $ line ) {
456
+ $ cells = array ();
457
+ for ($ ii = 0 ; $ ii < strlen ($ line ); $ ii ++) {
458
+ if ($ line [$ ii ] == '1 ' ) {
459
+ $ color = '#000 ' ;
460
+ } else {
461
+ $ color = '#fff ' ;
462
+ }
463
+
464
+ $ cells [] = phutil_tag (
465
+ 'td ' ,
466
+ array (
467
+ 'width ' => $ cell_size ,
468
+ 'height ' => $ cell_size ,
469
+ 'style ' => 'background: ' .$ color ,
470
+ ),
471
+ '' );
472
+ }
473
+ $ rows [] = phutil_tag ('tr ' , array (), $ cells );
474
+ }
475
+
476
+ return phutil_tag (
477
+ 'table ' ,
478
+ array (
479
+ 'style ' => 'margin: 24px auto; ' ,
480
+ ),
481
+ $ rows );
482
+ }
483
+
484
+ final protected function throwResult (PhabricatorAuthFactorResult $ result ) {
485
+ throw new PhabricatorAuthFactorResultException ($ result );
486
+ }
487
+
488
+ final protected function getInstallDisplayName () {
489
+ $ uri = PhabricatorEnv::getURI ('/ ' );
490
+ $ uri = new PhutilURI ($ uri );
491
+ return $ uri ->getDomain ();
492
+ }
493
+
494
+ final protected function getChallengeResponseParameterName (
495
+ PhabricatorAuthFactorConfig $ config ) {
496
+ return $ this ->getParameterName ($ config , 'mfa.response ' );
497
+ }
498
+
499
+ final protected function getChallengeResponseFromRequest (
500
+ PhabricatorAuthFactorConfig $ config ,
501
+ AphrontRequest $ request ) {
502
+
503
+ $ name = $ this ->getChallengeResponseParameterName ($ config );
504
+
505
+ $ value = $ request ->getStr ($ name );
506
+ $ value = (string )$ value ;
507
+ $ value = trim ($ value );
508
+
509
+ return $ value ;
510
+ }
511
+
512
+ final protected function hasCSRF (PhabricatorAuthFactorConfig $ config ) {
513
+ $ engine = $ config ->getSessionEngine ();
514
+ $ request = $ engine ->getRequest ();
515
+
516
+ if (!$ request ->isHTTPPost ()) {
517
+ return false ;
518
+ }
519
+
520
+ return $ request ->validateCSRF ();
521
+ }
522
+
403
523
}
0 commit comments