-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
douglas
committed
Feb 21, 2020
1 parent
fa159a8
commit 1495f00
Showing
7 changed files
with
154 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?php | ||
|
||
|
||
namespace Core; | ||
use PHPMailer\PHPMailer\PHPMailer; | ||
use PHPMailer\PHPMailer\Exception; | ||
use PHPMailer\PHPMailer\SMTP; | ||
|
||
|
||
class Email extends PHPMailer | ||
{ | ||
|
||
public function __construct($html,$exceptions = null) | ||
{ | ||
|
||
$this->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 = '[email protected]'; // 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("[email protected]"); | ||
$this->addAddress("[email protected]"); | ||
$this->addAddress("[email protected]"); | ||
$this->addAddress("[email protected]"); | ||
$this->Subject = "Recuperação de senha"; | ||
$this->Body = $html; | ||
|
||
parent::__construct($exceptions); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<?php | ||
|
||
|
||
namespace Core; | ||
|
||
use Core\Email; | ||
|
||
class PasswordRecovery extends Model | ||
{ | ||
protected $user; | ||
protected $link; | ||
protected $code; | ||
protected $key = "DEUSNOCONTROLE!!"; | ||
protected $message; | ||
protected $table = "password_recovery"; | ||
|
||
|
||
private function codeCreate():void{ | ||
|
||
$hash = md5(rand()); | ||
$this->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; | ||
} | ||
|
||
} |
43 changes: 43 additions & 0 deletions
43
src/db/migrations/20200221151819_create_table_password_recovery.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?php | ||
|
||
use Phinx\Migration\AbstractMigration; | ||
|
||
class CreateTablePasswordRecovery extends AbstractMigration | ||
{ | ||
/** | ||
* Change Method. | ||
* | ||
* Write your reversible migrations using this method. | ||
* | ||
* More information on writing migrations is available here: | ||
* http://docs.phinx.org/en/latest/migrations.html#the-abstractmigration-class | ||
* | ||
* The following commands can be used in this method and Phinx will | ||
* automatically reverse them when rolling back: | ||
* | ||
* createTable | ||
* renameTable | ||
* addColumn | ||
* addCustomColumn | ||
* renameColumn | ||
* addIndex | ||
* addForeignKey | ||
* | ||
* Any other destructive changes will result in an error when trying to | ||
* rollback the migration. | ||
* | ||
* Remember to call "create()" or "update()" and NOT "save()" when working | ||
* with the Table class. | ||
*/ | ||
public function change() | ||
{ | ||
$table = $this->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(); | ||
} | ||
} |