diff --git a/app/Controller/Admin/PasswordRecoveryController.php b/app/Controller/Admin/PasswordRecoveryController.php index cdc8576..6262f95 100644 --- a/app/Controller/Admin/PasswordRecoveryController.php +++ b/app/Controller/Admin/PasswordRecoveryController.php @@ -8,11 +8,12 @@ use Core\Controller; use Core\Load; use Core\Validate; +use Core\PasswordRecovery; class PasswordRecoveryController extends Controller { - CONST SECRET = ""; + CONST SECRET = "DEUSNOCONTROLE!!"; public function forgot(){ @@ -41,8 +42,10 @@ public function enviarLinkRecuperarSenha(){ echo("Não achou o e-mail: {$data["email"]}"); return false; }else{ - $code = base64_encode(openssl_encrypt($dataRecovery["idrecovery"],"AES-128-ECB",User::SECRET)); - dd($user); + + $recovery = new PasswordRecovery(); + dd($recovery->sendMessageLink($user)); + } } diff --git a/app/Functions/helpers.php b/app/Functions/helpers.php index b81bc05..7ee6a2e 100755 --- a/app/Functions/helpers.php +++ b/app/Functions/helpers.php @@ -1,5 +1,6 @@ connection = new PDO("mysql:host={$this->host};dbname={$this->dbname};charset=utf8", "{$this->userdb}", "$this->passworddb",$options); - }catch(\PDOException $e){ $this->erros = $e->getMessage(); } diff --git a/src/Email.php b/src/Email.php new file mode 100644 index 0000000..3eeb8e3 --- /dev/null +++ b/src/Email.php @@ -0,0 +1,37 @@ +SMTPDebug = SMTP::DEBUG_OFF; + $this->isSMTP(); + $this->Host = 'smtp.gmail.com'; // Set the SMTP server to send through + $this->SMTPAuth = true; // Enable SMTP authentication + $this->Username = 'dcdouglas64@gmail.com'; // SMTP username + $this->Password = 'nokia5233'; // SMTP password + $this->SMTPSecure = "tls"; // Enable TLS encryption; `PHPMailer::ENCRYPTION_SMTPS` also accepted + $this->Port = 587; + $this->isHTML(true); + $this->CharSet = 'UTF-8'; + $this->setLanguage("pt_br"); + $this->setFrom("dcdouglas64@gmail.com"); + $this->addAddress("conveswebtecnologia@gmail.com"); + $this->addAddress("douglasflamengo_07@hotmail.com"); + $this->addAddress("dcdouglas64@gmail.com"); + $this->Subject = "Recuperação de senha"; + $this->Body = $html; + + parent::__construct($exceptions); + } + +} \ No newline at end of file diff --git a/src/PasswordRecovery.php b/src/PasswordRecovery.php new file mode 100644 index 0000000..5f9b279 --- /dev/null +++ b/src/PasswordRecovery.php @@ -0,0 +1,56 @@ +code = base64_encode(openssl_encrypt($hash,"AES-128-ECB",$this->key)); + + } + + private function linkCreate():void{ + $root = (!empty($_SERVER['HTTPS']) ? 'https' : 'http') . '://' . $_SERVER['HTTP_HOST'] . '/'; + $this->link = $root . "recovery-password/code={$this->code}"; + } + + private function messageCreate(){ + + } + + private function recordAttempt(){ + $data = [ + "email" => $this->user->email, + "hash" => $this->code, + "status" => 0, + "user_id" => $this->user->id + ]; + + $this->create($data); + } + + public function sendMessageLink(object $user){ + $this->user = $user; + $this->codeCreate(); + $this->linkCreate(); + $this->recordAttempt(); + $email = new Email($this->link); + $email = $email->send(); + + return $email; + } + +} \ No newline at end of file diff --git a/src/db/migrations/20200221151819_create_table_password_recovery.php b/src/db/migrations/20200221151819_create_table_password_recovery.php new file mode 100644 index 0000000..6b12884 --- /dev/null +++ b/src/db/migrations/20200221151819_create_table_password_recovery.php @@ -0,0 +1,43 @@ +table("password_recovery"); + $table->addColumn("email","string",["limit" => 255]); + $table->addColumn("hash","string",["limit" => 88]); + $table->addColumn('status', 'integer', ['null' => true]); + $table->addColumn('user_id', 'integer', ['null' => true]); + $table->addForeignKey('user_id', 'users', 'id',['delete'=> 'SET_NULL']); + $table->addColumn("created",'timestamp', ['default' => 'CURRENT_TIMESTAMP']); + $table->create(); + } +}