-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.php
193 lines (172 loc) · 5.06 KB
/
index.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
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
<?php
/**
* Step 1: Require the Slim Framework
*
* If you are not using Composer, you need to require the
* Slim Framework and register its PSR-0 autoloader.
*
* If you are using Composer, you can skip this step.
*/
session_start();
require 'Slim/Slim.php';
require 'config/database.php';
require 'config/general.php';
\Slim\Slim::registerAutoloader();
/**
* Step 2: Instantiate a Slim application
*
* This example instantiates a Slim application using
* its default settings. However, you will usually configure
* your Slim application now by passing an associative array
* of setting names and values into the application constructor.
*/
$app = new \Slim\Slim();
$app->contentType('text/html; charset=utf-8');
/**
* Step 3: Define the Slim application routes
*
* Here we define several Slim application routes that respond
* to appropriate HTTP request methods. In this example, the second
* argument for `Slim::get`, `Slim::post`, `Slim::put`, `Slim::patch`, and `Slim::delete`
* is an anonymous function.
*/
// GET route
$app->get(
'/',
function () {
require_once('template/head.tpl.php');
require_once('template/index.tpl.php');
require_once('template/foot.tpl.php');
}
);
// GET route
$app->get(
'/form',
function () {
require_once('template/head.tpl.php');
require_once('template/form.tpl.php');
require_once('template/foot.tpl.php');
}
);
// GET route
$app->get(
'/legislador/:legislador',
function ($legislador) {
require_once('template/head.tpl.php');
require_once('template/legislador.tpl.php');
require_once('template/foot.tpl.php');
}
);
// POST route
$app->post(
'/post',
function () {
echo 'This is a POST route';
}
);
$app->get (
'/login',
function () {
}
);
$app->post (
'/login',
function () {
$salt = 'LB2SvJAtfwrEYqykb9x5qvNh';
}
);
$app->get (
'/login/twitter',
function () use ($app) {
require_once('includes/twitteroauth/twitteroauth.php');
require_once('includes/twitteroauth/OAuth.php');
if(isset($_SESSION['name']) && isset($_SESSION['twitter_id'])) { //check whether user already logged in with twitter
echo "Name :".$_SESSION['name']."<br>";
echo "Twitter ID :".$_SESSION['twitter_id']."<br>";
echo "Image :<img src='".$_SESSION['image']."'/><br>";
echo "<br/><a href='". getURL('/logout') . "'>Logout</a>";
} else { // Not logged in
$connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET);
$request_token = $connection->getRequestToken(OAUTH_CALLBACK); //get Request Token
if( $request_token) {
$token = $request_token['oauth_token'];
$_SESSION['request_token'] = $token ;
$_SESSION['request_token_secret'] = $request_token['oauth_token_secret'];
switch ($connection->http_code) {
case 200:
$url = $connection->getAuthorizeURL($token);
//echo $url;exit;
//redirect to Twitter .
$app->redirect($url);
break;
default:
echo "Coonection with twitter Failed";
$app->redirect($url);
break;
}
} else { //error receiving request token
echo "Error Receiving Request Token";
}
}
}
);
$app->get(
'/logout',
function () use ($app) {
session_destroy();
$app->redirect('/');
}
);
$app->get(
'/registro',
function () {
require_once('template/head.tpl.php');
require_once('template/registro.tpl.php');
require_once('template/foot.tpl.php');
}
);
$app->post(
'/registro',
function () use ($app) {
if ($_POST['password'] != $_POST['password2']) {
session_destroy();
$app->redirect('/registro');
} else {
$salt = 'LB2SvJAtfwrEYqykb9x5qvNh';
$password = crypt($_POST['password'], $salt );
if ( crearUsuario($_POST['nombre'], $_POST['email'], $password)) {
$app->response()->header("Content-Type", "application/json");
$message='El usuario ha sido creado exitosamente';
print_r(json_encode($message));
} else {
$message='Error al crear usuario';
print_r(json_encode($message));
}
}
}
);
// PUT route
$app->put(
'/put',
function () {
echo 'This is a PUT route';
}
);
// PATCH route
$app->patch('/patch', function () {
echo 'This is a PATCH route';
});
// DELETE route
$app->delete(
'/delete',
function () {
echo 'This is a DELETE route';
}
);
/**
* Step 4: Run the Slim application
*
* This method should be called last. This executes the Slim application
* and returns the HTTP response to the HTTP client.
*/
$app->run();