83 lines
2.4 KiB
PHP
83 lines
2.4 KiB
PHP
<?php
|
|
|
|
/**
|
|
* RegisterController
|
|
* Register new user
|
|
*/
|
|
class RegisterController extends Controller
|
|
{
|
|
/**
|
|
* Construct this object by extending the basic Controller class. The parent::__construct thing is necessary to
|
|
* put checkAuthentication in here to make an entire controller only usable for logged-in users (for sure not
|
|
* needed in the RegisterController).
|
|
*/
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
}
|
|
|
|
/**
|
|
* Register page
|
|
* Show the register form, but redirect to main-page if user is already logged-in
|
|
*/
|
|
public function index()
|
|
{
|
|
// Redirect non-logged-in users to the login page
|
|
if (!LoginModel::isUserLoggedIn()) {
|
|
Redirect::to('login/index');
|
|
return;
|
|
}
|
|
|
|
$this->View->render('register/index');
|
|
}
|
|
|
|
/**
|
|
* Register page action
|
|
* POST-request after form submit
|
|
*/
|
|
public function register_action()
|
|
{
|
|
// Restrict registration to admins only
|
|
if (!LoginModel::isAdmin()) {
|
|
Session::add('feedback_negative', Text::get('FEEDBACK_ADMIN_ONLY'));
|
|
Redirect::to('login/index');
|
|
return;
|
|
}
|
|
|
|
$registration_successful = RegistrationModel::registerNewUser();
|
|
|
|
if ($registration_successful) {
|
|
Redirect::to('login/index');
|
|
} else {
|
|
Redirect::to('register/index');
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Verify user after activation mail link opened
|
|
* @param int $user_id user's id
|
|
* @param string $user_activation_verification_code user's verification token
|
|
*/
|
|
public function verify($user_id, $user_activation_verification_code)
|
|
{
|
|
if (isset($user_id) && isset($user_activation_verification_code)) {
|
|
RegistrationModel::verifyNewUser($user_id, $user_activation_verification_code);
|
|
$this->View->render('register/verify');
|
|
} else {
|
|
Redirect::to('login/index');
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Generate a captcha, write the characters into $_SESSION['captcha'] and returns a real image which will be used
|
|
* like this: <img src="......./login/showCaptcha" />
|
|
*
|
|
* This method is now deprecated as Captcha is no longer used in the registration process.
|
|
*/
|
|
public function showCaptcha()
|
|
{
|
|
Session::add('feedback_negative', Text::get('FEEDBACK_CAPTCHA_NOT_USED'));
|
|
Redirect::to('register/index');
|
|
}
|
|
}
|