2016-10-29 15:07:15 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
|
|
function login_boton($formulario){
|
|
|
|
if($formulario =='x') {
|
|
|
|
session_destroy();
|
|
|
|
$respuesta = new xajaxResponse('utf-8');
|
|
|
|
$respuesta->addRedirect("index.php");
|
|
|
|
return $respuesta;
|
|
|
|
}
|
2016-10-29 22:14:19 +00:00
|
|
|
|
2016-10-29 15:07:15 +00:00
|
|
|
if(isset($_SESSION['id'])){
|
|
|
|
|
|
|
|
$accion = "<li><a class=' btn ' onclick=\"xajax_login_boton('x') \"><i class='glyphicon glyphicon-log-out fa-fw'></i>$_SESSION[username]</a></li>";
|
|
|
|
}else{
|
|
|
|
$accion = registro_express("nuevo_$nombre_formato","boton");
|
|
|
|
print $accion;
|
|
|
|
return;
|
|
|
|
// return $login;
|
|
|
|
}
|
|
|
|
$resultado ="
|
|
|
|
<div id='login_div' name='login_div' style='' >
|
|
|
|
<ul class='nav navbar-nav navbar-right' >
|
|
|
|
$accion
|
2016-10-29 22:14:19 +00:00
|
|
|
</ul>
|
2016-10-29 15:07:15 +00:00
|
|
|
</div>
|
2016-10-29 22:14:19 +00:00
|
|
|
";
|
2016-10-29 15:07:15 +00:00
|
|
|
print $resultado;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
$xajax->registerFunction("login_boton");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function revisar_ingreso($formulario){
|
|
|
|
$formulario = mysql_seguridad($formulario);
|
|
|
|
if($formulario =="") {
|
|
|
|
$formulario ="
|
|
|
|
<form class='form-horizontal' id='form-contacto' name='form-contacto' >
|
2016-10-29 22:14:19 +00:00
|
|
|
<fieldset>
|
2016-10-29 15:07:15 +00:00
|
|
|
<label class='' for='email'>Correo o usuario</label>
|
|
|
|
<div class='input-group' id='grupo_email'>
|
|
|
|
<span class='input-group-addon'><i class='glyphicon glyphicon-user fa-fw'></i></span>
|
|
|
|
<input id='email'name='email' class='form-control input-large' type='email' placeholder ='Correo o usuario'>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
<!-- Text input-->
|
|
|
|
|
2016-10-29 22:14:19 +00:00
|
|
|
|
2016-10-29 15:07:15 +00:00
|
|
|
<label class='control-label' for='password'>Clave</label>
|
|
|
|
<div class='input-group' >
|
|
|
|
<span class='input-group-addon'><i class='glyphicon glyphicon-lock fa-fw'></i></span>
|
2016-10-29 22:14:19 +00:00
|
|
|
<input class='form-control input-large' id='password' name='password' type='password' placeholder='clave' required='' >
|
2016-10-29 15:07:15 +00:00
|
|
|
</div>
|
2016-10-29 22:14:19 +00:00
|
|
|
|
2016-10-29 15:07:15 +00:00
|
|
|
<div class='input-group'>
|
|
|
|
<label for='recordar'>No recuerdo mi clave
|
|
|
|
<input type='radio' value ='1' id='recordar' name='recordar' >
|
|
|
|
</div>
|
|
|
|
|
|
|
|
</fieldset>
|
|
|
|
</form>
|
|
|
|
";
|
|
|
|
$resultado = "
|
|
|
|
<div id='login_ok'>
|
|
|
|
$formulario
|
|
|
|
<!-- Button -->
|
|
|
|
<div class='control-group'>
|
|
|
|
<label class='control-label' for='signin'></label>
|
|
|
|
<div class='controls'>
|
|
|
|
<button id='ingresar' name='ingresar' class='btn btn-success btn-block' onclick=\"xajax_revisar_ingreso(xajax.getFormValues('form-contacto')) \">Ingresar</button>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<br>
|
|
|
|
<div id='login_info'></div>
|
|
|
|
</div>
|
|
|
|
";
|
|
|
|
if(!isset($_SESSION['id'])){ print $resultado; }else {
|
|
|
|
|
|
|
|
//print $nuevo ;
|
|
|
|
}
|
2016-10-29 22:14:19 +00:00
|
|
|
return;
|
2016-10-29 15:07:15 +00:00
|
|
|
}
|
|
|
|
include("includes/datos.php");
|
|
|
|
$div='contenido';
|
|
|
|
$respuesta = new xajaxResponse('utf-8');
|
|
|
|
|
|
|
|
$email = $formulario[email];
|
|
|
|
$recordar = $formulario[recordar];
|
|
|
|
|
2016-10-29 22:14:19 +00:00
|
|
|
|
2016-10-29 15:07:15 +00:00
|
|
|
if($email =='') {
|
|
|
|
|
|
|
|
$respuesta->addAlert("Ingresa tu nombre de usuario o email");
|
|
|
|
return $respuesta;
|
2016-10-29 22:14:19 +00:00
|
|
|
}
|
2016-10-29 15:07:15 +00:00
|
|
|
if($formulario[password] =='' AND $recordar =='') {
|
|
|
|
|
|
|
|
$respuesta->addAlert("Ingresa tu clave");
|
|
|
|
return $respuesta;
|
|
|
|
}
|
|
|
|
$password= MD5($formulario[password]);
|
2016-10-29 22:14:19 +00:00
|
|
|
$link=Conectarse();
|
2016-10-29 15:07:15 +00:00
|
|
|
mysqli_set_charset($link, "utf8");
|
2016-10-29 22:14:19 +00:00
|
|
|
|
|
|
|
if($recordar =='1')
|
2016-10-29 15:07:15 +00:00
|
|
|
{
|
2016-10-29 22:14:19 +00:00
|
|
|
if($email =='')
|
|
|
|
{
|
2016-10-29 15:07:15 +00:00
|
|
|
$tipo='danger';
|
|
|
|
$mensaje ="Por favor escribe tu <strong>correo o usuario</strong> si olvidaste tu clave.";
|
|
|
|
$respuesta->addAssign($div,"innerHTML",$mensaje);
|
|
|
|
return $respuesta;
|
|
|
|
}else
|
|
|
|
{
|
|
|
|
$consulta = "SELECT id,email,control,id_empresa FROM $tabla_autenticacion WHERE (email = '$email' OR username = '$email' )";
|
|
|
|
$sql=mysqli_query($link,$consulta);
|
|
|
|
if (mysqli_num_rows($sql)!='0')
|
|
|
|
{
|
2016-10-29 22:14:19 +00:00
|
|
|
$firma_recuperacion = sha1("$control".mktime()."");
|
2016-10-29 15:07:15 +00:00
|
|
|
$correo = mysqli_result($sql,0,"email");
|
|
|
|
$control = mysqli_result($sql,0,"control");
|
|
|
|
$id_usuario = mysqli_result($sql,0,"id");
|
|
|
|
$id_empresa = mysqli_result($sql,0,"id_empresa");
|
|
|
|
$firma ="UPDATE $tabla_autenticacion SET `firma_recuperacion` = '$firma_recuperacion' WHERE `usuarios`.`id` = '$id_usuario';";
|
|
|
|
$cambiar_firma=mysqli_query($link,$firma);
|
|
|
|
$tipo='success';
|
|
|
|
|
|
|
|
$direccion = remplacetas("empresa","id",$id_empresa,"direccion","");
|
|
|
|
$telefono = remplacetas("empresa","id",$id_empresa,"telefono","");
|
|
|
|
$web = remplacetas("empresa","id",$id_empresa,"web","");
|
|
|
|
$email = remplacetas("empresa","id",$id_empresa,"email","");
|
|
|
|
$imagen = remplacetas("empresa","id",$id_empresa,"imagen","");
|
|
|
|
$razon_social = remplacetas("empresa","id",$id_empresa,"razon_social","");
|
|
|
|
$slogan = remplacetas("empresa","id",$id_empresa,"slogan","");
|
|
|
|
|
2016-10-29 22:14:19 +00:00
|
|
|
$headers = "MIME-Version: 1.0\r\n";
|
|
|
|
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
|
|
|
|
$headers .= "From: $razon_social[0] <$email[0]>\r\n";
|
|
|
|
$headers .= "Reply-To: $email[0]\r\n";
|
|
|
|
$headers .= "Return-path: $email[0]\r\n";
|
2016-10-29 15:07:15 +00:00
|
|
|
|
|
|
|
$asunto= "Cambio de clave";
|
|
|
|
$cuerpo ="
|
|
|
|
$razon_social[0]
|
|
|
|
<div style='border: solid 1px; padding:20px ; border-radius: 10px; background-color:#E6F8E0 '>
|
|
|
|
<h1>Aplicación de formularios</h1>
|
|
|
|
|
|
|
|
<hr />
|
|
|
|
<p>Se ha solicitado un cambio de clave para tu usuario.<br />
|
|
|
|
Si fuiste tu quien lo solicitó, sigue este <a href='http://$_SERVER[HTTP_HOST]/milfs/index.php?change=$firma_recuperacion'>enlace</a> para realizar el cambio.</p>
|
|
|
|
http://$_SERVER[HTTP_HOST]/milfs/index.php?change=$firma_recuperacion
|
|
|
|
|
|
|
|
<h3>Si no solicitaste el cambio, por favor comunícalo respondiendo este correo.</h3>
|
|
|
|
</div>
|
2016-10-29 22:14:19 +00:00
|
|
|
|
2016-10-29 15:07:15 +00:00
|
|
|
";
|
|
|
|
$mensaje =" Enviamos un correo con la confirmación a $correo";
|
|
|
|
mail("$correo","$asunto","$cuerpo","$headers") ;
|
2016-10-29 22:14:19 +00:00
|
|
|
}else
|
2016-10-29 15:07:15 +00:00
|
|
|
{
|
|
|
|
$tipo='danger';
|
|
|
|
$mensaje ="El <strong>correo o usuario</strong> no se encuentra registrado aún.";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$resultado ="<div class='alert alert-$tipo'>$mensaje</div>";
|
|
|
|
$respuesta->addAssign($div,"innerHTML",$resultado);
|
|
|
|
|
|
|
|
return $respuesta;
|
|
|
|
}
|
2016-10-29 22:14:19 +00:00
|
|
|
|
2016-10-29 15:07:15 +00:00
|
|
|
//$consulta = "SELECT * FROM $tabla_autenticacion WHERE (email = '$email' OR username = '$email' )AND passwd = '$password' LIMIT 1";
|
2016-10-29 22:14:19 +00:00
|
|
|
$consulta= "SELECT *
|
|
|
|
FROM $tabla_autenticacion, usuarios_grupo
|
|
|
|
WHERE (email = '$email' OR username = '$email' )AND passwd = '$password'
|
|
|
|
AND $tabla_autenticacion.id_grupo = usuarios_grupo.id
|
|
|
|
LIMIT 1";
|
2016-10-29 15:07:15 +00:00
|
|
|
|
|
|
|
$sql=mysqli_query($link,$consulta);
|
|
|
|
if (mysqli_num_rows($sql)!='0'){
|
|
|
|
if(mysqli_result($sql,0,"status") === '0' ) {
|
|
|
|
$resultado = "
|
2016-10-29 22:14:19 +00:00
|
|
|
<div class='alert alert-danger' >
|
2016-10-29 15:07:15 +00:00
|
|
|
Aún no se ha confirmado tu email, por favor revisa tu correo</p>
|
|
|
|
</div >";
|
|
|
|
//$div ="login_ok";
|
|
|
|
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
//session_destroy();
|
|
|
|
$_SESSION = array();
|
|
|
|
$_SESSION['username']= mysqli_result($sql,0,"username");
|
|
|
|
$_SESSION['id']= mysqli_result($sql,0,"id");
|
|
|
|
$_SESSION['grupo']= mysqli_result($sql,0,"id_grupo");
|
|
|
|
$_SESSION['tabla_autenticacion']= "$tabla_autenticacion";
|
|
|
|
$_SESSION['prioridad'] = mysqli_result($sql,0,"prioridad");
|
|
|
|
$_SESSION['id_empresa']= mysqli_result($sql,0,"id_empresa");
|
|
|
|
$_SESSION[$usuarios_sesion]= "$usuarios_sesion";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$resultado .="
|
|
|
|
$sucursal
|
2016-10-29 22:14:19 +00:00
|
|
|
|
2016-10-29 15:07:15 +00:00
|
|
|
<div class=' alert alert-success'><h3><b>Hola $_SESSION[username] </b</h3></div>";
|
|
|
|
//$url=urlencode('../index.php');
|
|
|
|
//$respuesta->addRedirect("$_SESSION[site]");
|
|
|
|
$respuesta->addScript("window.location='../'");
|
|
|
|
//header("Location: ../");
|
|
|
|
//return;
|
2016-10-29 22:14:19 +00:00
|
|
|
}
|
2016-10-29 15:07:15 +00:00
|
|
|
}else{
|
|
|
|
$resultado = "
|
2016-10-29 22:14:19 +00:00
|
|
|
<div class='alert alert-danger' >
|
|
|
|
Los datos no son correctos, por favor rectifica o ponte en contacto con el area de soporte para mas información.</p>
|
2016-10-29 15:07:15 +00:00
|
|
|
</div >";
|
|
|
|
}
|
|
|
|
$respuesta->addAssign($div,"innerHTML",$resultado);
|
|
|
|
return $respuesta;
|
|
|
|
}
|
2016-10-29 22:14:19 +00:00
|
|
|
|
2016-10-29 15:07:15 +00:00
|
|
|
$xajax->registerFunction("revisar_ingreso");
|
|
|
|
|
|
|
|
function cambiar_password_formato($change) {
|
|
|
|
$firma_recuperacion = remplacetas("usuarios","firma_recuperacion",$change,"firma_recuperacion") ;
|
|
|
|
if($firma_recuperacion[0] =='') {
|
|
|
|
$formato ="<div class='alert alert-danger'><h1>Lo sentimos</h1><p>El Link ya no es válido</p></div>";
|
2016-10-29 22:14:19 +00:00
|
|
|
return $formato;
|
2016-10-29 15:07:15 +00:00
|
|
|
}
|
|
|
|
$formato="
|
|
|
|
<DIV id='cambio_password'>
|
|
|
|
<div class='container alert alert-warning'>
|
|
|
|
<div class='row'>
|
2016-10-29 22:14:19 +00:00
|
|
|
|
2016-10-29 15:07:15 +00:00
|
|
|
<form role='form' id='cambiar_password_form' name='cambiar_password_form'>
|
|
|
|
<fieldset>
|
|
|
|
<legend class='text-center'>Cambio de clave</legend>
|
|
|
|
<div class='col-sm-6'>
|
|
|
|
<div style='margin-bottom: 25px' class='input-group' id='password_nuevo_grupo'>
|
|
|
|
<span class='input-group-addon'><i class='glyphicon glyphicon-unlock-alt fa-fw'></i></span>
|
|
|
|
<input id='password_nuevo' type='password' class='form-control' name='password_nuevo' placeholder='Nuevo password'>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div class='col-sm-6'>
|
|
|
|
<div style='margin-bottom: 25px' class='input-group' id='password_confirmacion_grupo'>
|
|
|
|
<span class='input-group-addon' ><i class='glyphicon glyphicon-lock fa-fw'></i></span>
|
|
|
|
<input id='password_confirmacion' type='password' class='form-control' name='password_confirmacion' placeholder='Confirmar password'
|
|
|
|
onchange= \"xajax_confirma_campo((document.getElementById('password_nuevo').value),(this.value),'password_nuevo','password_confirmacion'); \" >
|
|
|
|
</div>
|
2016-10-29 22:14:19 +00:00
|
|
|
|
2016-10-29 15:07:15 +00:00
|
|
|
</div>
|
|
|
|
</fieldset>
|
2016-10-29 22:14:19 +00:00
|
|
|
|
|
|
|
|
2016-10-29 15:07:15 +00:00
|
|
|
</div>
|
|
|
|
<input type='hidden' id='firma_recuperacion' name='firma_recuperacion' value='$change'>
|
|
|
|
<a onclick=\"xajax_cambiar_password(xajax.getFormValues('cambiar_password_form')); \" class='btn btn-danger btn-block'>Grabar</a>
|
|
|
|
</form>
|
|
|
|
</DIV>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
";
|
|
|
|
return $formato;
|
|
|
|
}
|
|
|
|
|
|
|
|
function cambiar_password($formulario){
|
|
|
|
// if ( !isset ( $_SESSION['id'] ) ) { return;}
|
|
|
|
$respuesta = new xajaxResponse('utf-8');
|
|
|
|
$formulario = mysql_seguridad($formulario);
|
|
|
|
$actual= $formulario[password_actual];
|
|
|
|
$nuevo= $formulario[password_nuevo];
|
|
|
|
$confirmacion= $formulario[password_confirmacion];
|
|
|
|
$firma = $formulario[firma_recuperacion];
|
|
|
|
$firma_recuperacion = remplacetas("usuarios","firma_recuperacion",$formulario[firma_recuperacion],"firma_recuperacion") ;
|
|
|
|
if(isset($firma)) {$actual = $firma; $id_usuario = $firma_recuperacion[1]; }else{$id_usuario = $_SESSION[id]; }
|
|
|
|
$verifica = remplacetas("usuarios","id",$_SESSION[id],"passwd") ;
|
|
|
|
|
|
|
|
$size= strlen($nuevo);
|
|
|
|
if($nuevo != $confirmacion OR $actual =="" ){
|
2016-10-29 22:14:19 +00:00
|
|
|
|
2016-10-29 15:07:15 +00:00
|
|
|
$respuesta->addAlert("Los valores no coinciden ( $formulario[firma_recuperacion] ) $nuevo != $confirmacion $formulario[firma_recuperacion] $firma $actual \OR $actual");
|
|
|
|
return $respuesta;
|
|
|
|
}elseif($size < 8) {
|
|
|
|
$respuesta->addAlert("Use un password mas seguro: Mínimo 8 caracteres.");
|
|
|
|
return $respuesta;
|
|
|
|
}
|
|
|
|
elseif( $firma_recuperacion[0] != $formulario[firma_recuperacion]){
|
|
|
|
$respuesta->addAlert("El link ya no es valido");
|
|
|
|
return $respuesta;
|
|
|
|
|
|
|
|
}
|
|
|
|
elseif($formulario[firma_recuperacion] =='' AND $verifica[0] != MD5($actual) ){
|
|
|
|
$respuesta->addAlert("Error de password $formulario[firma_recuperacion]");
|
|
|
|
return $respuesta;
|
|
|
|
}else{}
|
2016-10-29 22:14:19 +00:00
|
|
|
|
|
|
|
$link=Conectarse();
|
2016-10-29 15:07:15 +00:00
|
|
|
mysqli_set_charset($link, "utf8");
|
|
|
|
$nueva_firma = sha1(mktime());
|
|
|
|
$consulta = "UPDATE usuarios SET passwd = '".MD5($nuevo)."' , firma_recuperacion = '$nueva_firma' WHERE id = $id_usuario;";
|
|
|
|
$sql_consulta=mysqli_query($link,$consulta);
|
|
|
|
if($sql_consulta) {
|
2016-10-29 22:14:19 +00:00
|
|
|
$resultado = "<div class='alert alert-success'>La clave se cambió con éxito.</div>";
|
2016-10-29 15:07:15 +00:00
|
|
|
}else{$resultado= "";}
|
|
|
|
$respuesta->addAlert("La clave se cambió con éxito.");
|
|
|
|
$respuesta->addRedirect("index.php");
|
|
|
|
return $respuesta;
|
|
|
|
}
|
2016-10-29 22:14:19 +00:00
|
|
|
|
2016-10-29 15:07:15 +00:00
|
|
|
$xajax->registerFunction("cambiar_password");
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-10-29 22:14:19 +00:00
|
|
|
?>
|