-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunciones.php
98 lines (76 loc) · 2.3 KB
/
funciones.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
<?php
include("config.php");
session_set_cookie_params($config['session_time']);
session_name($config['session_name']);
session_start();
if (!Conectar()) {
exit;
}
if($_GET["token"]){
$_SESSION["token"] = $_GET["token"];
}
if( $_SESSION["token"] ) {
$userDetail = file_get_contents("https://oauth2.googleapis.com/tokeninfo?id_token=".$_SESSION["token"]);
$userData = json_decode($userDetail);
if(!empty($userData)){
$googleEmail = $userData->email;
$googleImage = $userData->picture;
$googleName = $userData->name;
$sql = "select id,perfil from users where email='$googleEmail' and activo ='1' ";
$Result = mysqli_query($mysqli_link,$sql);
$Reg = mysqli_fetch_row($Result);
$userid = $Reg[0];
$perfil = $Reg[1];
if (mysqli_num_rows($Result) == 0) {
echo "El usuario no esta activo, contacte con el Administrador<br>";
echo "<a href='login.php?logout=1'>volver</a>";
exit;
}else{
$sql = "update users set fecha_login=NOW() where email='$googleEmail'; ";
$Result = mysqli_query($mysqli_link,$sql);
}
}else{
echo "Login fail<br>";
echo "<a href='login.php?logout=1'>volver</a>";
exit;
}
}else{
header('Location: login.php');
exit;
}
function Conectar(){
global $config, $mensaje, $mysqli_link;
$mysqli_link=mysqli_connect($config['db_servidor'],$config['db_usuario'],$config['db_password']);
if(!$mysqli_link){
$mensaje = "Error: error de conexion con mysql";
return False;
}
if( mysqli_select_db($mysqli_link,$config['db_db']) ){
mysqli_set_charset($mysqli_link,'utf8');
return $mysqli_link;
}
$mensaje = "Error: error accediendo a la base de datos";
return False;
}
function validar($string){
// filtro de caracteres enviados por POST
$allowed = "/[^a-zA-Z0-9\\.\\-\\_ \\,\\)\\(\\[\\]\\@\\á\\é\\í\\ó\\ú\\ñ\\Ñ\\!\\?\\$\\:]/i";
return preg_replace($allowed," ",$string);
}
function permiso($perfil,$permiso){
// determina si el perfil tiene permisos para el menu
global $mysqli_link;
$sql = "select $permiso from perfiles_permisos where perfil_id='$perfil' ";
$Result = mysqli_query($mysqli_link,$sql);
if(!$Result){
return false;
}else{
$Reg = mysqli_fetch_row($Result);
if($Reg[0] == '1'){
return true;
}else{
return false;
}
}
}
?>