Skip to content

Commit 5421b66

Browse files
committed
Se ha implementado libreria de envio de email con exito.
1 parent e237f77 commit 5421b66

File tree

7 files changed

+53
-30
lines changed

7 files changed

+53
-30
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
/vendor/
2+
/public/
23
.env

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ composer create-project lion-framework/lion-backend
77

88
## Update packages
99
```
10-
composer update
10+
composer install
1111
```
1212

1313
### Libraries used

app/Http/Controllers/Controller.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,46 @@
33
namespace App\Http\Controllers;
44

55
use Valitron\Validator;
6+
use LionMailer\Mailer;
7+
use PHPMailer\PHPMailer\PHPMailer;
8+
use PHPMailer\PHPMailer\SMTP;
69

710
class Controller {
11+
12+
protected static object $form;
813

914
public function __construct() {
1015

1116
}
1217

18+
public static function content(bool $option = false): void {
19+
if (!$option) {
20+
self::$form = (object) ($_POST + $_FILES + $_ENV + $_GET + $_SESSION);
21+
} else {
22+
self::$form = (object) json_decode(file_get_contents("php://input"), true);
23+
}
24+
}
25+
1326
public static function make(Validator $validator, array $rules) {
1427
$validator->rules($rules);
1528
return $validator->validate();
1629
}
1730

31+
public static function init(): void {
32+
Mailer::init([
33+
'class' => [
34+
'PHPMailer' => PHPMailer::class,
35+
'SMTP' => SMTP::class
36+
],
37+
'info' => [
38+
'debug' => $_ENV['MAIL_DEBUG'],
39+
'host' => $_ENV['MAIL_HOST'],
40+
'port' => $_ENV['MAIL_PORT'],
41+
'email' => $_ENV['MAIL_EMAIL'],
42+
'user_name' => $_ENV['MAIL_USER_NAME'],
43+
'password' => $_ENV['MAIL_PASSWORD']
44+
]
45+
]);
46+
}
47+
1848
}

app/Http/Controllers/Example/ExampleController.php

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,42 +4,35 @@
44

55
use App\Http\Controllers\Controller;
66
use LionRoute\Request;
7+
use LionMailer\Mailer;
8+
use LionMailer\Attach;
79
use Valitron\Validator;
810
use App\Models\Class\Example;
911

1012
class ExampleController extends Controller {
1113

1214
public function __construct() {
13-
15+
$this->init();
1416
}
1517

1618
public function methodExample(): Request {
17-
$validator = $this->make(new Validator($_POST), [
19+
$this->content(true);
20+
21+
$validator = $this->make(new Validator((array) self::$form), [
1822
'email' => [
1923
['user_data_email']
2024
],
21-
'lengthMin' => [
22-
['user_data_password', 8]
23-
],
2425
'required' => [
2526
['user_data_email'],
2627
['user_data_password']
2728
]
2829
]);
2930

3031
if($validator) {
31-
return new Request('success', 'Welcome to example.', $_POST);
32+
return new Request('success', 'Welcome to example.', self::$form);
3233
} else {
3334
return new Request('error', 'All fields are required and must meet the requested characteristics.');
3435
}
3536
}
3637

37-
public function methodToken(): array {
38-
return [
39-
'status' => "warning",
40-
'message' => "Welcome to token",
41-
'data' => $_POST
42-
];
43-
}
44-
4538
}

composer.lock

Lines changed: 12 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

index.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
header("Access-Control-Allow-Origin: *");
44
header("Access-Control-Max-Age: 3600");
55
header("Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept, Authorization");
6-
header("Access-Control-Allow-Methods: GET, POST, PUT, DELETE");
7-
header("Allow: GET, POST, PUT, DELETE");
6+
header("Access-Control-Allow-Methods: GET, POST, PUT, DELETE, OPTIONS");
7+
header("Allow: GET, POST, PUT, DELETE, OPTIONS");
88
header("Content-Type: application/json; charset=UTF-8");
99
session_start();
1010

routes/web.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
Route::middleware(['before' => 'no-auth'], function() {
2626
Route::prefix('autenticar', function() {
2727
Route::post('ingreso', [ExampleController::class, 'methodExample']);
28-
Route::post('token', [ExampleController::class, 'methodToken']);
2928
});
3029
});
3130

0 commit comments

Comments
 (0)