public function existe(Utilizador $e) { $sql = "SELECT * utilizador_id FROM estudante WHERE utilizador_id = :utilizador_id ORDER BY id LIMIT 1"; $statement = $this->_db->prepare($sql); $statement->bindParam(':utilizador_id', $e->id()); $result = $statement->execute(); $user = $statement->fetch(PDO::FETCH_ASSOC); if ($user != null) { return true; } return false; }
public function encontrar(Utilizador $e) { $sql = "SELECT * FROM docente WHERE utilizador_id = :uid ORDER BY id LIMIT 1"; $statement = $this->_db->prepare($sql); $statement->bindParam(':utilizador_id', $e->id()); $result = $statement->execute(); $docente = $statement->fetch(PDO::FETCH_ASSOC); if ($user != null) { $id = $docente['id']; $nome = $docente['nome']; $_docente = new Docente($id, $nome, $e); return $_docente; } return false; }
public static function login() { session_start(); if ($_SERVER['REQUEST_METHOD'] === 'POST') { $email = $_POST['email']; $password = $_POST['password']; $uc = new UtilizadorControlador(); $utilizador = Utilizador::novo(); $utilizador->setEmail($email); $utilizador->setPassword($password); $utilizadorAutenticado = $uc->autenticar($utilizador); if ($utilizadorAutenticado) { $_SESSION['id'] = $utilizadorAutenticado->id(); if ($uc->eDocente($utilizadorAutenticado)) { $_SESSION['tipo'] = 'SIGNO_USER_TYPE:0'; } else { $_SESSION['tipo'] = 'SIGNO_USER_TYPE:1'; } header('location:/index.php/' . $utilizadorAutenticado->utilizador()); } else { $erros = array('Utilizador ou senha incorrectos'); $title = 'x'; renderizar('login/index'); } } else { if (!isset($_SESSION['id']) && !isset($_SESSION['tipo'])) { renderizar('login/index'); } else { self::home(); } } }
/** * Authenticates a user. * The example implementation makes sure if the username and password * are both 'demo'. * In practical applications, this should be changed to authenticate * against some persistent user identity storage (e.g. database). * @return boolean whether authentication succeeds. */ public function authenticate() { $model = Utilizador::model()->findAllByAttributes( array( 'username'=>$this->username ) ); if($model[0]) { if( $model[0]->password == $this->password ) { $this->errorCode=self::ERROR_NONE; } else { $this->errorCode=self::ERROR_PASSWORD_INVALID; } } else { $this->errorCode=self::ERROR_USERNAME_INVALID; } return !$this->errorCode; }
$_SESSION['Id'] = $UserVer->getId(); // Meter Id do utilizar em que quer fazer login $_SESSION['Old_Id'] = $User->getId(); // Para voltar a Admin echo ' <script> window.location.replace("index.php?Logged=1"); </script> '; die; } catch (Exception $e) { $Erros[] = $linguagens[$User->getLinguagem()]['alerta_erroAoFazerLogin']; } } } $UserVer = new Utilizador($Id, $conn); // Criar instância do Utilizador $UserVer->getInfo(); // Atualizar a informação do utilizador if (!$UserVer->getExiste()) { echo ' <script> window.location.replace("admin.php"); </script> '; die; } if ($UserVer == $User) { $UserVerIgual = true; } $total = 0;
if ($_POST) { if (isset($_POST['email']) && isset($_POST['password']) && !empty($_POST['email']) && !empty($_POST['password'])) { $email = $_POST['email']; $password = $_POST['password']; $email = addslashes($email); // Nunca confiar no que o utilizar introduz. $password = addslashes($password); // Nunca confiar no que o utilizar introduz. $password = md5($password); // Encriptar password com md5 $User = login($email, $password); if (!isset($User)) { header("Location: login.php?erro=2"); die; } $User = new Utilizador($User['Id'], $conn); $User->printInfo(); $_SESSION['Id'] = $User->getId(); } else { header("Location: login.php?erro=1"); die; } } if ($_GET) { if (isset($_GET['erro'])) { $erro = $_GET['erro']; if ($erro == 1) { $err[] = $_SESSION['Lang']['login_emailOuPasswordFalta']; } if ($erro == 2) { $err[] = $_SESSION['Lang']['login_emailOuPasswordErrados'];
/** * Returns the data model based on the primary key given in the GET variable. * If the data model is not found, an HTTP exception will be raised. * @param integer the ID of the model to be loaded */ public function loadModel($id) { $model=Utilizador::model()->findByPk($id); if($model===null) throw new CHttpException(404,'The requested page does not exist.'); return $model; }
<div class="view"> <table> <tr> <td width="50"> <?php $user = Utilizador::getUserById($data->utilizador_oid); echo CHtml::imageButton('.\\'.$user->teste,array( 'width'=>50, 'height'=>50 ) ); ?> </td> <td style="float:left;"> <?php echo $user->username; ?> diz, <br/> <b><?php echo CHtml::encode($data->texto); ?></b> </td> </tr> </table> </div>
public function actionDelete($idevento) { $idusr = Utilizador::getIdByUsername(Yii::app()->user->name); Favoritos::deleteFavorito($idusr,$idevento); $this->redirect(array('//favoritos/index')); }
public function actionMudaFavorito() { $idev = $_GET['idevento']; $idusr = $_GET['iduser']; $modelF = new Favoritos; $user = Utilizador::getUserById($idusr); if(Yii::app()->user->name != $user->username) echo "Hello Hacker, your ip has been registed!"; else if(Favoritos::isFavoriteUsrEv($idusr, $idev)) { Favoritos::deleteFavorito($idusr, $idev); $label = ".\./images/star_empty.png"; } else { Favoritos::insertFavorito($idusr, $idev); $label = ".\./images/star_full.png"; } echo $label; }
<?php if(!Yii::app()->user->isGuest) { $utilizador = Utilizador::getUserByUsername(Yii::app()->user->name); } $idMap = "map_canvas"; $map = "map"; $funcao = 'acertarFronteiras'; $this->renderPartial('//utils/googlemap', array( 'width'=>'100%', 'height'=>'360px', 'id'=>$idMap, 'varnamemap'=>$map, 'events'=>array( array('bounds_changed','changeFronteiras'), ), 'functioncall'=>$funcao ) ); ?> <script type="text/javascript"> var marcas = {}; function <?php echo $funcao; ?>() { <?php if(isset($utilizador)){?> var sw = new google.maps.LatLng(<?php echo $utilizador->lat;?>, <?php echo $utilizador->lon; ?>); var ne = new google.maps.LatLng(<?php echo $utilizador->lat2;?>, <?php echo $utilizador->lon2; ?>);
array('id'=>'signup','onclick'=>' $("#login-form").attr("action", "'.$this->createUrl("//utilizador/create").'"); $("#LoginForm_username").val(""); $("#LoginForm_password").val(""); window.location="'.$this->createUrl("//utilizador/create").'"') ); ?> </span> <?php $this->endWidget(); ?> </div> <?php } else { ?> <div style="float:right;"><b> Bem vindo <?php echo Yii::app()->user->name; ?>! </b> <?php echo '<br />'; echo CHtml::imageButton( Utilizador::getFotoUrlByUsername(Yii::app()->user->name), array( 'width'=>65, 'height'=>65 ) ); echo '<br/>'; echo CHtml::link('Logout',array('//site/logout')); ?> </div> <?php } ?> <script type="text/javascript"> function focus(){ if( $("#LoginForm_username").val() == "Username" ) { $("#LoginForm_username").val("");
<?php if(Yii::app()->user->isGuest) { $this->widget('zii.widgets.CMenu',array( 'items'=>array( array('label'=>'Página Inicial', 'url'=>array('/site/index')), array('label'=>'Pesquisar Eventos', 'url'=>array('//pesquisa/pesquisa')), ), )); } else if(Yii::app()->user->name != 'admin'){ $this->widget('zii.widgets.CMenu',array( 'items'=>array( array('label'=>'Página Inicial', 'url'=>array('//site/index')), array('label'=>'Pesquisar Eventos', 'url'=>array('//pesquisa/pesquisa')), array('label'=>'Ver Favoritos', 'url'=>array('//favoritos/index')), array('label'=>'Alterar Dados', 'url'=>array('//utilizador/update&id='. Utilizador::getIdByUsername(Yii::app()->user->name))), array('label'=>'Criar Evento','url'=>array('//evento/create')), array('label'=>'Os Meus Eventos','url'=>array('//evento/created')) ) )); } else { $this->widget('zii.widgets.CMenu',array( 'items'=>array( array('label'=>'Gerir Eventos', 'url'=>array('//evento/admin')), array('label'=>'Gerir Comentários', 'url'=>array('//comentario/admin')), array('label'=>'Gerir Utilizadores', 'url'=>array('//utilizador/admin')), array('label'=>'Gerir Newsletters', 'url'=>array('//newsletter/index')), ) )); } ?>
public function actionCreated() { $criterio = new CDbCriteria(); $criterio->select = 'titulo,idevento,'.'descricao,'.'dtinicio,'. 'dtfim,tipo_idtipo,'.'lat,'.'lon'; $criterio->condition = 'utilizador_oid = '. Utilizador::getIdByUsername(Yii::app()->user->name); $eventosUtilizador = new CActiveDataProvider( 'Evento', array( 'criteria'=> $criterio, 'pagination'=>array( 'pageSize'=>4, ), ) ); $this->render('created',array('eventosUtilizador'=>$eventosUtilizador)); }
header("Location: index.php"); die; } $Servidor = new Servidor($Id, $conn); $Servidor->getInfo(); $Servidor->getFullStatus(); updateRunningServers($User->getId()); } else { header("Location: index.php"); die; } $OldUser = false; if (isset($_SESSION['Old_Id']) && !empty($_SESSION['Old_Id']) && $_SESSION['Id'] != $_SESSION['Old_Id']) { $OldUser = true; try { $OldUserC = new Utilizador($_SESSION['Old_Id'], $conn); $OldUserC->getInfo(); } catch (Exception $e) { $_SESSION['Old_Id'] = ""; $OldUser = false; } } else { $OldUser = false; } $total = 0; $Servidores = getServidoresByIdUtilizador($User->getId()); if (count($Servidores)) { foreach ($Servidores as $Servidors) { $server = new Servidor($Servidors['Id'], $conn); $server->getFullStatus(); // Fazer update aos Status
die; } } } if (isset($_GET['AJAX'])) { $Pedido = $_GET['AJAX']; if ($Pedido == "AUMENTARMAXSERVIDORES") { $UserVer = new Utilizador($Id, $conn); $UserVer->getInfo(); $UserVer->setNumeroMaxServidores($UserVer->getNumeroMaxServidores() + 1); $UserVer->atualizaInfo(); echo json_encode(array("Status" => true, "MaxServidores" => $UserVer->getNumeroMaxServidores(), "Percentagem" => round(getPercentagem($UserVer->getNumeroServidores(), $UserVer->getNumeroMaxServidores())))); die; } if ($Pedido == "DIMINUIRMAXSERVIDORES") { $UserVer = new Utilizador($Id, $conn); $UserVer->getInfo(); if ($UserVer->getNumeroMaxServidores() > 0) { if ($UserVer->getNumeroServidores() < $UserVer->getNumeroMaxServidores()) { $UserVer->setNumeroMaxServidores($UserVer->getNumeroMaxServidores() - 1); $UserVer->atualizaInfo(); } } echo json_encode(array("Status" => true, "MaxServidores" => $UserVer->getNumeroMaxServidores(), "Percentagem" => round(getPercentagem($UserVer->getNumeroServidores(), $UserVer->getNumeroMaxServidores())))); die; } if ($Pedido == "InfoEstatisticas") { $Servidores = array(); $Servidores = getServidoresByIdUtilizador($User->getId()); # print_r($Servidores); $total = 0;
public function eEstudante(Utilizador $u) { $sql = "SELECT * FROM estudante WHERE utilizador_id = :id ORDER BY id LIMIT 1"; $statement = $this->_db->prepare($sql); $statement->bindParam(':id', $u->id(), PDO::PARAM_INT); $result = $statement->execute(); $estudante = $statement->fetch(PDO::FETCH_ASSOC); if ($estudante != null) { $id = $estudante['id']; $nome = $estudante['nome']; $ne = $estudante['numero_de_estudante']; $_estudante = new Estudante($id, $ne, $nome, $u); return $_estudante; } return false; }
$total = 0; $Servidores = getServidoresByIdUtilizador($User->getId()); foreach ($Servidores as $Servidor) { $server = new Servidor($Servidor['Id'], $conn); $server->getFullStatus(); // Fazer update aos Status $total += $server->getSlots(); } addInformacaoServidores($Servidores); $slotsOcupados = $total; $smarty = new Smarty(); $OldUser = false; if (isset($_SESSION['Old_Id']) && !empty($_SESSION['Old_Id']) && $_SESSION['Id'] != $_SESSION['Old_Id']) { $OldUser = true; try { $OldUserC = new Utilizador($_SESSION['Old_Id'], $conn); $OldUserC->getInfo(); } catch (Exception $e) { $_SESSION['Old_Id'] = ""; $OldUser = false; } } else { $OldUser = false; } $Sucessos = array(); $Erros = array(); if ($_POST) { if ($_POST['Action']) { $Action = $_POST['Action']; if ($Action == "MudarPassword") { if (isset($_POST['PasswordAtual']) && !empty($_POST['PasswordAtual']) && isset($_POST['NovaPassword']) && !empty($_POST['NovaPassword']) && isset($_POST['RepNovaPassword']) && !empty($_POST['RepNovaPassword'])) {
require_once __DIR__ . "/../base_dados/config.php"; // Conexão com base de dados require_once __DIR__ . "/../base_dados/functions.php"; require_once __DIR__ . "/../__classes/Utilizador.class.php"; // Classe Utilizador require_once __DIR__ . "/../__classes/Servidor.class.php"; // Classe Utilizador require_once __DIR__ . "/../includes/querys/SourceQuery.class.php"; require_once __DIR__ . "/../lang.php"; require_once __DIR__ . "/../includes/phpmailer/PHPMailerAutoload.php"; #require_once(__DIR__."/../base_dados/config.php"); $stmt = $conn->prepare(GETALLUTILIZADORES); $stmt->execute(); $utilizadoresV = $stmt->fetchAll(); foreach ($utilizadoresV as $utilizador) { $user = new Utilizador($utilizador['Id'], $conn); if (!$user->hasCron()) { continue; } $mail = new PHPMailer(); $mail->isSMTP(); $mail->Host = $email_host; $mail->SMTPAuth = true; $mail->Username = $email_user; $mail->Password = $email_pass; $mail->SMTPSecure = $email_sec; $mail->Port = $email_port; $mail->setFrom('*****@*****.**', 'CyberPanel - Servers Info'); $mail->isHTML(true); $stmt = $conn->prepare(GETSERVIDORBYIDUTILIZADOR); $stmt->execute(array(":IdUtilizador" => $user->getId()));