blob: 68789b70124847e52ce9c32071edd3bf06a6c67c (
plain)
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
|
<?php
/**
* Part of grauphel
*
* PHP version 5
*
* @category Tools
* @package Grauphel
* @author Christian Weiske <cweiske@cweiske.de>
* @copyright 2014 Christian Weiske
* @license http://www.gnu.org/licenses/agpl.html GNU AGPL v3
* @link http://cweiske.de/grauphel.htm
*/
namespace OCA\Grauphel\Controller;
use \OCP\AppFramework\Controller;
/**
* Login and authorization handling
*
* @category Tools
* @package Grauphel
* @author Christian Weiske <cweiske@cweiske.de>
* @copyright 2014 Christian Weiske
* @license http://www.gnu.org/licenses/agpl.html GNU AGPL v3
* @version Release: @package_version@
* @link http://cweiske.de/grauphel.htm
*/
class AccessController extends Controller
{
public function login($returnUrl = null)
{
$returnUrl = $this->loadReturnUrl($returnUrl);
if (isset($_POST['user']) && trim($_POST['user']) != '') {
$this->deps->frontend->setUser(trim($_POST['user']));
header('Location: ' . $returnUrl);
exit(0);
}
$hFormUrl = htmlspecialchars(
$this->deps->urlGen->addParams(
$this->deps->urlGen->accessLogin(),
array('returnurl' => $returnUrl)
)
);
//FIXME: do some real login
header('HTTP/1.0 200 OK');
echo <<<HTM
<html>
<head>
<title>grauphel login</title>
</head>
<body>
<form method="post" action="$hFormUrl">
<p>
Log into <em>grauphel</em>:
</p>
<label>
User name:
<input id="user" type="text" name="user" size="20" value=""/>
</label>
<input type="submit" value="Login" />
</form>
<script type="text/javascript">
//FIXME
/*
document.getElementById('user').value = 'cweiske';
document.forms[0].submit();
/**/
</script>
</body>
</html>
HTM;
exit(0);
}
public function authorize($returnUrl = null)
{
var_dump('asd');die();
$returnUrl = $this->loadReturnUrl($returnUrl);
if (isset($_POST['auth'])) {
if ($_POST['auth'] == 'ok') {
$this->deps->frontend->setAuth(true);
} else if ($_POST['auth'] == 'cancel') {
$this->deps->frontend->setAuth(false);
}
header('Location: ' . $returnUrl);
exit(0);
}
header('HTTP/1.0 200 OK');
$hFormUrl = htmlspecialchars(
$this->deps->urlGen->addParams(
$this->deps->urlGen->accessAuthorize(),
array('returnurl' => $returnUrl)
)
);
echo <<<HTM
<html>
<head>
<title>grauphel authorization</title>
</head>
<body>
<form method="post" action="$hFormUrl">
<p>
Shall application FIXME get full access to the notes?
</p>
<button type="submit" name="auth" value="ok">Yes, authorize</button>
<button type="submit" name="auth" value="cancel">No, decline</button>
</body>
</html>
HTM;
exit(0);
}
protected function loadReturnUrl($returnUrl = null)
{
if ($returnUrl === null) {
if (isset($_GET['returnurl'])) {
$returnUrl = $_GET['returnurl'];
} else {
$returnUrl = $this->deps->urlGen->index();
}
}
return $returnUrl;
}
/**
* @NoAdminRequired
* @NoCSRFRequired
* @PublicPage
*/
public function test()
{
var_dump('asd');die();
$this->registerResponder('xml', function($value) {
return new XMLResponse($value);
});
return array('foo' => 'bar');
}
}
?>
|