Guest User

Untitled

a guest
Nov 25th, 2017
422
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.55 KB | None | 0 0
  1. CREATE DEFINER=`root`@`localhost` FUNCTION `valid`(p_senha varchar(50), p_email varchar(150), p_service int(1)) RETURNS varchar(200) CHARSET utf8
  2. BEGIN
  3. DECLARE vn_token VARCHAR(200);
  4. DECLARE vn_cod_cli INT(50);
  5. DECLARE vn_auth INT(50);
  6. DECLARE vn_sequencia INT(50);
  7.  
  8.  
  9. if p_email is null or p_service is null or p_senha is null then
  10.  
  11. return '1';
  12. else
  13.  
  14. select sequencia
  15. into vn_cod_cli
  16. from clientes
  17. where email = p_email
  18. and senha = (select md5(p_senha));
  19.  
  20. if vn_cod_cli is null then
  21.  
  22. return '2';
  23. else
  24.  
  25. select upper(replace(UUID(), '-', ''))
  26. into vn_token;
  27.  
  28. select sequencia, auth
  29. into vn_sequencia, vn_auth
  30. from auth
  31. where cod_cli = vn_cod_cli;
  32.  
  33. if vn_sequencia is null then
  34.  
  35. insert into auth (hash, auth, geracao, cod_cli, service)
  36. values (vn_token, 'N', now(), vn_cod_cli, service);
  37.  
  38. return vn_token;
  39. elseif vn_auth = 'N' then
  40.  
  41. return vn_token;
  42.  
  43. else
  44.  
  45. return '3';
  46.  
  47. end if;
  48. end if;
  49. end if;
  50. end
  51.  
  52. <?php
  53.  
  54. use PHPMailerPHPMailerPHPMailer;
  55. use PHPMailerPHPMailerException;
  56.  
  57.  
  58. require 'PHPMailer/vendor/autoload.php';
  59. require_once('acessabanco.php');
  60.  
  61. $email = $_POST['em'];
  62. $senha = $_POST['pass'];
  63.  
  64. $objDb = new db();
  65. $link = $objDb->conecta_banco();
  66.  
  67. $func = "SELECT valid('$senha', '$email', 1) return";
  68.  
  69. $exec = mysqli_query($link, $func);
  70.  
  71. if ($exec){
  72.  
  73. $arr = mysqli_fetch_array($exec);
  74.  
  75. $return = $arr['return'];
  76. if ($return == '1'){
  77.  
  78. echo('<div class="alert alert-danger"><strong>Atenção </strong>Dados imcompletos</div>');
  79. } else if ($return == '2'){
  80.  
  81. echo('<div class="alert alert-danger"><strong>Atenção </strong>O email informado não existe em nosso sistema, cadastre-se!</div>');
  82. } else if ($return == '3'){
  83.  
  84. echo('200');
  85. } else {
  86.  
  87. $token = $return;
  88.  
  89. $mail = new PHPMailer(true);
  90. try {
  91.  
  92. $mail->CharSet = 'UTF-8';
  93. $mail->isSMTP();
  94. $mail->Host = 'smtp.gmail.com';
  95. $mail->SMTPAuth = true;
  96. $mail->Username = 'noreplayanuncieja@gmail.com';
  97. $mail->Password = '*******';
  98. $mail->SMTPSecure = 'tls';
  99. $mail->Port = 587;
  100. $mail->SMTPOptions = array (
  101. 'ssl' => array (
  102. 'verify_peer' => false,
  103. 'verify_peer_name' => false,
  104. 'allow_self_signed' => true));
  105.  
  106. $mail->setFrom($email, 'Recuperação de Conta');
  107. $mail->addAddress($email, 'Recuperação de Conta');
  108.  
  109. $mail->isHTML(true);
  110. $mail->Subject = 'Here is the subject';
  111. $mail->Body = $token;
  112. $mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
  113.  
  114. $mail->send();
  115. echo('<div class="alert alert-success"><strong>Prezado amigo,</strong> enviamos um email para você com um token, ele irá expirar em 20 minutos, informe-o para validar sua conta em nosso sistema.! </div>');
  116. } catch (Exception $e) {
  117. echo 'Message could not be sent.';
  118. echo 'Mailer Error: ' . $mail->ErrorInfo;
  119. }
  120.  
  121. }
  122.  
  123. } else {
  124.  
  125. echo('<div class="alert alert-danger"><strong>Atenção </strong>Falha na comunicação com o servidor devido a manutenções. Tente novamente mais tarde.</div>');
  126. }
  127. ?>
  128.  
  129. $(document).ready(function () {
  130.  
  131. $('#forgot_it').css('display', 'none');
  132. $("#recovery").click(function(){
  133. $("#forgot_it").toggle("slow");
  134. $("#login").toggle("hide");
  135. });
  136.  
  137. $("#env_token").click(function(){
  138. if ($("#forgot_email").val() == ''){
  139.  
  140. $("#forgot_email").effect( "shake", {times:3}, 1000 );
  141. } else {
  142.  
  143. }
  144. });
  145.  
  146. $("#remember").click(function(){
  147. $("#forgot_it").toggle("hide");
  148. $("#login").toggle("slow");
  149. });
  150.  
  151. $("#efetuar_login").click(function () {
  152. if ($("#email").val() == ''){
  153.  
  154. $("#email").effect( "shake", {times:3}, 1000 );
  155. } else if ($("#password").val() == ''){
  156.  
  157. $("#password").effect( "shake", {times:3}, 1000 );
  158. } else {
  159.  
  160. var dados_login = $('#log').serialize();
  161. $("#modal-load").modal('show');
  162. $.ajax({
  163. url: 'php-classes/authlogin.php',
  164. type: 'post',
  165. data: dados_login,
  166. success: function (data) {
  167. $("#r").append(data);
  168. $("#modal-load").modal('hide');
  169. }
  170. });
  171. }
  172.  
  173. });
  174.  
  175. });
Add Comment
Please, Sign In to add comment