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 function participar($idEve) { $vdt = new Validate\Validator(); $vdt->addRule('idEve', new Validate\Rule\NumNatural())->addFilter('presente', FilterFactory::booleanFilter())->addFilter('publico', FilterFactory::booleanFilter()); $req = $this->request; $data = array_merge(array('idEve' => $idEve), $req->post()); if (!$vdt->validate($data)) { throw new TurnbackException($vdt->getErrors()); } $usuario = $this->session->getUser(); $evento = Evento::findOrFail($idEve); $hoy = Carbon\Carbon::now(); if ($hoy->gt($evento->fecha)) { throw new TurnbackException('El evento ya ha ocurrido.'); } $sumaPost = $vdt->getData('presente') ? 3 : 1; $participe = $evento->usuarios()->where('usuario_id', $usuario->id)->first(); if (is_null($participe)) { $evento->usuarios()->attach($usuario->id, ['presente' => $vdt->getData('presente'), 'publico' => $vdt->getData('publico')]); } else { $participe->pivot->presente = $vdt->getData('presente'); $participe->pivot->publico = $vdt->getData('publico'); $participe->pivot->save(); $sumaPost -= $participe->pivot->presente ? 3 : 1; } if ($sumaPost != 0) { $evento->contenido()->increment('puntos', $sumaPost); } $this->flash('success', 'Su participación fue registrada exitosamente.'); $this->redirectTo('shwEvento', array('idEve' => $evento->id)); }
public function votar($idPro) { $vdt = new Validate\Validator(); $vdt->addRule('postura', new Validate\Rule\InArray(array(-1, 0, 1)))->addRule('idPro', new Validate\Rule\NumNatural())->addFilter('publico', FilterFactory::booleanFilter()); $req = $this->request; $data = array_merge(array('idPro' => $idPro), $req->post()); if (!$vdt->validate($data)) { throw new TurnbackException($vdt->getErrors()); } $usuario = $this->session->getUser(); $propuesta = Propuesta::with('contenido')->findOrFail($idPro); $voto = VotoPropuesta::firstOrNew(array('propuesta_id' => $propuesta->id, 'usuario_id' => $usuario->id)); $cfgPtsAutr = [-1 => 0, 0 => 0, 1 => 2]; $cfgPtsPost = [-1 => 1, 0 => 2, 1 => 3]; $cfgCount = [-1 => 'votos_contra', 0 => 'votos_neutro', 1 => 'votos_favor']; $postura = $vdt->getData('postura'); $sumaAutr = $cfgPtsAutr[$postura]; $sumaPost = $cfgPtsPost[$postura]; if (!$voto->exists) { $usuario->increment('puntos', 3); UserlogCtrl::createLog('votPropues', $usuario->id, $propuesta); } else { if ($voto->postura != $postura) { $hoy = Carbon\Carbon::now(); if ($hoy->lt($voto->updated_at->addDays(3))) { throw new TurnbackException('No puede cambiar su voto tan pronto.'); } $usuario->decrement('puntos', 3); $propuesta->decrement($cfgCount[$voto->postura]); $sumaAutr -= $cfgPtsAutr[$voto->postura]; $sumaPost -= $cfgPtsPost[$voto->postura]; } else { if ($voto->publico != $vdt->getData('publico')) { $voto->timestamps = false; $voto->publico = $vdt->getData('publico'); $voto->save(); $this->flash('success', 'La privacidad de su voto fue cambiada exitosamente.'); $this->redirectTo('shwPropues', array('idPro' => $propuesta->id)); } else { throw new TurnbackException('No puede votar dos veces la misma postura.'); } } } $voto->postura = $postura; $voto->publico = $vdt->getData('publico'); $voto->save(); $propuesta->increment($cfgCount[$postura]); if ($sumaPost != 0) { $propuesta->contenido->increment('puntos', $sumaPost); } if ($sumaAutr != 0) { $propuesta->contenido->autor()->increment('puntos', $sumaPost); } $this->flash('success', 'Su voto fue registrado exitosamente.'); $this->redirectTo('shwPropues', array('idPro' => $propuesta->id)); }
public function votar($idPro) { $vdt = new Validate\Validator(); $vdt->addRule('postura', new Validate\Rule\InArray(array(0, 1, 2)))->addRule('idPro', new Validate\Rule\NumNatural()); $req = $this->request; $data = array_merge(array('idPro' => $idPro), $req->post()); if (!$vdt->validate($data)) { throw new TurnbackException($vdt->getErrors()); } $usuario = $this->session->getUser(); $problemat = Problematica::with('contenido')->findOrFail($idPro); $voto = VotoProblematica::firstOrNew(array('problematica_id' => $problemat->id, 'usuario_id' => $usuario->id)); $cfgPtsAutr = [0, 1, 2]; $cfgPtsPost = [1, 2, 3]; $cfgCount = ['afectados_indiferentes', 'afectados_indirectos', 'afectados_directos']; $postura = $vdt->getData('postura'); $sumaAutr = $cfgPtsAutr[$postura]; $sumaPost = $cfgPtsPost[$postura]; if (!$voto->exists) { $usuario->increment('puntos', 3); UserlogCtrl::createLog('votProblem', $usuario->id, $problemat); } else { if ($voto->postura == $postura) { throw new TurnbackException('No puede votar dos veces la misma postura.'); } else { $fecha = Carbon\Carbon::now(); $fecha->subDays(3); if ($fecha->lt($voto->updated_at)) { throw new TurnbackException('No puede cambiar su voto tan pronto.'); } $problemat->decrement($cfgCount[$voto->postura]); $sumaAutr -= $cfgPtsAutr[$voto->postura]; $sumaPost -= $cfgPtsPost[$voto->postura]; } } $voto->postura = $postura; $voto->save(); $problemat->increment($cfgCount[$postura]); if ($sumaPost != 0) { $problemat->contenido->increment('puntos', $sumaPost); } if ($sumaAutr != 0) { $problemat->contenido->autor()->increment('puntos', $sumaPost); } $this->flash('success', 'Su voto fue registrado exitosamente.'); $this->redirectTo('shwProblem', array('idPro' => $problemat->id)); }
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 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'); }
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'); }
public function nuevaVersion($idDoc) { $vdt = new Validate\Validator(); $vdt->addRule('cuerpo', new Validate\Rule\MinLength(8))->addRule('cuerpo', new Validate\Rule\MaxLength(8192))->addFilter('cuerpo', FilterFactory::escapeHTML()); $req = $this->request; if (!$vdt->validate($req->post())) { throw new TurnbackException($vdt->getErrors()); } $documento = Documento::findOrFail($idDoc); $documento->increment('ultima_version'); $docVersion = new VersionDocumento(); $docVersion->version = $documento->ultima_version; $docVersion->documento()->associate($documento); $docVersion->save(); $parrafos = $this->parsearParrafos($vdt->getData('cuerpo')); foreach ($parrafos as $i => $parrafo) { $docParrafo = new ParrafoDocumento(); $docParrafo->cuerpo = $parrafo; $docParrafo->ubicacion = $i; $docParrafo->version()->associate($docVersion); $docParrafo->save(); } UserlogCtrl::createLog('modDocumen', $this->session->user('id'), $documento); $this->flash('success', 'Se ha creado exitosamente una nueva versión del documento.'); $this->redirectTo('shwDocumen', array('idDoc' => $documento->id)); }
public function cambiarPoder($idPat) { $vdt = new Validate\Validator(); $vdt->addRule('idPat', new Validate\Rule\NumNatural())->addRule('poderes', new Validate\Rule\Regex('/^\\[\\d*(?:,\\d+)*\\]$/')); $req = $this->request; $data = array_merge(array('idPat' => $idPat), $req->post()); if (!$vdt->validate($data)) { throw new TurnbackException($vdt->getErrors()); } $patrulla = Patrulla::findOrFail($idPat); $poderes = json_decode($vdt->getData('poderes')); $patrulla->poderes()->sync($poderes); AdminlogCtrl::createLog(implode(',', $poderes), 5, 'pod', $this->session->user('id'), $patrulla); $this->flash('success', 'Los permisos del grupo de moderación fueron modificados exitosamente.'); $this->redirectTo('shwAdmPatrull'); }
public function cambiarRol($idPar) { $vdt = new Validate\Validator(); $vdt->addRule('idPar', new Validate\Rule\NumNatural())->addRule('idUsu', new Validate\Rule\NumNatural())->addRule('jefe', new Validate\Rule\InArray(array(1, 0))); $req = $this->request; $data = array_merge(array('idPar' => $idPar), $req->post()); if (!$vdt->validate($data)) { throw new TurnbackException($vdt->getErrors()); } $partido = Partido::findOrFail($vdt->getData('idPar')); // TODO que pasa si el usuario no está en el partido? $usuario = Usuario::where(array('id' => $vdt->getData('idUsu'), 'partido_id' => $vdt->getData('idPar')))->first(); if ($usuario->id == $partido->creador_id) { throw new TurnbackException('No se puede cambiar el rol del creador del grupo.'); } else { if (is_null($usuario)) { throw new TurnbackException($usuario->identidad . ' no pertenece al grupo.'); } else { if (!($usuario->es_jefe xor $vdt->getData('jefe'))) { throw new TurnbackException('Configuración inválida.'); } } } $usuario->es_jefe = $vdt->getData('jefe'); $usuario->save(); $notificados = $partido->afiliados()->lists('id'); $log = UserlogCtrl::createLog($usuario->es_jefe ? 'newJefPart' : 'delJefPart', $usuario->id, $partido); NotificacionCtrl::createNotif($notificados, $log); $msg = $usuario->es_jefe ? ' comenzó a ' : ' dejó de '; $this->flash('success', $usuario->identidad . $msg . 'ser jefe del grupo.'); $this->redirectTo('shwModifRolPartido', array('idPar' => $idPar)); }
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'); }