Elgg  Version 2.2
 All Classes Namespaces Files Functions Variables Pages
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
register_translations($path, $load_all=false, $language=null)
When given a full path, finds translation files and loads them.
Definition: languages.php:70
elgg_echo($message_key, $args=array(), $language="")
Given a message key, returns an appropriately translated full-text string.
Definition: languages.php:21
$e
Definition: metadata.php:12
elgg_get_session()
Gets Elgg's session object.
Definition: sessions.php:23
get_user_by_username($username)
Get user by username.
Definition: users.php:98
register_error($error)
Display an error on next page load.
Definition: elgglib.php:452
$params
Definition: login.php:72
$persistent
Definition: login.php:26
$username
Definition: login.php:24
get_input($variable, $default=null, $filter_result=true)
Get some input from variables passed submitted through GET or POST.
Definition: input.php:27
const REFERER
Definition: elgglib.php:2029
$users
Definition: newest.php:3
elgg_trigger_plugin_hook($hook, $type, $params=null, $returnvalue=null)
Definition: elgglib.php:801
$password
Definition: login.php:25
$forward_source
Definition: login.php:21
$result
Definition: login.php:27
forward($location="", $reason= 'system')
Forward to $location.
Definition: elgglib.php:93
elgg_authenticate($username, $password)
Perform user authentication with a given username and password.
Definition: sessions.php:136
$forward_url
Definition: login.php:73
if($result!==true) $user
Definition: login.php:45
login(\ElggUser $user, $persistent=false)
Logs in a specified .
Definition: sessions.php:320
$session
Definition: login.php:9
system_message($message)
Display a system message on next page load.
Definition: elgglib.php:438