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)); }
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; }
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()); }
public function sancUsuario($idUsu) { $vdt = new Validate\Validator(); $vdt->addRule('idUsu', new Validate\Rule\NumNatural())->addRule('tipo', new Validate\Rule\InArray(array('Suspension', 'Advertencia', 'Quita')))->addRule('mensaje', new Validate\Rule\MinLength(4))->addRule('mensaje', new Validate\Rule\MaxLength(128))->addRule('cantidad', new Validate\Rule\NumNatural()); $req = $this->request; $data = array_merge(array('idUsu' => $idUsu), $req->post()); if (!$vdt->validate($data)) { throw new TurnbackException($vdt->getErrors()); } $usuario = Usuario::findOrFail($vdt->getData('idUsu')); switch ($vdt->getData('tipo')) { case 'Suspension': $usuario->suspendido = true; if ($vdt->getData('cantidad') > 0) { $usuario->fin_suspension = Carbon\Carbon::now()->addDays($vdt->getData('cantidad')); } else { $usuario->fin_suspension = null; } $usuario->save(); $mensaje = "El usuario fue suspendido."; break; case 'Advertencia': $usuario->advertencia = $vdt->getData('mensaje'); $usuario->fin_advertencia = Carbon\Carbon::now()->addDays($vdt->getData('cantidad')); $usuario->save(); $mensaje = "El usuario ha sido advertido."; break; case 'Quita': $usuario->decrement('puntos', $vdt->getData('cantidad')); $mensaje = "Se le han quitado los puntos al usuario."; break; } $subclase = strtolower(substr($vdt->getData('tipo'), 0, 3)); $log = AdminlogCtrl::createLog($vdt->getData('mensaje'), 1, $subclase, $this->session->user('id'), $usuario); NotificacionCtrl::createNotif($usuario->id, $log); $this->flash('success', $mensaje); $this->redirect($req->getReferrer()); }
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'); }
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; }
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; }
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; }
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; }
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'); }
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; }