We can use the following example to redirect a page if user is logged in or not. The following code can be put on the corresponding components or on module.
$redirect_url = JURI::getInstance()->toString(); //this JURI::getInstance()->toString() gives site url. You can replace it with any of your required url like registration page.
$user = & JFactory::getUser();
If ( $user->id ) { //if user is logged in
//do something
} else {
$redirect_url = str_replace('&','&', $redirect_url); // get rid of any ampersands
$redirect_url = JRoute::_($redirect_url);
$redirect_url = str_replace('&','&', $redirect_url); // get rid of any ampersands again
$app = & JFactory::getApplication();
$app->redirect($redirect_url); //redirect
}