https://joomla.stackexchange.com/questions/9546/custom-component-need-to-verify-if-user-is-logged-in
$user = JFactory::getUser(); // Get the user object
$app = JFactory::getApplication(); // Get the application
if ($user->id != 0)
{
// you are logged in
}
else
{
// Redirect the user
$app->redirect(JRoute::_('index.php?option=com_users&view=login'));
}