/** @var Message|null I18n message to display in case of UI or FAIL */
public $message = null;
+ /** @var string Whether the $message is an error or warning message, for styling reasons */
+ public $messageType = 'warning';
+
/**
* @var string|null Local user name from authentication.
* May be null if the authentication passed but no local user is known.
*/
public static function newPass( $username = null ) {
$ret = new AuthenticationResponse;
- $ret->status = AuthenticationResponse::PASS;
+ $ret->status = self::PASS;
$ret->username = $username;
return $ret;
}
*/
public static function newFail( Message $msg ) {
$ret = new AuthenticationResponse;
- $ret->status = AuthenticationResponse::FAIL;
+ $ret->status = self::FAIL;
$ret->message = $msg;
+ $ret->messageType = 'error';
return $ret;
}
*/
public static function newRestart( Message $msg ) {
$ret = new AuthenticationResponse;
- $ret->status = AuthenticationResponse::RESTART;
+ $ret->status = self::RESTART;
$ret->message = $msg;
return $ret;
}
*/
public static function newAbstain() {
$ret = new AuthenticationResponse;
- $ret->status = AuthenticationResponse::ABSTAIN;
+ $ret->status = self::ABSTAIN;
return $ret;
}
/**
* @param AuthenticationRequest[] $reqs AuthenticationRequests needed to continue
* @param Message $msg
+ * @param string $msgtype
* @return AuthenticationResponse
* @see AuthenticationResponse::UI
*/
- public static function newUI( array $reqs, Message $msg ) {
+ public static function newUI( array $reqs, Message $msg, $msgtype = 'warning' ) {
if ( !$reqs ) {
throw new \InvalidArgumentException( '$reqs may not be empty' );
}
+ if ( $msgtype !== 'warning' && $msgtype !== 'error' ) {
+ throw new \InvalidArgumentException( $msgtype . ' is not a valid message type.' );
+ }
$ret = new AuthenticationResponse;
- $ret->status = AuthenticationResponse::UI;
+ $ret->status = self::UI;
$ret->neededRequests = $reqs;
$ret->message = $msg;
+ $ret->messageType = $msgtype;
return $ret;
}
}
$ret = new AuthenticationResponse;
- $ret->status = AuthenticationResponse::REDIRECT;
+ $ret->status = self::REDIRECT;
$ret->neededRequests = $reqs;
$ret->redirectTarget = $redirectTarget;
$ret->redirectApiData = $redirectApiData;