3 function authenticate_success($user_record, $login_initial = false, $interactive = false) {
7 $_SESSION['uid'] = $user_record['uid'];
8 $_SESSION['theme'] = $user_record['theme'];
9 $_SESSION['authenticated'] = 1;
10 $_SESSION['page_flags'] = $user_record['page-flags'];
11 $_SESSION['my_url'] = $a->get_baseurl() . '/profile/' . $user_record['nickname'];
12 $_SESSION['addr'] = $_SERVER['REMOTE_ADDR'];
14 $a->user = $user_record;
17 if($a->user['login_date'] === '0000-00-00 00:00:00') {
18 $_SESSION['return_url'] = 'profile_photo/new';
19 $a->module = 'profile_photo';
20 info( t("Welcome ") . $a->user['username'] . EOL);
21 info( t('Please upload a profile photo.') . EOL);
24 info( t("Welcome back ") . $a->user['username'] . EOL);
27 $member_since = strtotime($a->user['register_date']);
28 if(time() < ($member_since + ( 60 * 60 * 24 * 14)))
29 $_SESSION['new_member'] = true;
31 $_SESSION['new_member'] = false;
32 if(strlen($a->user['timezone'])) {
33 date_default_timezone_set($a->user['timezone']);
34 $a->timezone = $a->user['timezone'];
37 $master_record = $a->user;
39 if((x($_SESSION,'submanage')) && intval($_SESSION['submanage'])) {
40 $r = q("select * from user where uid = %d limit 1",
41 intval($_SESSION['submanage'])
44 $master_record = $r[0];
47 $r = q("SELECT `uid`,`username`,`nickname` FROM `user` WHERE `password` = '%s' AND `email` = '%s'",
48 dbesc($master_record['password']),
49 dbesc($master_record['email'])
54 $a->identities = array();
56 $r = q("select `user`.`uid`, `user`.`username`, `user`.`nickname`
57 from manage left join user on manage.mid = user.uid
58 where `manage`.`uid` = %d",
59 intval($master_record['uid'])
62 $a->identities = array_merge($a->identities,$r);
65 logger('auth_identities: ' . print_r($a->identities,true), LOGGER_DEBUG);
67 $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `self` = 1 LIMIT 1",
68 intval($_SESSION['uid']));
71 $a->cid = $r[0]['id'];
72 $_SESSION['cid'] = $a->cid;
75 header('X-Account-Management-Status: active; name="' . $a->user['username'] . '"; id="' . $a->user['nickname'] .'"');
80 q("UPDATE `user` SET `login_date` = '%s', `language` = '%s' WHERE `uid` = %d LIMIT 1",
81 dbesc(datetime_convert()),
83 intval($_SESSION['uid'])
86 call_hooks('logged_in', $a->user);
88 if(($a->module !== 'home') && isset($_SESSION['return_url']))
89 goaway($a->get_baseurl() . '/' . $_SESSION['return_url']);
96 function can_write_wall(&$a,$owner) {
100 if((! (local_user())) && (! (remote_user())))
105 if(($uid) && ($uid == $owner)) {
111 // use remembered decision and avoid a DB lookup for each and every display item
112 // DO NOT use this function if there are going to be multiple owners
114 // We have a contact-id for an authenticated remote user, this block determines if the contact
115 // belongs to this page owner, and has the necessary permissions to post content
119 elseif($verified === 1)
123 $r = q("SELECT `contact`.*, `user`.`page-flags` FROM `contact` LEFT JOIN `user` on `user`.`uid` = `contact`.`uid`
124 WHERE `contact`.`uid` = %d AND `contact`.`id` = %d AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
125 AND `user`.`blockwall` = 0 AND `readonly` = 0 AND ( `contact`.`rel` IN ( %d , %d ) OR `user`.`page-flags` = %d ) LIMIT 1",
127 intval(remote_user()),
128 intval(CONTACT_IS_SHARING),
129 intval(CONTACT_IS_FRIEND),
130 intval(PAGE_COMMUNITY)
147 function permissions_sql($owner_id,$remote_verified = false,$groups = null) {
149 $local_user = local_user();
150 $remote_user = remote_user();
153 * Construct permissions
155 * default permissions - anonymous user
158 $sql = " AND allow_cid = ''
165 * Profile owner - everything is visible
168 if(($local_user) && ($local_user == $owner_id)) {
173 * Authenticated visitor. Unless pre-verified,
174 * check that the contact belongs to this $owner_id
175 * and load the groups the visitor belongs to.
176 * If pre-verified, the caller is expected to have already
177 * done this and passed the groups into this function.
180 elseif($remote_user) {
182 if(! $remote_verified) {
183 $r = q("SELECT id FROM contact WHERE id = %d AND uid = %d AND blocked = 0 LIMIT 1",
184 intval($remote_user),
188 $remote_verified = true;
189 $groups = init_groups_visitor($remote_user);
192 if($remote_verified) {
194 $gs = '<<>>'; // should be impossible to match
196 if(is_array($groups) && count($groups)) {
197 foreach($groups as $g)
198 $gs .= '|<' . intval($g) . '>';
202 " AND ( allow_cid = '' OR allow_cid REGEXP '<%d>' )
203 AND ( deny_cid = '' OR NOT deny_cid REGEXP '<%d>' )
204 AND ( allow_gid = '' OR allow_gid REGEXP '%s' )
205 AND ( deny_gid = '' OR NOT deny_gid REGEXP '%s')
207 intval($remote_user),
208 intval($remote_user),
218 function item_permissions_sql($owner_id,$remote_verified = false,$groups = null) {
220 $local_user = local_user();
221 $remote_user = remote_user();
224 * Construct permissions
226 * default permissions - anonymous user
229 $sql = " AND allow_cid = ''
237 * Profile owner - everything is visible
240 if(($local_user) && ($local_user == $owner_id)) {
245 * Authenticated visitor. Unless pre-verified,
246 * check that the contact belongs to this $owner_id
247 * and load the groups the visitor belongs to.
248 * If pre-verified, the caller is expected to have already
249 * done this and passed the groups into this function.
252 elseif($remote_user) {
254 if(! $remote_verified) {
255 $r = q("SELECT id FROM contact WHERE id = %d AND uid = %d AND blocked = 0 LIMIT 1",
256 intval($remote_user),
260 $remote_verified = true;
261 $groups = init_groups_visitor($remote_user);
264 if($remote_verified) {
266 $gs = '<<>>'; // should be impossible to match
268 if(is_array($groups) && count($groups)) {
269 foreach($groups as $g)
270 $gs .= '|<' . intval($g) . '>';
274 " AND ( private = 0 OR (( allow_cid = '' OR allow_cid REGEXP '<%d>' )
275 AND ( deny_cid = '' OR NOT deny_cid REGEXP '<%d>' )
276 AND ( allow_gid = '' OR allow_gid REGEXP '%s' )
277 AND ( deny_gid = '' OR NOT deny_gid REGEXP '%s')))
279 intval($remote_user),
280 intval($remote_user),