Beispiel #1
0
 public function validate($data)
 {
     $vdt = new Validate\Validator();
     $vdt->addRule('page', new Validate\Rule\NumNatural())->addRule('page', new Validate\Rule\NumMin(1))->addRule('take', new Validate\Rule\NumNatural())->addRule('take', new Validate\Rule\NumMin(1))->addRule('take', new Validate\Rule\NumMax(100))->addFilter('endless', FilterFactory::booleanFilter())->addOptional('page')->addOptional('take')->addOptional('endless');
     if (!$vdt->validate($data)) {
         throw new BearableException('Parámetros de paginación incorrectos.');
     }
     return $vdt;
 }
Beispiel #2
0
 public function registrar()
 {
     $vdt = new Validate\Validator();
     $vdt->addRule('nombre', new Validate\Rule\Alpha(array(' ')))->addRule('nombre', new Validate\Rule\MinLength(1))->addRule('nombre', new Validate\Rule\MaxLength(32))->addRule('apellido', new Validate\Rule\Alpha(array(' ')))->addRule('apellido', new Validate\Rule\MinLength(1))->addRule('apellido', new Validate\Rule\MaxLength(32))->addRule('password', new Validate\Rule\MinLength(8))->addRule('password', new Validate\Rule\MaxLength(128))->addRule('password', new Validate\Rule\Matches('password2'))->addRule('email', new Validate\Rule\Email())->addRule('email', new Validate\Rule\MaxLength(128))->addRule('email', new Validate\Rule\Unique('usuarios'))->addRule('email', new Validate\Rule\Unique('preusuarios'))->addFilter('email', 'strtolower')->addFilter('email', 'trim');
     if ($this->getMode() != 'testing') {
         $phrase = isset($this->flashData()['captcha']) ? $this->flashData()['captcha'] : null;
         $vdt->addRule('captcha', new Validate\Rule\Equal($phrase));
     }
     $req = $this->request;
     if (!$vdt->validate($req->post())) {
         throw new TurnbackException($vdt->getErrors());
     }
     $preuser = new Preusuario();
     $preuser->email = $vdt->getData('email');
     $preuser->password = password_hash($vdt->getData('password'), PASSWORD_DEFAULT);
     $preuser->nombre = $vdt->getData('nombre');
     $preuser->apellido = $vdt->getData('apellido');
     $preuser->emailed_token = bin2hex(openssl_random_pseudo_bytes(16));
     $preuser->save();
     if ($this->getMode() != 'testing') {
         $to = $preuser->email;
         $subject = 'Confirma tu registro en Virtuagora';
         $message = 'Hola, te registraste en virtuagora. Entra a este link para confirmar tu email: ' . $req->getUrl() . $this->urlFor('runValidUsuario', array('idUsu' => $preuser->id, 'token' => $preuser->emailed_token));
         mail($to, $subject, $message);
     }
     $this->render('registro/registro-exito.twig', array('email' => $preuser->email));
 }
Beispiel #3
0
 public static function getTagIds($tags)
 {
     if (!is_array($tags)) {
         throw new TurnbackException('Tags incorrectas.');
     }
     $vdt = new Validate\Validator();
     $vdt->addRule('tags', new Validate\Rule\AlphaNumeric([' ']))->addRule('tags', new Validate\Rule\MinLength(2))->addRule('tags', new Validate\Rule\MaxLength(32));
     if (!$vdt->validate(['tags' => $tags])) {
         throw new TurnbackException($vdt->getErrors());
     } else {
         if (count($tags) > 8) {
             throw new TurnbackException('No pueden asignarse más de 8 tags.');
         }
     }
     $tagIds = array();
     foreach ($tags as $tag) {
         $tagIds[] = Tag::firstOrCreate(['nombre' => FilterFactory::normalizeWhitespace($tag)])->id;
     }
     return $tagIds;
 }
Beispiel #4
0
 public function votar($idCom)
 {
     $vdt = new Validate\Validator();
     $vdt->addRule('idCom', new Validate\Rule\NumNatural())->addRule('valor', new Validate\Rule\InArray(array(-1, 1)));
     $req = $this->request;
     $data = array_merge(array('idCom' => $idCom), $req->post());
     if (!$vdt->validate($data)) {
         throw new TurnbackException($vdt->getErrors());
     }
     $usuario = $this->session->getUser();
     $comentario = Comentario::findOrFail($idCom);
     $voto = VotoComentario::firstOrNew(array('comentario_id' => $comentario->id, 'usuario_id' => $usuario->id));
     if (!$voto->exists) {
         $voto->valor = $vdt->getData('valor');
         $voto->save();
         $comentario->increment('votos', $voto->valor);
         $comentario->autor()->increment('puntos', $voto->valor);
     } else {
         throw new TurnbackException('No puede votar dos veces el mismo comentario.');
     }
     $this->flash('success', 'Su voto fue registrado exitosamente.');
     $this->redirect($req->getReferrer());
 }
