This repository was archived by the owner on Jun 3, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathswitchboard.drush.sw_auth.inc
More file actions
104 lines (97 loc) · 3.16 KB
/
switchboard.drush.sw_auth.inc
File metadata and controls
104 lines (97 loc) · 3.16 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
<?php
/**
* @file
* User authorization callbacks.
*/
/**
* Validation callback for drush sw-auth-login.
*
* @param string $provider_name
* The name of the Provider.
* @param string $email
* The email address used to login.
* @param string $password
* The password used to login.
*
* @return bool
* FALSE upon failure.
*/
function drush_switchboard_sw_auth_login_validate($provider_name = '', $email = '', $password = '') {
if (!switchboard_validate_provider_name($provider_name)) {
return switchboard_message_fail_generate('SWITCHBOARD_PROVIDER_INVALID', array(
'@provider_name' => $provider_name,
));
}
$provider =& \Fluxsauce\Switchboard\Provider::getInstance($provider_name);
if ($provider->authIsLoggedIn()) {
return switchboard_message_fail('SWITCHBOARD_AUTH_LOGIN_ALREADY_LOGGEDIN', dt('Already logged-in to @provider_name.', array(
'@provider_name' => $provider_name,
)));
}
if (!$email || !filter_var($email, FILTER_VALIDATE_EMAIL)) {
return switchboard_message_fail('SWITCHBOARD_AUTH_LOGIN_INVALID_EMAIL', dt('Invalid email; cannot authenticate.'));
}
if (!$password) {
return switchboard_message_fail('SWITCHBOARD_AUTH_LOGIN_INVALID_PASSWORD', dt('Password missing; cannot authenticate.'));
}
}
/**
* Command callback for drush sw-auth-login.
*
* @param string $provider_name
* The name of the Provider.
* @param string $email
* The email address used to login.
* @param string $password
* The password used to login.
*/
function drush_switchboard_sw_auth_login($provider_name, $email, $password) {
$provider =& \Fluxsauce\Switchboard\Provider::getInstance($provider_name);
$result = $provider->authLogin($email, $password);
if ($result) {
switchboard_message_success(dt('Logged into @provider_name as @email.', array(
'@provider_name' => $provider_name,
'@email' => $email,
)));
}
else {
switchboard_message_fail('SWITCHBOARD_AUTH_LOGIN_FAILURE', dt('Unable to login to @provider_name.', array(
'@provider_name' => $provider_name,
)));
}
}
/**
* Validation callback for drush sw-auth-logout.
*
* @param string $provider_name
* The name of the Provider.
*
* @return bool
* FALSE upon failure.
*/
function drush_switchboard_sw_auth_logout_validate($provider_name = '') {
if (!switchboard_validate_provider_name($provider_name)) {
return switchboard_message_fail_generate('SWITCHBOARD_PROVIDER_INVALID', array(
'@provider_name' => $provider_name,
));
}
$provider =& \Fluxsauce\Switchboard\Provider::getInstance($provider_name);
if (!$provider->authIsLoggedIn()) {
return switchboard_message_fail('SWITCHBOARD_AUTH_LOGOUT_ALREADY_LOGGEDOUT', dt('Already logged-out of @provider_name.', array(
'@provider_name' => $provider_name,
)));
}
}
/**
* Command callback for drush sw-auth-logout.
*
* @param string $provider_name
* The name of the Provider.
*/
function drush_switchboard_sw_auth_logout($provider_name) {
$provider =& \Fluxsauce\Switchboard\Provider::getInstance($provider_name);
$provider->authLogout();
switchboard_message_success(dt('Logged out of @provider.', array(
'@provider' => $provider_name,
)));
}