PageRenderTime 36ms CodeModel.GetById 9ms RepoModel.GetById 1ms app.codeStats 0ms

/vistas/registrar.php

https://gitlab.com/FerSo/tesis
PHP | 129 lines | 113 code | 15 blank | 1 comment | 14 complexity | 0c5ee44f61c786b1be05812604067aa4 MD5 | raw file
  1. <?session_start();?>
  2. <html>
  3. <?php include("../partes/head.php"); ?>
  4. <body>
  5. <?php include("../partes/header.php");
  6. if(!isset($_SESSION['usuario_nombre'])){?>
  7. <div class="container animated fadeInRight" style="max-width: 550px">
  8. <div class="row subtitle">
  9. <h1>
  10. <center>
  11. Registrate
  12. </center>
  13. </h1>
  14. </div>
  15. <p>Crea una cuenta para compartir..</p>
  16. <?php
  17. if (isset($_POST['enviar'])) {
  18. function valida_email($correo)
  19. {
  20. if (preg_match('/^[A-Za-z0-9-_.+%]+@[A-Za-z0-9-.]+\.[A-Za-z]{2,4}$/', $correo)) return true;
  21. else return false;
  22. }
  23. $sin_espacios = count_chars($_POST['usuario_nombre'], 1);
  24. if (!empty($sin_espacios[32])) {
  25. echo "El campo <em>usuario_nombre</em> no debe contener espacios en blanco. <a href='javascript:history.back();'>Reintentar</a>";
  26. } elseif (empty($_POST['usuario_nombre'])) {
  27. echo "No haz ingresado tu usuario. <a href='javascript:history.back();'>Reintentar</a>";
  28. } elseif (empty($_POST['nombre'])) {
  29. echo "No haz ingresado tu nombre. <a href='javascript:history.back();'>Reintentar</a>";
  30. } elseif (empty($_POST['apellido'])) {
  31. echo "No haz ingresado tu apellido. <a href='javascript:history.back();'>Reintentar</a>";
  32. } elseif (empty($_POST['usuario_clave'])) {
  33. echo "No haz ingresado contraseña. <a href='javascript:history.back();'>Reintentar</a>";
  34. } elseif ($_POST['usuario_clave'] != $_POST['usuario_clave_conf']) {
  35. echo "Las contraseñas ingresadas no coinciden. <a href='javascript:history.back();'>Reintentar</a>";
  36. } elseif (!valida_email($_POST['usuario_email'])) {
  37. echo "El email ingresado no es válido. <a href='javascript:history.back();'>Reintentar</a>";
  38. } else {
  39. $usuario_nombre = mysql_real_escape_string($_POST['usuario_nombre']);
  40. $nombre = mysql_real_escape_string($_POST['nombre']);
  41. $apellido = mysql_real_escape_string($_POST['apellido']);
  42. $usuario_clave = mysql_real_escape_string($_POST['usuario_clave']);
  43. $usuario_email = mysql_real_escape_string($_POST['usuario_email']);
  44. $sql = mysql_query("SELECT usuario_nombre FROM usuarios WHERE usuario_nombre='" . $usuario_nombre . "'");
  45. if (mysql_num_rows($sql) > 0) {
  46. echo "El nombre usuario elegido ya ha sido registrado anteriormente. <a href='javascript:history.back();'>Reintentar</a>";
  47. } else {
  48. $usuario_clave = md5($usuario_clave); // encriptamos la contraseña ingresada con md5
  49. // ingresamos los datos a la BD
  50. $reg = mysql_query("INSERT INTO usuarios (usuario_nombre, nombre, apellido, usuario_clave, usuario_email, fecha_reg) VALUES ('" . $usuario_nombre . "', '" . $nombre . "', '" . $apellido . "', '" . $usuario_clave . "', '" . $usuario_email . "', NOW())");
  51. $consult = mysql_query("SELECT id_usuario FROM usuarios WHERE usuario_nombre = '" . $usuario_nombre . "'");
  52. $cons = mysql_fetch_array($consult);
  53. $modulo = "Resgistrarse";
  54. $accion = "Nuevo Usuario: " . $usuario_nombre . "";
  55. $bit = mysql_query("INSERT INTO bitacora (id_usuario, fecha, modulo, accion) VALUES ('" . $cons[0] . "', NOW(),'" . $modulo . "' , '" . $accion . "')");
  56. if ($bit) {
  57. echo "Datos ingresados correctamente.";
  58. } else {
  59. echo "ha ocurrido un error y no se registraron los datos.";
  60. }
  61. if ($reg) {
  62. echo "Datos ingresados correctamente. <a class=\"btn-primary btn-xs\" href=\"acceso.php\">Inicia Sesión</a>";
  63. } else {
  64. echo "ha ocurrido un error y no se registraron los datos.";
  65. }
  66. }
  67. }
  68. } else {
  69. ?>
  70. <form action="<?= $_SERVER['PHP_SELF'] ?>" method="post">
  71. <div class="form-group">
  72. <input type="text" name="usuario_nombre" class="form-control" placeholder="Nombre de Usuario"
  73. maxlength="15" minlength="6" required="">
  74. </div>
  75. <div class="form-group">
  76. <input type="text" name="nombre" class="form-control" placeholder="Nombre" maxlength="15"
  77. minlength="3" required="">
  78. </div>
  79. <div class="form-group">
  80. <input type="text" name="apellido" class="form-control" placeholder="Apellido" maxlength="15"
  81. minlength="3" required="">
  82. </div>
  83. <div class="form-group">
  84. <input type="password" name="usuario_clave" class="form-control" placeholder="Contraseña"
  85. maxlength="15" minlength="6" required="">
  86. </div>
  87. <div class="form-group">
  88. <input type="password" name="usuario_clave_conf" class="form-control"
  89. placeholder="Confirmar Contraseña" maxlength="15" minlength="6" required="">
  90. </div>
  91. <div class="form-group">
  92. <input type="email" name="usuario_email" class="form-control" placeholder="Correo Electrónico"
  93. maxlength="50" minlength="6" required="">
  94. </div>
  95. <input type="submit" name="enviar" value="Registrar" class="btn-primary">
  96. </input><input class="btn-info" style="background-color: dimgrey; border-color: dimgrey;" type="reset" value="Limpiar"/>
  97. <p class="text-muted text-center">
  98. <small>Ya tienes una cuenta?</small>
  99. </p>
  100. <a class="btn-primary btn-xs" href="acceso.php">Inicia Sesión</a>
  101. </form>
  102. <?php } ?>
  103. </div>
  104. <?php
  105. }else{ ?>
  106. <script>
  107. window.location="../vistas/index.php";
  108. </script><?
  109. }
  110. include("../partes/footer.php");
  111. include("../partes/scripts.php");
  112. ?>
  113. </body>
  114. </html>