-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconsultas_offsession.php
More file actions
71 lines (54 loc) · 2.15 KB
/
consultas_offsession.php
File metadata and controls
71 lines (54 loc) · 2.15 KB
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
<?php
include 'conectionDB.php';
include 'EnviarMail.php';
date_default_timezone_set('America/Argentina/Salta');
if( isset($_POST['Registrar']) ) {
$email = strip_tags($_POST['email']);
$user_name = strip_tags($_POST['usuario']);
$password = strip_tags($_POST['password']);
$password_r = strip_tags($_POST['password_r']);
$codigo = rand(0, 9999);
$msg = "";
$data = array();
$data['status'] = true;
$data['data'] = "";
$data['error'] = "";
$data['status_email'] = false;
$data['data_email'] = "";
$data['error_email'] = "";
//*
//aquí como todo estuvo OK, resta controlar que no exista previamente el mail ingresado en la tabla users.
$result = $conn->query("SELECT * FROM `users` WHERE `email` = '".$email."' OR `username` = '".$user_name."' ");
$users = $result->fetch_all(MYSQLI_ASSOC);
//cuento cuantos elementos tiene $tabla,
$count = count($users);
//solo si no hay un usuario con mismo mail o username, procedemos a insertar fila con nuevo usuario
if ($count == 0){
$password= hash("sha256",strip_tags($_POST['password']));
$sql = "INSERT INTO `users`(`id`, `username`, `password`, `salt`, `is_superuser`, `fecha_creado`, `email`, `codigo`, `status`) VALUES (NULL,'$user_name','$password','0','0',CURRENT_TIMESTAMP,'$email','$codigo','0')";
if(mysqli_query($conn,$sql)){
$data['status'] = true;
$data['data'] = "Usuario creado correctamente, chequear su correo electronico y confirmar via email";
$data_email = EnviarMail_Prueba($email,$user_name);
$data['status_email'] = $data_email['status_email'];
}else {
$data['status'] = false;
$data['error'] ="Error al cargar en base de datos";
}
}else{
$data['status'] = false;
$result = $conn->query("SELECT * FROM `users` WHERE `email` = '".$email."' ");
$users = $result->fetch_all(MYSQLI_ASSOC);
//cuento cuantos elementos tiene $tabla,
$count = count($users);
if ($count == 0){
$data['error'] ="El nombre de usuario ya existe";
}
else{
$data['error'] ="El mail ingresado ya existe";
}
}
//*/
echo json_encode($data, JSON_FORCE_OBJECT);
}
?>