Beispiel #5
0
 public function verifCiudadano()
 {
     $vdt = new Validate\Validator();
     $vdt->addRule('entrantes', new Validate\Rule\Regex('/^\\[\\d+(?:,\\d+)*\\]$/'));
     $req = $this->request;
     if (!$vdt->validate($req->post())) {
         throw new TurnbackException('Configuración inválida.');
     }
     $entrantes = json_decode($vdt->getData('entrantes'));
     Usuario::whereIn('id', $entrantes)->whereNull('verified_at')->increment('puntos', 100, array('verified_at' => Carbon\Carbon::now()));
     foreach ($entrantes as $entrante) {
         $log = AdminlogCtrl::createLog('', 7, 'new', $this->session->user('id'), $entrante, 'Usuario');
         NotificacionCtrl::createNotif($entrante, $log);
     }
     $this->flash('success', 'Se han verificado los ciudadanos seleccionados exitosamente.');
     $this->redirectTo('shwAdmVrfUsuario');
 }
Beispiel #6
0
 public function reiniciarClave($idUsu, $token)
 {
     $vdt = new Validate\QuickValidator(array($this, 'notFound'));
     $vdt->test($idUsu, new Validate\Rule\NumNatural());
     $vdt->test($token, new Validate\Rule\AlphaNumeric());
     $vdt->test($token, new Validate\Rule\ExactLength(32));
     $vdt = new Validate\Validator();
     $vdt->addRule('password', new Validate\Rule\MinLength(8))->addRule('password', new Validate\Rule\MaxLength(128))->addRule('password', new Validate\Rule\Matches('password2'));
     if (!$vdt->validate($this->request->post())) {
         throw new TurnbackException($vdt->getErrors());
     }
     $usuario = Usuario::findOrFail($idUsu);
     if ($token != $usuario->token) {
         throw new TurnbackException('El link ha expirado o es inválido. Recordá que solamente es válido por una hora.');
     }
     $ahora = Carbon\Carbon::now();
     if ($ahora->gt($usuario->updated_at->addHour())) {
         throw new TurnbackException('El link ha expirado o es inválido. Recordá que solamente es válido por una hora.');
     }
     $usuario->token = null;
     $usuario->password = password_hash($vdt->getData('password'), PASSWORD_DEFAULT);
     $usuario->save();
     $this->redirectTo('endReiniciarClave');
 }
Beispiel #7
0
 private function validarOrganismo($data)
 {
     $vdt = new Validate\Validator();
     $vdt->addRule('nombre', new Validate\Rule\Alpha(array(' ')))->addRule('nombre', new Validate\Rule\MinLength(2))->addRule('nombre', new Validate\Rule\MaxLength(64))->addRule('descripcion', new Validate\Rule\MaxLength(512))->addRule('cupo', new Validate\Rule\NumNatural())->addRule('cupo', new Validate\Rule\NumMin(1))->addRule('cupo', new Validate\Rule\NumMax(128))->addRule('url', new Validate\Rule\URL())->addRule('email', new Validate\Rule\Email())->addRule('telefono', new Validate\Rule\Telephone())->addOptional('url')->addOptional('email')->addOptional('telefono')->addFilter('url', FilterFactory::emptyToNull())->addFilter('email', FilterFactory::emptyToNull())->addFilter('telefono', FilterFactory::emptyToNull());
     if (!$vdt->validate($data)) {
         throw new TurnbackException($vdt->getErrors());
     }
     return $vdt;
 }
 private function validarDocumento($data, $cuerpo = true)
 {
     $vdt = new Validate\Validator();
     $vdt->addRule('titulo', new Validate\Rule\MinLength(8))->addRule('titulo', new Validate\Rule\MaxLength(128))->addRule('descripcion', new Validate\Rule\MinLength(8))->addRule('descripcion', new Validate\Rule\MaxLength(1024))->addRule('categoria', new Validate\Rule\NumNatural())->addRule('categoria', new Validate\Rule\Exists('categorias'))->addFilter('tags', FilterFactory::explode(','));
     if ($cuerpo) {
         $vdt->addRule('cuerpo', new Validate\Rule\MinLength(8))->addRule('cuerpo', new Validate\Rule\MaxLength(8192))->addFilter('cuerpo', FilterFactory::escapeHTML());
     }
     if (!$vdt->validate($data)) {
         throw new TurnbackException($vdt->getErrors());
     }
     return $vdt;
 }
