Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- function getToken($length) {
- $token = "";
- $symbols = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
- $max = strlen($symbols);
- for ($i = 0; $i < $length; $i++) {
- $token .= $symbols[random_int(0, $max - 1)];
- }
- return $token;
- }
- session_start();
- include __DIR__.'/pdo-wrapper.php';
- include __DIR__.'/../vendor/autoload.php';
- use Mailgun\Mailgun;
- $db = new Database();
- $error = array();
- if (empty($_POST['username'])) {
- $error[] = "Your Username field is empty.";
- } else {
- $count = $db->getCount('todo_users', 'username = :username', array(':username' => $_POST['username']));
- if ($count[0][0] >= 1) {
- $error[] = "This user already exists.";
- } else {
- $username = strip_tags($_POST['username']);
- }
- }
- if (empty($_POST['email'])) {
- $error[] = "Your E-Mail field is empty.";
- } else {
- if (!filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)) {
- $error[] = "Your E-Mail is not valid.";
- } else {
- $count = $db->getCount('todo_users', 'email = :email', array(':email' => $_POST['email']));
- if ($count[0][0] >= 1) {
- $error[] = "This E-Mail is already linked with another account.";
- } else {
- $email = strip_tags($_POST['email']);
- }
- }
- }
- if (empty($_POST['password']) && empty($_POST['repassword'])) {
- $error[] = "Your Password fields is empty.";
- } else {
- if ($_POST['password'] != $_POST['repassword']) {
- $error[] = "Your Password and Repeat Password field does not match.";
- } else {
- if ($_POST['password'] == $_POST['username']) {
- $error[] = "You can't use Username as your Password.";
- } else {
- $password = hash('sha256', strip_tags($_POST['password']));
- }
- }
- }
- if (empty($_POST['securityq'])) {
- $error[] = "Your Security Question field is empty.";
- } else {
- $question = hash('sha256', strip_tags($_POST['securityq']));
- }
- if (empty($_POST['token'])) {
- $error[] = "Your Invitation Key field is empty.";
- } else {
- $key = strip_tags($_POST['token']);
- }
- if (!empty($error)) {
- $_SESSION['errors'] = $error;
- header("Location: ../auth/register");
- } else {
- date_default_timezone_set("Europe/Helsinki");
- $joined = time();
- $activateToken = getToken(25);
- $stmt = $db->db->prepare("INSERT INTO todo_users (email, username, password, question, active, role, joined, sortby) VALUES (:email, :username, :password, :question, :token, 'Regular', :joined, '0')");
- $stmt->bindValue(':email', $email);
- $stmt->bindValue(':username', $username);
- $stmt->bindValue(':password', $password);
- $stmt->bindValue(':question', $question);
- $stmt->bindValue(':token', $activateToken);
- $stmt->bindValue(':joined', $joined);
- $stmt->execute();
- var_dump($email);
- $apiKey = 'api-key';
- $domain = 'mg.my-domain.com';
- $mg = Mailgun::create($apiKey);
- $res = $mg->messages()->send($domain, array(
- 'from' => 'todo@my-domain.com',
- 'to' => ''.$email,
- 'subject' => 'subject',
- 'html' => 'Click <a href="https://my-domain.com?token='. $activateToken .'">here</a> to activate your account.'
- ));
- $_SESSION['success'] = "You have been successfully registered. Now you have to go to your E-Mail and activate account.";
- header("Location: ../auth/register");
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement