Elgg  Version 1.11
login.php
Go to the documentation of this file.
1 <?php
10 
11 // set forward url
12 if ($session->has('last_forward_from')) {
13  $forward_url = $session->get('last_forward_from');
14  $forward_source = 'last_forward_from';
15 } elseif (get_input('returntoreferer')) {
17  $forward_source = 'return_to_referer';
18 } else {
19  // forward to main index page
20  $forward_url = '';
22 }
23 
24 $username = get_input('username');
25 $password = get_input('password', null, false);
26 $persistent = (bool) get_input("persistent");
27 $result = false;
28 
29 if (empty($username) || empty($password)) {
30  register_error(elgg_echo('login:empty'));
31  forward();
32 }
33 
34 // check if logging in with email address
35 if (strpos($username, '@') !== false && ($users = get_user_by_email($username))) {
36  $username = $users[0]->username;
37 }
38 
40 if ($result !== true) {
43 }
44 
46 if (!$user) {
47  register_error(elgg_echo('login:baduser'));
49 }
50 
51 try {
53  // re-register at least the core language file for users with language other than site default
54  register_translations(dirname(dirname(__FILE__)) . "/languages/");
55 } catch (LoginException $e) {
56  register_error($e->getMessage());
58 }
59 
60 // elgg_echo() caches the language and does not provide a way to change the language.
61 // @todo we need to use the config object to store this so that the current language
62 // can be changed. Refs #4171
63 if ($user->language) {
64  $message = elgg_echo('loginok', array(), $user->language);
65 } else {
66  $message = elgg_echo('loginok');
67 }
68 
69 // clear after login in case login fails
70 $session->remove('last_forward_from');
71 
72 $params = array('user' => $user, 'source' => $forward_source);
74 
get_user_by_email($email)
Get an array of users from an email address.
Definition: users.php:120
get_input($variable, $default=null, $filter_result=true)
Get some input from variables passed submitted through GET or POST.
Definition: input.php:27
$e
Definition: metadata.php:12
elgg_get_session()
Gets Elgg&#39;s session object.
Definition: sessions.php:23
elgg forward
Meant to mimic the php forward() function by simply redirecting the user to another page...
Definition: elgglib.js:419
get_user_by_username($username)
Get user by username.
Definition: users.php:98
$params
Definition: login.php:72
$persistent
Definition: login.php:26
elgg_echo($message_key, $args=array(), $language="")
Given a message key, returns an appropriately translated full-text string.
Definition: languages.php:21
$username
Definition: login.php:24
const REFERER
Definition: elgglib.php:1995
$users
Definition: newest.php:3
elgg_trigger_plugin_hook($hook, $type, $params=null, $returnvalue=null)
Definition: elgglib.php:775
$password
Definition: login.php:25
elgg system_message
Wrapper function for system_messages.
Definition: elgglib.js:374
$forward_source
Definition: login.php:21
$result
Definition: login.php:27
elgg_authenticate($username, $password)
Perform user authentication with a given username and password.
Definition: sessions.php:136
elgg register_error
Wrapper function for system_messages.
Definition: elgglib.js:383
$forward_url
Definition: login.php:73
if($result!==true) $user
Definition: login.php:45
register_translations($path, $load_all=false)
When given a full path, finds translation files and loads them.
Definition: languages.php:140
login(\ElggUser $user, $persistent=false)
Logs in a specified .
Definition: sessions.php:320
$session
Definition: login.php:9