MediaWiki master
RememberMeAuthenticationRequest.php
Go to the documentation of this file.
1<?php
7namespace MediaWiki\Auth;
8
11use UnexpectedValueException;
12
23
29 public const CHOOSE_REMEMBER = 'choose';
30
35 public const FORCE_CHOOSE_REMEMBER = 'force-choose';
36
40 public const ALWAYS_REMEMBER = 'always';
41
45 public const NEVER_REMEMBER = 'never';
46
50 public const ALLOWED_FLAGS = [
55 ];
56
63
70 public $skippable = true;
71
73 private $checkbox = false;
74
79 protected $expiration = null;
80
82 public $rememberMe = false;
83
88 public function __construct( string $flag = self::CHOOSE_REMEMBER ) {
90 $provider = RequestContext::getMain()->getRequest()->getSession()->getProvider();
91 '@phan-var SessionProvider $provider';
92
93 switch ( $flag ) {
95 $this->skippable = true;
96 $this->checkbox = true;
97 $this->expiration = $provider->getRememberUserDuration();
98 break;
100 $this->skippable = false;
101 $this->checkbox = true;
102 $this->expiration = $provider->getRememberUserDuration();
103 break;
105 $this->skippable = true;
106 $this->checkbox = false;
107 $this->expiration = $provider->getRememberUserDuration();
108 break;
110 $this->skippable = true;
111 $this->checkbox = false;
112 $this->expiration = null;
113 break;
114 default:
115 throw new UnexpectedValueException( '$flag must be one of the values: \'' .
116 implode( "', '", self::ALLOWED_FLAGS ) . '\'' );
117 }
118 }
119
124 public function getFieldInfo() {
125 if ( !$this->expiration || !$this->checkbox ) {
126 return [];
127 }
128
129 $expirationDays = ceil( $this->expiration / ( 3600 * 24 ) );
130 return [
131 'rememberMe' => [
132 'type' => 'checkbox',
133 'label' => wfMessage( 'userlogin-remembermypassword' )->numParams( $expirationDays ),
134 'help' => wfMessage( 'authmanager-userlogin-remembermypassword-help' ),
135 'optional' => true,
136 'skippable' => $this->skippable,
137 ]
138 ];
139 }
140}
wfMessage( $key,... $params)
This is the function for getting translated interface messages.
This is a value object for authentication requests.
const OPTIONAL
Indicates that the request is not required for authentication to proceed.
This is an authentication request added by AuthManager to show a "remember me" checkbox.
const CHOOSE_REMEMBER
Indicates that the user may be able to choose whether to be remembered or not.
const ALWAYS_REMEMBER
Indicates that the user will always be remembered.
bool $required
Whether this field must be filled in on the form.
int null $expiration
How long the user will be remembered, in seconds.
getFieldInfo()
Fetch input field info.This will be used in the AuthManager APIs and web UIs to define API input para...
const FORCE_CHOOSE_REMEMBER
Indicates that the user will be able to choose whether to be remembered or not.
bool $skippable
Whether display of this field can be skipped, accepting the default value, if there are no other fiel...
const NEVER_REMEMBER
Indicates that the user will never be remembered.
Group all the pieces relevant to the context of a request into one instance.
A SessionProvider provides SessionInfo and support for Session.