Esempio n. 1
0
<?php

use Workout\Models\User;
$app->get('/dashboard', $authenticate($app), function () use($app) {
    $user = User::find($_SESSION['id']);
    $app->render('dashboard/home.twig', ['title' => 'Dashboard', 'username' => $user->username, 'logged' => true, 'loggedin' => empty($user) ? false : true]);
})->name('dashboard.home');
Esempio n. 2
0
<?php

use Workout\Models\User;
use Workout\Models\Mail;
$app->map('/register', function () use($app) {
    if ($app->request->isPost()) {
        $errors = [];
        $email = $app->request()->post('email');
        $email_code = md5($email + microtime());
        $password = $app->request()->post('password');
        $password_again = $app->request()->post('password_again');
        $username = '******' . rand(10000, 1000000);
        $user = User::where('email', $email)->first();
        if (!$user) {
            if ($password == $password_again) {
                $user = new User();
                $user->username = $username;
                $user->email = $email;
                $user->email_code = $email_code;
                $user->password = password_hash($password, PASSWORD_DEFAULT);
                $user->save();
                $mail = Mail::sendEmail($email, $email_code);
            } else {
                $errors[] = "Passwords do not match!!";
            }
        } else {
            $errors[] = "This email already exists!";
        }
        if (!empty($errors)) {
            $app->render('users/register.twig', ['errors' => $errors]);
        } else {
Esempio n. 3
0
<?php

use Workout\Models\User;
$app->map('/login', function () use($app) {
    if ($app->request()->isPost()) {
        $errors = [];
        $email = $app->request()->post('email');
        $password = $app->request()->post('password');
        $user = User::where('email', $email)->where('active', 1)->first();
        if ($user && password_verify($password, $user->password)) {
            $_SESSION['username'] = $user->username;
            $_SESSION['id'] = $user->id;
        } else {
            $errors[] = "The email and password don't match!";
        }
        if (!empty($errors)) {
            $app->render('users/login.twig', ['errors' => $errors, 'email' => $email]);
        } else {
            $app->redirect('/dashboard');
        }
    } else {
        if (isset($_SESSION['id'])) {
            $app->redirect('/dashboard');
        } else {
            $app->render('/users/login.twig');
        }
    }
})->via('GET', 'POST')->name('users.login');
Esempio n. 4
0
<?php

use Workout\Models\User;
$app->get('/activate/:email/:email_code', function ($email, $email_code) use($app) {
    $user = User::where('email', trim($email))->where('email_code', trim($email_code))->first();
    if ($user) {
        User::where('email', $email)->update(['active' => 1]);
        $app->redirect('/activate/success');
    } else {
        $app->redirect('/activate/error');
    }
})->name('users.activate');
$app->get('/activate/success', function () use($app) {
    $app->render('success/activation.twig');
})->name('users.activate.success');
$app->get('/activate/error', function () use($app) {
    $app->render('error/activation.twig');
})->name('users.activate.error');