Hi
We are using OJS 2.4.6 and in this version logged-in users can enter the registration page and register with a new username. I added this code to RegistrationForm.inc.php
in order to redirect the user:
if(Validation::isLoggedIn()){ header("Location: " . $baseUrl); /* Redirect browser */ exit(); }
but $baseUrl
variable is not accessible in this page and I should replace it with the absolute Url of the website, which is not a good idea.
Is there a better way to prohibit the users from registration page?
How can I access the baseurl?
Best,
Al
You probably want this check as part of the registration handler, instead of the registration form. See:
function RegistrationHandler() {
parent::UserHandler();
}
/**
* Display registration form for new users.
* @param $args array
* @param $request PKPRequest
*/
function register($args, &$request) {
$this->validate($request);
$this->setupTemplate($request, true);
$journal =& $request->getJournal();
if ($journal != null) {
import('classes.user.form.RegistrationForm');
if (checkPhpVersion('5.0.0')) { // WARNING: This form needs $this in constructor
$regForm = new RegistrationForm();
} else {
You can generate a redirect via the Request object. An example is nearby in that file:
} else {
$regForm =& new RegistrationForm();
}
$regForm->readInputData();
if ($regForm->validate()) {
$regForm->execute();
if (Config::getVar('email', 'require_validation')) {
// Send them home; they need to deal with the
// registration email.
$request->redirect(null, 'index');
}
$reason = null;
if (Config::getVar('security', 'implicit_auth')) {
Validation::login('', '', $reason);
} else {
Validation::login($regForm->getData('username'), $regForm->getData('password'), $reason);
}
The redirect function is very flexible and well documented as to the parameters:
/**
* Redirect to the specified page within a PKP Application.
* Shorthand for a common call to $request->redirect($dispatcher->url($request, ROUTE_PAGE, ...)).
* @param $context Array The optional contextual paths
* @param $page string The name of the op to redirect to.
* @param $op string optional The name of the op to redirect to.
* @param $path mixed string or array containing path info for redirect.
* @param $params array Map of name => value pairs for additional parameters
* @param $anchor string Name of desired anchor on the target page
*/
function redirect($context = null, $page = null, $op = null, $path = null, $params = null, $anchor = null) {
$_this =& PKPRequest::_checkThis();
$dispatcher =& $_this->getDispatcher();
$_this->redirectUrl($dispatcher->url($_this, ROUTE_PAGE, $context, $page, $op, $path, $params, $anchor));
}
Please do open an Issue and Pull Request on Github for this, if you are able.
thank you @ctgraham ,
problem solved.
I created the Issue