This repository has been archived on 2023-12-29. You can view files and clone it, but cannot push or open issues or pull requests.
dogstats/web/pages/register/controller.php

91 lines
2.7 KiB
PHP
Raw Normal View History

2023-10-22 01:46:22 +02:00
<?php
class Register extends Page {
function index()
{
$this->set('template', 'register.html');
}
function validate()
{
$email = trim($_REQUEST['email']);
$password = trim($_REQUEST['password']);
$password2 = trim($_REQUEST['password2']);
$hash = password_hash($password, PASSWORD_DEFAULT);
$u = new User();
$err = false;
if(!$email)
$err = "Email is required";
else if(!filter_var($email, FILTER_VALIDATE_EMAIL))
$err = "Email is invalid";
else if(!$password)
$err = "Password is required";
else if($password != $password2)
$err = "Passwords do not match";
else if(strlen($password) < 8)
$err = "Password must be at least 8 characters long";
else if($u->exists($email))
$err = "Email already exists";
if($err)
{
$this->set('template', '/templates/partials/error.html');
2023-10-22 23:05:24 +02:00
$this->set('errorTitle', 'Error');
$this->set('errorMessage', $err);
2023-10-22 01:46:22 +02:00
return;
}
else
{
$u->id = $email;
$u->email = $email;
$u->password = $hash;
$u->active = 0;
try
{
$u->save();
2023-10-29 09:16:10 +01:00
$this->redirect('/register/success');
2023-10-22 01:46:22 +02:00
}
catch(Exception $e)
{
$this->set('template', '/templates/partials/error.html');
2023-10-22 23:05:24 +02:00
$this->set('errorTitle', 'Error');
$this->set('errorMessage', $e->getMessage());
2023-10-22 01:46:22 +02:00
return;
}
2023-10-29 09:16:10 +01:00
2023-10-22 01:46:22 +02:00
return;
}
2023-10-22 23:05:24 +02:00
//return print_r(['email'=>$email,'password'=>$password,'password2'=>$password2], true);
2023-10-22 01:46:22 +02:00
}
function success()
{
$this->set('template', '/templates/partials/success.html');
2023-10-22 23:05:24 +02:00
$this->set('successTitle', 'Success');
$this->set('successMessage', 'You have successfully registered. Activate your account from the Link in your email');
2023-10-22 01:46:22 +02:00
}
function test()
{
$u = new User();
$u->id = 'chris@chris.ch';
$u->email = 'chris@chris.ch';
$u->password = '123456';
$u->save();
return nl2br(print_r($u, true));
}
function test2()
{
$u = new User();
$response = $u->load('chris@chasdris.ch');
return nl2br(print_r($response, true));
}
}