ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
loginuserpass.php
Go to the documentation of this file.
1 <?php
2 
12 // Retrieve the authentication state
13 if (!array_key_exists('AuthState', $_REQUEST)) {
14  throw new SimpleSAML_Error_BadRequest('Missing AuthState parameter.');
15 }
16 $authStateId = $_REQUEST['AuthState'];
18 
20 if ($source === NULL) {
21  throw new Exception('Could not find authentication source with id ' . $state[sspmod_core_Auth_UserPassBase::AUTHID]);
22 }
23 
24 
25 if (array_key_exists('username', $_REQUEST)) {
26  $username = $_REQUEST['username'];
27 } elseif ($source->getRememberUsernameEnabled() && array_key_exists($source->getAuthId() . '-username', $_COOKIE)) {
28  $username = $_COOKIE[$source->getAuthId() . '-username'];
29 } elseif (isset($state['core:username'])) {
30  $username = (string)$state['core:username'];
31 } else {
32  $username = '';
33 }
34 
35 if (array_key_exists('password', $_REQUEST)) {
36  $password = $_REQUEST['password'];
37 } else {
38  $password = '';
39 }
40 
41 $errorCode = NULL;
42 $errorParams = NULL;
43 
44 if (!empty($_REQUEST['username']) || !empty($password)) {
45  // Either username or password set - attempt to log in
46 
47  if (array_key_exists('forcedUsername', $state)) {
48  $username = $state['forcedUsername'];
49  }
50 
51  if ($source->getRememberUsernameEnabled()) {
53  $params = $sessionHandler->getCookieParams();
54  $params['expire'] = time();
55  $params['expire'] += (isset($_REQUEST['remember_username']) && $_REQUEST['remember_username'] == 'Yes' ? 31536000 : -300);
56  \SimpleSAML\Utils\HTTP::setCookie($source->getAuthId() . '-username', $username, $params, FALSE);
57  }
58 
59  if ($source->isRememberMeEnabled()) {
60  if (array_key_exists('remember_me', $_REQUEST) && $_REQUEST['remember_me'] === 'Yes') {
61  $state['RememberMe'] = TRUE;
63  }
64  }
65 
66  try {
68  } catch (SimpleSAML_Error_Error $e) {
69  /* Login failed. Extract error code and parameters, to display the error. */
70  $errorCode = $e->getErrorCode();
72  }
73 }
74 
76 $t = new SimpleSAML_XHTML_Template($globalConfig, 'core:loginuserpass.php');
77 $t->data['stateparams'] = array('AuthState' => $authStateId);
78 if (array_key_exists('forcedUsername', $state)) {
79  $t->data['username'] = $state['forcedUsername'];
80  $t->data['forceUsername'] = TRUE;
81  $t->data['rememberUsernameEnabled'] = FALSE;
82  $t->data['rememberUsernameChecked'] = FALSE;
83  $t->data['rememberMeEnabled'] = $source->isRememberMeEnabled();
84  $t->data['rememberMeChecked'] = $source->isRememberMeChecked();
85 } else {
86  $t->data['username'] = $username;
87  $t->data['forceUsername'] = FALSE;
88  $t->data['rememberUsernameEnabled'] = $source->getRememberUsernameEnabled();
89  $t->data['rememberUsernameChecked'] = $source->getRememberUsernameChecked();
90  $t->data['rememberMeEnabled'] = $source->isRememberMeEnabled();
91  $t->data['rememberMeChecked'] = $source->isRememberMeChecked();
92  if (isset($_COOKIE[$source->getAuthId() . '-username'])) $t->data['rememberUsernameChecked'] = TRUE;
93 }
94 $t->data['links'] = $source->getLoginLinks();
95 $t->data['errorcode'] = $errorCode;
97 $t->data['errorparams'] = $errorParams;
98 
99 if (isset($state['SPMetadata'])) {
100  $t->data['SPMetadata'] = $state['SPMetadata'];
101 } else {
102  $t->data['SPMetadata'] = NULL;
103 }
104 
105 $t->show();
106 exit();
107 
$params
Definition: disable.php:11
static handleLogin($authStateId, $username, $password)
Handle login request.
Add rich text string
$_COOKIE['client_id']
Definition: server.php:9
static getAllErrorCodeMessages()
Get a map of both errorcode titles and descriptions.
Definition: ErrorCodes.php:135
$password
Definition: pwgen.php:17
const AUTHID
The key of the AuthId field in the state.
static setCookie($name, $value, $params=null, $throw=true)
Set a cookie.
Definition: HTTP.php:1107
const STAGEID
The string used to identify our states.
$errorParams
static loadState($id, $stage, $allowMissing=false)
Retrieve saved state.
Definition: State.php:259
if(!array_key_exists('AuthState', $_REQUEST)) $authStateId
Create styles array
The data for the language used.
static getSessionHandler()
This function retrieves the current instance of the session handler.
$source
$errorCode
if(!empty($_REQUEST['username'])||!empty($password)) $globalConfig
getParameters()
Retrieve the error parameters given when throwing this error.
Definition: Error.php:140
Add data(end) time
Method that wraps PHPs time in order to allow simulations with the workflow.
$state
static getById($authId, $type=null)
Retrieve authentication source.
Definition: Source.php:324
getErrorCode()
Retrieve the error code given when throwing this error.
Definition: Error.php:129
static saveState(&$state, $stage, $rawId=false)
Save the state.
Definition: State.php:194
static getInstance($instancename='simplesaml')
Get a configuration file by its instance name.