aboutsummaryrefslogtreecommitdiffstats
path: root/include/security.php
diff options
context:
space:
mode:
Diffstat (limited to 'include/security.php')
-rw-r--r--include/security.php55
1 files changed, 49 insertions, 6 deletions
diff --git a/include/security.php b/include/security.php
index 38045c8a9..2107ed819 100644
--- a/include/security.php
+++ b/include/security.php
@@ -12,7 +12,7 @@
* @param bool $return
* @param bool $update_lastlog
*/
-function authenticate_success($user_record, $login_initial = false, $interactive = false, $return = false, $update_lastlog = false) {
+function authenticate_success($user_record, $channel = null, $login_initial = false, $interactive = false, $return = false, $update_lastlog = false) {
$_SESSION['addr'] = $_SERVER['REMOTE_ADDR'];
@@ -23,11 +23,15 @@ function authenticate_success($user_record, $login_initial = false, $interactive
$_SESSION['account_id'] = $user_record['account_id'];
$_SESSION['authenticated'] = 1;
+ if($channel)
+ $uid_to_load = $channel['channel_id'];
- $uid_to_load = (((x($_SESSION,'uid')) && (intval($_SESSION['uid'])))
- ? intval($_SESSION['uid'])
- : intval(App::$account['account_default_channel'])
- );
+ if(! $uid_to_load) {
+ $uid_to_load = (((x($_SESSION,'uid')) && (intval($_SESSION['uid'])))
+ ? intval($_SESSION['uid'])
+ : intval(App::$account['account_default_channel'])
+ );
+ }
if($uid_to_load) {
change_channel($uid_to_load);
@@ -82,6 +86,41 @@ function authenticate_success($user_record, $login_initial = false, $interactive
/* else just return */
}
+function atoken_login($atoken) {
+ if(! $atoken)
+ return false;
+ $_SESSION['authenticated'] = 1;
+ $_SESSION['visitor_id'] = $atoken['xchan_hash'];
+ $_SESSION['atoken'] = $atoken['atoken_id'];
+
+ \App::set_observer($atoken);
+ return true;
+}
+
+
+function atoken_xchan($atoken) {
+
+ $c = channelx_by_n($atoken['atoken_uid']);
+ if($c) {
+ return [
+ 'atoken_id' => $atoken['atoken_id'],
+ 'xchan_hash' => substr($c['channel_hash'],0,16) . '.' . $atoken['atoken_name'],
+ 'xchan_name' => $atoken['atoken_name'],
+ 'xchan_addr' => t('guest:') . $atoken['atoken_name'] . '@' . \App::get_hostname(),
+ 'xchan_network' => 'unknown',
+ 'xchan_hidden' => 1,
+ 'xchan_photo_mimetype' => 'image/jpeg',
+ 'xchan_photo_l' => get_default_profile_photo(300),
+ 'xchan_photo_m' => get_default_profile_photo(80),
+ 'xchan_photo_s' => get_default_profile_photo(48)
+
+ ];
+ }
+ return null;
+}
+
+
+
/**
* @brief Change to another channel with current logged-in account.
*
@@ -125,13 +164,17 @@ function change_channel($change_channel) {
);
if($x) {
$_SESSION['my_url'] = $x[0]['xchan_url'];
- $_SESSION['my_address'] = $r[0]['channel_address'] . '@' . substr(z_root(), strpos(z_root(), '://') + 3);
+ $_SESSION['my_address'] = $r[0]['channel_address'] . '@' . App::get_hostname();
App::set_observer($x[0]);
App::set_perms(get_all_perms(local_channel(), $hash));
}
if(! is_dir('store/' . $r[0]['channel_address']))
@os_mkdir('store/' . $r[0]['channel_address'], STORAGE_DEFAULT_PERMISSIONS,true);
+
+ $arr = [ 'channel_id' => $change_channel, 'chanx' => $ret ];
+ call_hooks('change_channel', $arr);
+
}
return $ret;