]> git.mxchange.org Git - friendica.git/blob - include/auth.php
full theming support
[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['is_visitor']);
11                 unset($_SESSION['administrator']);
12                 unset($_SESSION['cid']);
13                 unset($_SESSION['theme']);
14                 notice( t('Logged out.') . EOL);
15                 goaway($a->get_baseurl());
16         }
17         if(x($_SESSION,'uid')) {
18                 $r = q("SELECT * FROM `user` WHERE `uid` = %d LIMIT 1",
19                         intval($_SESSION['uid']));
20                 if($r === NULL || (! count($r))) {
21                         goaway($a->get_baseurl());
22                 }
23                 $a->user = $r[0];
24                 $_SESSION['theme'] = $a->user['theme'];
25                 if(strlen($a->user['timezone']))
26                         date_default_timezone_set($a->user['timezone']);
27
28                 $_SESSION['my_url'] = $a->get_baseurl() . '/profile/' . $r[0]['nickname'];
29
30                 $r = q("SELECT * FROM `contact` WHERE `uid` = %s AND `self` = 1 LIMIT 1",
31                         intval($_SESSION['uid']));
32                 if(count($r)) {
33                         $a->contact = $r[0];
34                         $a->cid = $r[0]['id'];
35                         $_SESSION['cid'] = $a->cid;
36
37                 }
38         }
39 }
40 else {
41         unset($_SESSION['authenticated']);
42         unset($_SESSION['uid']);
43         unset($_SESSION['visitor_id']);
44         unset($_SESSION['is_visitor']);
45         unset($_SESSION['administrator']);
46         unset($_SESSION['cid']);
47         $encrypted = hash('whirlpool',trim($_POST['password']));
48
49         if((x($_POST,'auth-params')) && $_POST['auth-params'] == 'login') {
50                 $r = q("SELECT * FROM `user` 
51                         WHERE `email` = '%s' AND `password` = '%s' AND `blocked` = 0 AND `verified` = 1 LIMIT 1",
52                         dbesc(trim($_POST['login-name'])),
53                         dbesc($encrypted));
54                 if(($r === false) || (! count($r))) {
55                         notice( t('Login failed.') . EOL );
56                         goaway($a->get_baseurl());
57                 }
58                 $_SESSION['uid'] = $r[0]['uid'];
59                 $_SESSION['theme'] = $r[0]['theme'];
60                 $_SESSION['authenticated'] = 1;
61                 $_SESSION['my_url'] = $a->get_baseurl() . '/profile/' . $r[0]['nickname'];
62
63                 notice( t("Welcome back ") . $r[0]['username'] . EOL);
64                 $a->user = $r[0];
65                 if(strlen($a->user['timezone']))
66                         date_default_timezone_set($a->user['timezone']);
67
68                 $r = q("SELECT * FROM `contact` WHERE `uid` = %s AND `self` = 1 LIMIT 1",
69                         intval($_SESSION['uid']));
70                 if(count($r)) {
71                         $a->cid = $r[0]['id'];
72                         $_SESSION['cid'] = $a->cid;
73                 }
74
75
76         }
77 }
78
79 // Returns an array of group id's this contact is a member of.
80 // This array will only contain group id's related to the uid of this
81 // DFRN contact. They are *not* neccessarily unique across the entire site. 
82
83
84 if(! function_exists('init_groups_visitor')) {
85 function init_groups_visitor($contact_id) {
86         $groups = array();
87         $r = q("SELECT `gid` FROM `group_member` 
88                 WHERE `contact-id` = %d ",
89                 intval($contact_id)
90         );
91         if(count($r)) {
92                 foreach($r as $rr)
93                         $groups[] = $rr['gid'];
94         }
95         return $groups;
96 }}
97
98