Skip to content

Commit 4e26b02

Browse files
Add files via upload
1 parent 0e1f4ae commit 4e26b02

File tree

4 files changed

+178
-0
lines changed

4 files changed

+178
-0
lines changed

includes/db.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
/**
4+
* Tester.su database connect and session start.
5+
*/
6+
7+
require 'libs/rb.php';
8+
9+
R::setup('mysql:host=localhost;dbname=tester', 'root');
10+
session_start();

includes/loader.php

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
3+
/**
4+
* Tester.su template loader using twig library.
5+
*
6+
* @url https://twig.symfony.com/
7+
*/
8+
9+
require_once 'libs/vendor/autoload.php';
10+
11+
/**
12+
* Pass arguments to the HTML template.
13+
*
14+
* @param string $template
15+
*
16+
* @param array $args
17+
*
18+
* @return void
19+
*/
20+
function load_template( $temp, $args = array() )
21+
{
22+
/*
23+
* Gives user avatar into template.
24+
*/
25+
$args['avatar'] = @$_SESSION['user']->avatar;
26+
27+
/*
28+
* Gives csrf token into form.
29+
*/
30+
$token = bin2hex( random_bytes( 32 ) );
31+
$_SESSION['csrf_token'] = $token;
32+
$args['csrf_token'] = $token;
33+
34+
$loader = new Twig_Loader_Filesystem( 'templates' );
35+
$twig = new Twig_Environment( $loader );
36+
37+
$template = $twig->loadTemplate( $temp );
38+
echo $template->render( $args );
39+
}

includes/requires.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php
2+
3+
/**
4+
* Tester.su standard require package.
5+
*/
6+
7+
require_once 'includes/db.php';
8+
require_once 'includes/loader.php';
9+
require_once 'includes/smtp.php';

includes/smtp.php

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
<?php
2+
3+
/**
4+
* Uses the PHPmailer library to send emails through SMTP more efficiently.
5+
* v6.13 is using.
6+
*
7+
* @url https://github.com/PHPMailer/PHPMailer/
8+
*/
9+
10+
use PHPMailer\PHPMailer\PHPMailer;
11+
use PHPMailer\PHPMailer\Exception;
12+
13+
require_once 'libs/vendor/phpmailer/phpmailer/src/Exception.php';
14+
require_once 'libs/vendor/phpmailer/phpmailer/src/PHPMailer.php';
15+
require_once 'libs/vendor/phpmailer/phpmailer/src/SMTP.php';
16+
require_once 'includes/requires.php';
17+
18+
19+
abstract class SMTP
20+
{
21+
/**
22+
* The Srevant class.
23+
* Tester.su SMTP server settings.
24+
*
25+
* @url https://ru.wikipedia.org/wiki/%D0%A8%D0%B0%D0%B1%D0%BB%D0%BE%D0%BD_%D0%BF%D1%80%D0%BE%D0%B5%D0%BA%D1%82%D0%B8%D1%80%D0%BE%D0%B2%D0%B0%D0%BD%D0%B8%D1%8F
26+
*/
27+
28+
/**
29+
* @var object
30+
*/
31+
private static $mail;
32+
33+
/**
34+
* Setting to send mails.
35+
*
36+
* @return void
37+
*/
38+
private static function getSMTP()
39+
{
40+
static::$mail = new PHPMailer;
41+
static::$mail->CharSet = 'UTF-8';
42+
43+
static::$mail->isSMTP();
44+
static::$mail->SMTPAuth = true;
45+
static::$mail->SMTPDebug = 0;
46+
47+
static::$mail->Host = 'ssl://smtp.mail.ru';
48+
static::$mail->Port = 465;
49+
static::$mail->Username = '[email protected]';
50+
static::$mail->Password = 'ka8Jq1_$as';
51+
52+
static::$mail->setFrom( '[email protected]', 'tester.su' );
53+
}
54+
55+
/**
56+
* Sends mail with activation code to complete the sign up process.
57+
*
58+
* @return void
59+
*/
60+
public static function sendActivation()
61+
{
62+
self::getSMTP();
63+
64+
$body = '<p><b>Welcome to us!<br>This your activation code: '.$_SESSION['activation'].'</b></p>';
65+
66+
static::$mail->addAddress( $_SESSION['email'], 'Dear Customer' );
67+
static::$mail->Subject = 'Sign up Completion';
68+
static::$mail->msgHTML( $body );
69+
70+
static::$mail->send();
71+
}
72+
73+
/**
74+
* Sends mail with users login and a new password for account recovery procedure.
75+
*
76+
* @param string $login
77+
*
78+
* @param string $password
79+
*
80+
* @return void
81+
*/
82+
public static function sendRecovery( $login, $password )
83+
{
84+
self::getSMTP();
85+
86+
$body = "<p><b>We received information that you lost your account<br>This your login: ".$login.
87+
";<br>And your new password: ".$password.".<br>If you have not left an application for
88+
account recovery just ignore this message.<br>But if you are the owner of the account, the attacker may have left this request.
89+
Then we recommend that you change the email address in your account settings</b></p>";
90+
91+
static::$mail->addAddress( $_SESSION['email'], 'Dear Customer' );
92+
static::$mail->Subject = 'Account recovery';
93+
static::$mail->msgHTML( $body );
94+
95+
static::$mail->send();
96+
}
97+
98+
/**
99+
* Sends mail with users login and a new password for account recovery procedure.
100+
*
101+
* @param string $login
102+
*
103+
* @param string $password
104+
*
105+
* @return void
106+
*/
107+
public static function sendActivationLink( $link )
108+
{
109+
self::getSMTP();
110+
111+
$body = "<p><b>We received information that you want to change your email address.<br>If you have not left an application for
112+
change email address just ignore this message.<br>Follow this link to confirm you are owner of this account:<br>" . $link . "</b></p>";
113+
114+
static::$mail->addAddress( $_SESSION['email'], 'Dear Customer' );
115+
static::$mail->Subject = 'Email change procedure';
116+
static::$mail->msgHTML( $body );
117+
118+
static::$mail->send();
119+
}
120+
}

0 commit comments

Comments
 (0)