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());
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());
21 if(strlen($a->user['timezone']))
22 date_default_timezone_set($a->user['timezone']);
27 unset($_SESSION['authenticated']);
28 unset($_SESSION['uid']);
29 unset($_SESSION['visitor_id']);
30 unset($_SESSION['administrator']);
31 $encrypted = hash('whirlpool',trim($_POST['password']));
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'])),
38 if(($r === false) || (! count($r))) {
39 $_SESSION['sysmsg'] = 'Login failed.' . EOL ;
40 goaway($a->get_baseurl());
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'];
48 $_SESSION['my_url'] = $a->get_baseurl() . '/profile/' . $r[0]['uid'];
50 $_SESSION['sysmsg'] = "Welcome back " . $r[0]['username'] . EOL;
52 if(strlen($a->user['timezone']))
53 date_default_timezone_set($a->user['timezone']);
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.
64 if(! function_exists('init_groups_visitor')) {
65 function init_groups_visitor($contact_id) {
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 ",
74 $groups[] = $rr['name'];