Beispiel #9
0
 private function validarPatrulla($data)
 {
     $vdt = new Validate\Validator();
     $vdt->addRule('nombre', new Validate\Rule\Alpha(array(' ')))->addRule('nombre', new Validate\Rule\MinLength(2))->addRule('nombre', new Validate\Rule\MaxLength(64))->addRule('descripcion', new Validate\Rule\MaxLength(512));
     if (!$vdt->validate($data)) {
         throw new TurnbackException($vdt->getErrors());
     }
     return $vdt;
 }
Beispiel #10
0
 private function validarPropuesta($data)
 {
     $vdt = new Validate\Validator();
     $vdt->addRule('titulo', new Validate\Rule\MinLength(8))->addRule('titulo', new Validate\Rule\MaxLength(128))->addRule('categoria', new Validate\Rule\NumNatural())->addRule('categoria', new Validate\Rule\Exists('categorias'))->addRule('referido', new Validate\Rule\NumNatural())->addRule('cuerpo', new Validate\Rule\MinLength(8))->addRule('cuerpo', new Validate\Rule\MaxLength(8192))->addFilter('cuerpo', FilterFactory::escapeHTML())->addFilter('referido', FilterFactory::emptyToNull())->addFilter('tags', FilterFactory::explode(','))->addOptional('referido');
     if (!$vdt->validate($data)) {
         throw new TurnbackException($vdt->getErrors());
     }
     return $vdt;
 }
Beispiel #11
0
 private function validarPartido($data)
 {
     $vdt = new Validate\Validator();
     $vdt->addRule('nombre', new Validate\Rule\Alpha(array(' ')))->addRule('nombre', new Validate\Rule\MinLength(2))->addRule('nombre', new Validate\Rule\MaxLength(64))->addRule('acronimo', new Validate\Rule\Alpha())->addRule('acronimo', new Validate\Rule\MinLength(2))->addRule('acronimo', new Validate\Rule\MaxLength(8))->addRule('descripcion', new Validate\Rule\MinLength(4))->addRule('descripcion', new Validate\Rule\MaxLength(512))->addRule('fundador', new Validate\Rule\Alpha(array(' ')))->addRule('fundador', new Validate\Rule\MaxLength(32))->addRule('fecha', new Validate\Rule\Date())->addRule('url', new Validate\Rule\URL())->addRule('email', new Validate\Rule\Email())->addRule('telefono', new Validate\Rule\Telephone())->addOptional('fundador')->addOptional('fecha')->addOptional('url')->addOptional('email')->addOptional('telefono')->addFilter('fundador', FilterFactory::emptyToNull())->addFilter('fecha', FilterFactory::emptyToNull())->addFilter('url', FilterFactory::emptyToNull())->addFilter('email', FilterFactory::emptyToNull())->addFilter('telefono', FilterFactory::emptyToNull());
     if (!$vdt->validate($data)) {
         throw new TurnbackException($vdt->getErrors());
     }
     return $vdt;
 }
Beispiel #12
0
 public function eliminar()
 {
     $vdt = new Validate\Validator();
     $vdt->addRule('password', new Validate\Rule\MinLength(8))->addRule('password', new Validate\Rule\MaxLength(128));
     $req = $this->request;
     if (!$vdt->validate($req->post())) {
         throw new TurnbackException($vdt->getErrors());
     }
     if (!$this->session->login($this->session->user('email'), $vdt->getData('password'))) {
         throw new TurnbackException('Contraseña inválida.');
     }
     $usuario = $this->session->getUser();
     $usuario->delete();
     $this->session->logout();
     $this->flash('success', 'Su cuenta ha sido eliminada.');
     $this->redirectTo('shwIndex');
 }
Beispiel #13
0
 private function validarEvento($data)
 {
     $vdt = new Validate\Validator();
     $vdt->addRule('titulo', new Validate\Rule\MinLength(8))->addRule('titulo', new Validate\Rule\MaxLength(128))->addRule('categoria', new Validate\Rule\NumNatural())->addRule('categoria', new Validate\Rule\Exists('categorias'))->addRule('lugar', new Validate\Rule\MinLength(4))->addRule('lugar', new Validate\Rule\MaxLength(128))->addRule('fecha', new Validate\Rule\Date('Y-m-d H:i:s'))->addRule('tags', new Validate\Rule\Required())->addRule('cuerpo', new Validate\Rule\MinLength(8))->addRule('cuerpo', new Validate\Rule\MaxLength(8192))->addFilter('cuerpo', FilterFactory::escapeHTML())->addFilter('asociar', FilterFactory::booleanFilter())->addFilter('tags', FilterFactory::explode(','));
     if (!$vdt->validate($data)) {
         throw new TurnbackException($vdt->getErrors());
     }
     return $vdt;
 }