]> git.mxchange.org Git - friendica.git/blob - include/auth.php
some changes
[friendica.git] / include / auth.php
1 <?php
2
3 // login/logout 
4
5 if((x($_SESSION,'authenticated')) && (! ($_POST['auth-params'] == 'login'))) {
6         if($_POST['auth-params'] == 'logout' || $a->module == "logout") {
7                 unset($_SESSION['authenticated']);
8                 unset($_SESSION['uid']);
9                 unset($_SESSION['visitor_id']);
10                 unset($_SESSION['administrator']);
11                 $_SESSION['sysmsg'] = "Logged out." . EOL;
12                 goaway($a->get_baseurl());
13         }
14         if(x($_SESSION,'uid')) {
15                 $r = q("SELECT * FROM `user` WHERE `uid` = %d LIMIT 1",
16                         intval($_SESSION['uid']));
17                 if($r === NULL || (! count($r))) {
18                         goaway($a->get_baseurl());
19                 }
20                 $a->user = $r[0];
21                 if(strlen($a->user['timezone']))
22                         date_default_timezone_set($a->user['timezone']);
23
24         }
25 }
26 else {
27         unset($_SESSION['authenticated']);
28         unset($_SESSION['uid']);
29         unset($_SESSION['visitor_id']);
30         unset($_SESSION['administrator']);
31         $encrypted = hash('whirlpool',trim($_POST['password']));
32
33         if((x($_POST,'auth-params')) && $_POST['auth-params'] == 'login') {
34                 $r = q("SELECT * FROM `user` 
35                         WHERE `email` = '%s' AND `password` = '%s' LIMIT 1",
36                         dbesc(trim($_POST['login-name'])),
37                         dbesc($encrypted));
38                 if(($r === false) || (! count($r))) {
39                         $_SESSION['sysmsg'] = 'Login failed.' . EOL ;
40                         goaway($a->get_baseurl());
41                 }
42                 $_SESSION['uid'] = $r[0]['uid'];
43                 $_SESSION['admin'] = $r[0]['admin'];
44                 $_SESSION['authenticated'] = 1;
45                 if(x($r[0],'nickname'))
46                         $_SESSION['my_url'] = $a->get_baseurl() . '/profile/' . $r[0]['nickname'];
47                 else
48                         $_SESSION['my_url'] = $a->get_baseurl() . '/profile/' . $r[0]['uid'];
49
50                 $_SESSION['sysmsg'] = "Welcome back " . $r[0]['username'] . EOL;
51                 $a->user = $r[0];
52                 if(strlen($a->user['timezone']))
53                         date_default_timezone_set($a->user['timezone']);
54
55         }
56 }
57
58 // Returns an array of group names this contact is a member of.
59 // Since contact-id's are unique and each "belongs" to a given user uid,
60 // this array will only contain group names related to the uid of this
61 // DFRN contact. They are *not* neccessarily unique across the entire site. 
62
63
64 if(! function_exists('init_groups_visitor')) {
65 function init_groups_visitor($contact_id) {
66         $groups = array();
67         $r = q("SELECT `group_member`.`gid`, `group`.`name` 
68                 FROM `group_member` LEFT JOIN `group` ON `group_member`.`gid` = `group`.`id` 
69                 WHERE `group_member`.`contact-id` = %d ",
70                 intval($contact_id)
71         );
72         if(count($r)) {
73                 foreach($r as $rr)
74                         $groups[] = $rr['name'];
75         }
76         return $groups;
77 }}
78
79