Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- CREATE DEFINER=`root`@`localhost` FUNCTION `valid`(p_senha varchar(50), p_email varchar(150), p_service int(1)) RETURNS varchar(200) CHARSET utf8
- BEGIN
- DECLARE vn_token VARCHAR(200);
- DECLARE vn_cod_cli INT(50);
- DECLARE vn_auth INT(50);
- DECLARE vn_sequencia INT(50);
- if p_email is null or p_service is null or p_senha is null then
- return '1';
- else
- select sequencia
- into vn_cod_cli
- from clientes
- where email = p_email
- and senha = (select md5(p_senha));
- if vn_cod_cli is null then
- return '2';
- else
- select upper(replace(UUID(), '-', ''))
- into vn_token;
- select sequencia, auth
- into vn_sequencia, vn_auth
- from auth
- where cod_cli = vn_cod_cli;
- if vn_sequencia is null then
- insert into auth (hash, auth, geracao, cod_cli, service)
- values (vn_token, 'N', now(), vn_cod_cli, service);
- return vn_token;
- elseif vn_auth = 'N' then
- return vn_token;
- else
- return '3';
- end if;
- end if;
- end if;
- end
- <?php
- use PHPMailerPHPMailerPHPMailer;
- use PHPMailerPHPMailerException;
- require 'PHPMailer/vendor/autoload.php';
- require_once('acessabanco.php');
- $email = $_POST['em'];
- $senha = $_POST['pass'];
- $objDb = new db();
- $link = $objDb->conecta_banco();
- $func = "SELECT valid('$senha', '$email', 1) return";
- $exec = mysqli_query($link, $func);
- if ($exec){
- $arr = mysqli_fetch_array($exec);
- $return = $arr['return'];
- if ($return == '1'){
- echo('<div class="alert alert-danger"><strong>Atenção </strong>Dados imcompletos</div>');
- } else if ($return == '2'){
- echo('<div class="alert alert-danger"><strong>Atenção </strong>O email informado não existe em nosso sistema, cadastre-se!</div>');
- } else if ($return == '3'){
- echo('200');
- } else {
- $token = $return;
- $mail = new PHPMailer(true);
- try {
- $mail->CharSet = 'UTF-8';
- $mail->isSMTP();
- $mail->Host = 'smtp.gmail.com';
- $mail->SMTPAuth = true;
- $mail->Username = 'noreplayanuncieja@gmail.com';
- $mail->Password = '*******';
- $mail->SMTPSecure = 'tls';
- $mail->Port = 587;
- $mail->SMTPOptions = array (
- 'ssl' => array (
- 'verify_peer' => false,
- 'verify_peer_name' => false,
- 'allow_self_signed' => true));
- $mail->setFrom($email, 'Recuperação de Conta');
- $mail->addAddress($email, 'Recuperação de Conta');
- $mail->isHTML(true);
- $mail->Subject = 'Here is the subject';
- $mail->Body = $token;
- $mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
- $mail->send();
- 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>');
- } catch (Exception $e) {
- echo 'Message could not be sent.';
- echo 'Mailer Error: ' . $mail->ErrorInfo;
- }
- }
- } else {
- 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>');
- }
- ?>
- $(document).ready(function () {
- $('#forgot_it').css('display', 'none');
- $("#recovery").click(function(){
- $("#forgot_it").toggle("slow");
- $("#login").toggle("hide");
- });
- $("#env_token").click(function(){
- if ($("#forgot_email").val() == ''){
- $("#forgot_email").effect( "shake", {times:3}, 1000 );
- } else {
- }
- });
- $("#remember").click(function(){
- $("#forgot_it").toggle("hide");
- $("#login").toggle("slow");
- });
- $("#efetuar_login").click(function () {
- if ($("#email").val() == ''){
- $("#email").effect( "shake", {times:3}, 1000 );
- } else if ($("#password").val() == ''){
- $("#password").effect( "shake", {times:3}, 1000 );
- } else {
- var dados_login = $('#log').serialize();
- $("#modal-load").modal('show');
- $.ajax({
- url: 'php-classes/authlogin.php',
- type: 'post',
- data: dados_login,
- success: function (data) {
- $("#r").append(data);
- $("#modal-load").modal('hide');
- }
- });
- }
- });
- });
Add Comment
Please, Sign In to add comment