-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathclass.DYB.php
More file actions
72 lines (66 loc) · 3.21 KB
/
class.DYB.php
File metadata and controls
72 lines (66 loc) · 3.21 KB
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
<?php
class DYB {
/**
* Once your user is logged into your system call this method to redirect user on DoYouBuzz and automaticaly connect him.
* Here an example of call :
* <code>
* <?php
* DYB::sso_connect('votre-nom', // Your slug
'fr', // Lang (fr, us)
'123', // The user id on your system
$_SESSION['timestamp'], // Timestamp given to you in GET by DoYouBuzz
'john.doe@gmail.com', // User's email
'supercalifragilistic', // Secret key, set in settings pages, or given to you by DYB
'John', // User firstname
'Doe', // User lastname
null, // The Group ID which the user is member of
0, // Do we do a callback? (need to specify the url in settings)
0); // Do we do a return (need to specify the url in settings)
* ?>
* </code>
* @param string $slug Your slug, given by DoYouBuzz
* @param string $lang The lang for DoYouBuzz, 'fr', 'us'. Maybe more in future.
* @param string $external_id The user's id in your system. Must be less than 250 characters
* @param int $timestamp The timestamp given to you when calling your page. $_GET['timestamp'].
* @param string $email User email.
* @param string $secretkey The secret key that you set in your settings section. Do not display this one!
* @param string $firstname User firstname
* @param string $lastname User lastname
* @param string|array $groups_id The id of your groups
* @param string $user_type Type of the user : '1', '2', '3' or null
* @param $doCallback
* @param $doReturn
* @param string $redirect
* @param string $redirectCvId
* @param string $back_title
* @param string $back_href
* @param string $back_target
* @param string $action_title
* @param string $action_url
*/
function sso_connect($slug, $lang, $external_id, $timestamp, $email, $secretkey, $firstname = null,
$lastname = null, $groups_id = null, $user_type = null, $doCallback = false, $doReturn = false,
$redirect = null, $redirectCvId = null, $back_title = null, $back_href = null, $back_target = null,
$action_title = null, $action_url = null) {
$groupsParam = '';
if (!is_array($groups_id) && !empty($groups_id)) {
$groups_id = array($groups_id);
}
$group = '';
if (is_array($groups_id)) {
foreach($groups_id as $g) {
$groupsParam .= '&groups[]=' . rawurlencode($g);
$group .= $g;
}
}
$hash = md5($email . $firstname . $lastname . $external_id . $group . $user_type . $timestamp . $secretkey);
$param = '?email=' . rawurlencode($email) . '&external_id=' . rawurlencode($external_id) . '&firstname='
. rawurlencode($firstname) . $groupsParam . '&hash=' . $hash . '&lastname=' . rawurlencode($lastname)
. '&user_type=' . $user_type . '×tamp=' . $timestamp . '&redirect=' . $redirect . '&redirectCvId=' . $redirectCvId . '&back_title=' .
$back_title . '&back_href=' . $back_href . '&back_target=' . $back_target . '&action_title=' . $action_title
. '&action_url=' . $action_url;
$url = 'http://showcase.doyoubuzz.com/p/' . $lang . '/' . $slug . '/sso' . $param;
header('location:'.$url, true, 302);
exit;
}
}