-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.php
156 lines (141 loc) · 7.84 KB
/
app.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
<?php
// Prepare view
$app->view(new \Slim\Views\Twig());
$app->view->parserOptions = array(
'charset' => 'utf-8',
'cache' => false,
'auto_reload' => true,
'strict_variables' => false,
'autoescape' => true,
);
$app->view->parserExtensions = array(new ExtendedTwig());
// Prepare singletons
$app->container->singleton('session', function () use ($app) {
return new SessionManager($app->getMode());
});
$app->container->singleton('translator', function () {
$trans = new Symfony\Component\Translation\Translator('es');
$trans->addLoader('php', new Symfony\Component\Translation\Loader\PhpFileLoader());
$trans->addResource('php', __DIR__.'/../locales/es.php', 'es');
return $trans;
});
$app->api = false;
// Prepare error handler
$app->error(function (Exception $e) use ($app) {
if ($app->api) {
// TODO setar codigo de error correcto.
$msg = array('code' => $e->getCode(), 'message' => $e->getMessage());
if ($e instanceof TurnbackException) {
$msg['errors'] = $e->getErrors();
}
echo json_encode($msg);
} else {
if ($e instanceof TurnbackException) {
$app->flash('errors', $e->getErrors());
ob_end_clean();
$app->redirect($app->request->getReferrer());
} else if ($e instanceof BearableException) {
$app->render('ref/misc/error.twig', array('mensaje' => $e->getMessage()), $e->getCode());
} else if ($e instanceof Illuminate\Database\Eloquent\ModelNotFoundException) {
$app->notFound();
} else if ($e instanceof Illuminate\Database\QueryException && $e->getCode() == 23000) {
$app->render('ref/misc/error.twig', array('mensaje' => 'La información ingresada es inconsistente.'), 400);
} else {
// $app->render('misc/fatal-error.twig', array('type' => get_class($e), 'exception' => $e));
$app->render('ref/misc/error.twig', ['mensaje' => 'Ocurrió un error interno.'], 500);
}
}
});
// Prepare hooks
$app->hook('slim.before', function () use ($app) {
$app->view()->appendData(array('user' => $app->session->user()));
});
// Prepare middlewares
$checkNoSession = function () use ($app) {
if ($app->session->check()) {
$app->redirectTo('shwPortal');
}
};
$checkRole = function ($role) use ($app) {
return function () use ($role, $app) {
if (is_array($role)) {
$userRoles = $app->session->grantedRoles($role);
$rejected = empty($userRoles);
} else {
$rejected = !$app->session->hasRole($role);
}
if ($rejected) {
throw new BearableException('No tiene permiso para realizar esta acción', 403);
}
};
};
// Prepare dispatcher
// $app->get('/test', function () use ($app) {
// // $req = $app->request;
// // $uri = $req->headers->get('x-forwarded-host')?: $req->getUrl();
// // var_dump($uri);
// $app->render('ref/test.twig');
// });
$app->group('/eje', function () use ($app, $checkRole) {
$app->get('/crear', $checkRole('mod'), 'DerechoCtrl:verCrear')->name('shwCrearDerecho');
$app->post('/crear', $checkRole('mod'), 'DerechoCtrl:crear')->name('runCrearDerecho');
$app->get('/:idDer', 'DerechoCtrl:ver')->name('shwDerecho');
$app->get('/:idDer/modificar', $checkRole('mod'), 'DerechoCtrl:verModificar')->name('shwModifDerecho');
$app->post('/:idDer/modificar', $checkRole('mod'), 'DerechoCtrl:modificar')->name('runModifDerecho');
});
$app->group('/admin', function () use ($app, $checkRole) {
$app->get('/', $checkRole('mod'), 'AdminCtrl:verIndexAdmin')->name('shwIndexAdmin');
$app->get('/upload', $checkRole('mod'), 'AdminCtrl:verSubirImagen')->name('shwCrearImagen');
$app->post('/upload', $checkRole('mod'), 'AdminCtrl:subirImagen')->name('runCrearImagen');
$app->get('/imagen/:idEve', 'AdminCtrl:verImagen')->name('shwImagen');
$app->post('/sancionar/:idUsu', $checkRole('mod'), 'AdminCtrl:sancUsuario')->name('runSanUsuario');
$app->get('/ajustes', $checkRole('mod'), 'AdminCtrl:verAdminAjustes')->name('shwAdmAjuste');
$app->post('/ajustes', $checkRole('mod'), 'AdminCtrl:adminAjustes')->name('runAdmAjuste');
$app->get('/estadisticas', $checkRole('mod'), 'AdminCtrl:verEstadisticas')->name('shwEstadi');
$app->get('/estadisticas/:fechaDesde/:fechaHasta/imprimir', $checkRole('mod'), 'AdminCtrl:verEstadisticasTemporalesImprimir')->name('shwEstadiTempImpr');
$app->get('/exportar', $checkRole('mod'), 'AdminCtrl:verExportar')->name('shwExportar');
$app->get('/emails', $checkRole('mod'), 'AdminCtrl:verEmails')->name('shwEmails');
$app->get('/ejes', $checkRole('mod'), 'AdminCtrl:verModificarEjes')->name('shwModificarEjes');
$app->get('/comments/:idDer', $checkRole('mod'), 'AdminCtrl:verComments')->name('shwComments');
$app->get('/moderador/crear', $checkRole('mod'), 'AdminCtrl:verCrearModerador')->name('shwCrearModerad');
$app->post('/moderador/crear', $checkRole('mod'), 'AdminCtrl:crearModerador')->name('runCrearModerad');
});
$app->group('/comentario', function () use ($app, $checkRole) {
$app->get('', 'ComentarioCtrl:listar')->name('shwListaComenta');
$app->post('/comentar/:tipoRaiz/:idRaiz', $checkRole('usr'), 'ComentarioCtrl:comentar')->name('runComentar');
$app->get('/:idCom', 'ComentarioCtrl:ver')->name('shwComenta');
$app->post('/:idCom/votar', $checkRole('usr'), 'ComentarioCtrl:votar')->name('runVotarComenta');
$app->post('/eliminar', $checkRole('usr'), 'ComentarioCtrl:eliminar')->name('runElimiComenta');
});
$app->get('/', 'PortalCtrl:verIndex')->name('shwIndex');
$app->get('/portal', 'PortalCtrl:verPortal')->name('shwPortal');
//$app->get('/tos', 'PortalCtrl:verTos')->name('shwTos');;
$app->get('/login', $checkNoSession, 'PortalCtrl:verLogin')->name('shwLogin');
$app->post('/login', $checkNoSession, 'PortalCtrl:login')->name('runLogin');
$app->post('/logout', 'PortalCtrl:logout')->name('runLogout');
$app->get('/registro', $checkNoSession, 'PortalCtrl:verRegistrar')->name('shwCrearUsuario');
$app->post('/registro', $checkNoSession, 'PortalCtrl:registrar')->name('runCrearUsuario');
$app->get('/validar/:idUsu/:token', 'PortalCtrl:verificarEmail')->name('runValidUsuario');
$app->get('/recuperar-clave', $checkNoSession, 'PortalCtrl:verRecuperarClave')->name('shwRecuperarClave');
$app->post('/recuperar-clave', $checkNoSession, 'PortalCtrl:recuperarClave')->name('runRecuperarClave');
$app->get('/reiniciar-clave/:idUsu/:token', $checkNoSession, 'PortalCtrl:verReiniciarClave')->name('shwReiniciarClave');
$app->post('/reiniciar-clave/:idUsu/:token', $checkNoSession, 'PortalCtrl:reiniciarClave')->name('runReiniciarClave');
$app->get('/reiniciar-clave', $checkNoSession, 'PortalCtrl:finReiniciarClave')->name('endReiniciarClave');
$app->get('/contenido/:idCon', 'ContenidoCtrl:ver')->name('shwConteni');
$app->get('/contenido', 'ContenidoCtrl:listar')->name('shwListaConteni');
$app->get('/usuario/:idUsu', 'UsuarioCtrl:ver')->name('shwUsuario');
$app->get('/usuario/:idUsu/imagen/:res', 'UsuarioCtrl:verImagen')->name('shwImgUsuario');
$app->get('/usuario', 'UsuarioCtrl:listar')->name('shwListaUsuario');
$app->group('/perfil', function () use ($app, $checkRole) {
$app->get('/modificar', $checkRole('usr'), 'UsuarioCtrl:verModificar')->name('shwModifUsuario');
$app->post('/modificar', $checkRole('usr'), 'UsuarioCtrl:modificar')->name('runModifUsuario');
$app->get('/cambiar-clave', $checkRole('usr'), 'UsuarioCtrl:verCambiarClave')->name('shwModifClvUsuario');
$app->post('/cambiar-clave', $checkRole('usr'), 'UsuarioCtrl:cambiarClave')->name('runModifClvUsuario');
});
$app->get('/testemail', function () use ($app) {
$headers = "From: La Reforma Santa Fe <noreply@basesparalareforma.digital>\r\n";
$to = 'guillermocroppi@gmail.com';
$subject = 'Confirma tu registro';
$message = $this->view->fetch('email/email.twig');
mail($to, $subject, $message, $headers);
});