-
Notifications
You must be signed in to change notification settings - Fork 0
/
flipside_auth.php
executable file
·79 lines (75 loc) · 2.33 KB
/
flipside_auth.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
<?php
/**
* Plugin Name: Flipside Auth Plugin
* Plugin URI: https://dev.burningflipside.com
* Description: Flipside Auth.
* Version: 0.2
* Author: Patrick
*/
function get_base_uri()
{
$ret = getenv('PROFILES_URL');
if($ret === false)
{
return 'https://profiles.burningflipside.com';
}
return $ret;
}
function flipside_redirect_login_page()
{
if(strpos($_SERVER['REQUEST_URI'], 'wp-login.php'))
{
if(isset($_GET['action']) && $_GET['action'] == 'logout')
{
wp_logout();
wp_redirect(get_base_uri().'/logout.php');
exit();
}
$redirect = site_url();
if(isset($_GET['redirect_to']))
{
$redirect = $_GET['redirect_to'];
}
wp_redirect(get_base_uri().'/login.php?return='.$redirect);
exit();
}
if(!is_user_logged_in())
{
if(isset($_COOKIE['PHPSESSID']))
{
$old_id = session_id();
$new_id = $_COOKIE['PHPSESSID'];
session_id($new_id);
require_once('/var/www/common/FlipSession.php');
if(\Flipside\FlipSession::isLoggedIn())
{
$flipUser = \Flipside\FlipSession::getUser();
$wpUser = get_user_by('email', $flipUser->mail);
if($wpUser !== false)
{
if($flipUser->isInGroupNamed('WordPressAdmins'))
{
$wpUser->set_role('administrator');
}
wp_set_current_user($wpUser->ID);
wp_set_auth_cookie($wpUser->ID);
do_action('wp_login', $wpUser->user_login, $wpUser);
}
else
{
$uid = wp_create_user($flipUser->uid, wp_generate_password($length=12, $include_standard_special_chars=false), $flipUser->mail);
if($flipUser->isInGroupNamed('WordPressAdmins'))
{
$wpUser = get_user_by('id', $uid);
$wpUser->set_role('administrator');
}
wp_set_current_user($uid);
wp_set_auth_cookie($uid);
}
}
session_id($old_id);
}
}
}
add_action('init','flipside_redirect_login_page');
?>