-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdemo_auth.php
48 lines (41 loc) · 1.09 KB
/
demo_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
<?php
require 'https_django_auth.php';
// command-line interface
if ('cli' === PHP_SAPI) {
$options_default = [
"username" => "",
"password" => "",
"url" => "",
];
$options = getopt('', ["username:", "password:",
"url:"]);
// var_dump($options);
$options = $options + $options_default;
// var_dump($options);
if(!$options['username'] || !$options['password'] || !$options['url']) {
$fn = $_SERVER['SCRIPT_FILENAME'];
echo "Usage: php $fn --username=LOGIN_USERNAME --password=LOGIN_PASSWORD ";
echo "--url=LOGIN_URL";
echo "\n";
exit(1);
}
// logging in
try {
$result_arr = call_user_func_array("login_django_https", $options);
$result = $result_arr['authorized'];
$id = $result_arr['id'];
$error = "Wrong password";
} catch (Exception $e) {
$result = false;
$error = $e->getMessage();
}
if($result) {
echo "Login successful $id\n";
exit(0);
}
else {
echo "Login failed: $error\n";
exit(1);
}
}
?>