forked from pedrocastagna/WebDevSec-main
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsendTokenClient.php
More file actions
128 lines (106 loc) · 3.13 KB
/
sendTokenClient.php
File metadata and controls
128 lines (106 loc) · 3.13 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
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
<?php
include_once 'controllers/functions.php';
include_once 'controllers/model.php';
include_once 'config/app.php';
$model = new model();
$functions = new functions();
$emailpost = $_POST["email"];
$rsUser = $functions->search("clients","email",$emailpost);
if(!$emailpost){
$error="ERR01 - Cadastro realizado com sucesso. Porém NÃO foi possível enviar o email de acesso";
$errors=1;
echo $error;
exit;
}
if(!$rsUser) {
$error="ERR02 - Cadastro realizado com sucesso. Porém NÃO foi possível enviar o email de acesso";
$errors=1;
echo $error;
exit;
}
$id = $rsUser["id"];
$email = $rsUser["email"];
$user = $rsUser["user"];
if($rsUser["password"]){
$password = $rsUser["password"];
}else{
$password = $functions->createPassword();
$newPassword = 1;
}
$token = $email.$password;
$token = hash('sha256',$token);
if($newPassword){
$qryUpdate = "UPDATE clients SET password = '".$password."' WHERE id = ".$id;
$rsExec = $model->model_exec($qryUpdate);
}
$urlToken = _HOST_.'acesso/token/'.$token;
$corpo = '
Olá '.$user.',
<br />
<br />
<strong>Você acaba de receber seu acesso ao WDS App.</strong>
<br />
<br />
<br />
<br />
Acesse a url abaixo, informe seu e-mail, uma nova senha e pronto! Já poderá acessar a plataforma.
<br />
<br />
<strong>Acesse agora: <a href="'.$urlToken.'" title="Acesse Agora">Seu Acesso WDS App >></a></strong>
<br />
<br />
<br />
Caso você não consiga clicar no link acima,
<br />
<br />
copie o link completo e cole na barra de endereços do seu navegador.
<br />
<br />
<a href="'.$urlToken.'" title="Seu Acesso WDS App">'.$urlToken.'</a>
<br />
<br />
<br />
<br />
<strong>Este é uma mensagem pessoal e instransferível, não compartilhe seus dados de acesso. </strong>
<br />
<br />
<br />
<br />
<span style="font-size:12px">
<strong>WDS App</strong>
<br />
<br />
</span>
';
$mailConf = $functions->getMailData();
require 'phpmailer/src/Exception.php';
require 'phpmailer/src/PHPMailer.php';
require 'phpmailer/src/SMTP.php';
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\SMTP;
use PHPMailer\PHPMailer\Exception;
$mail = new PHPMailer(true);
$mail->IsSMTP();
$mail->IsHTML(true);
$mail->Host = $mailConf["smtphost"];
$mail->SMTPAuth = true;
$mail->Username = $mailConf["mailuser"];
$mail->Password = $mailConf["mailpass"];
$mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS;
$mail->Port = 587;
$mail->Timeout = 3600;
$mail->CharSet = PHPMailer::CHARSET_UTF8;
$mail->Subject = "Seu Acesso ao WDS App - Crie uma nova senha";
$mail->Body = $corpo;
$mail->setFrom($mailConf["mailuser"], $mailConf["mailfrom"]);
$mail->addReplyTo($mailConf["mailuser"], $mailConf["mailfrom"]);
$mail->addAddress($email);
try {
$mail->send();
$qryUpdate = "UPDATE users SET email_token = 1 WHERE id = ".$id;
$rsExec = $model->model_exec($qryUpdate);
$return = $token;
} catch (Exception $e) {
$return = "error;Cadastro realizado com sucesso. Porém NÃO foi possível enviar o email de acesso";
}
echo $return;