Phpbb3 forum integration with existing site - session

I am trying to integrate the phpbb forum with my existing site. I have already looked at these links, and it doesn't seem to work. I have copied this code
define('IN_PHPBB', true);
define('ROOT_PATH', "/path/to/forums");
if (!defined('IN_PHPBB') || !defined('ROOT_PATH')) {
exit();
}
$phpEx = "php";
$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : ROOT_PATH . '/';
include($phpbb_root_path . 'common.' . $phpEx);
$user->session_begin();
$auth->acl($user->data);
into a loginforum.php file, which I include in every page I want the sessions to be kept. I have done the three steps indicated in the sessions integration section, but when I try to check whether the user is authenticated, it doesn't seem so. Using the same code here:
<?php
if ($user->data['user_id'] == ANONYMOUS){
echo 'Please login!';
}
else{
echo 'Thanks for logging in, ' . $user->data['username_clean'];
}
?>
I only get the "Please login" phrase, even when I login.
I've been over this for hours, I don't understand where the problem is. Shouldn't it work after the three miraculous steps?

Try this:
if ($user->data['username'] == 'Anonymous')
{
echo 'Please login!';
}
This is the first (and guest) user in the PHPBB database:
SELECT `user_id`,
`username`,
`username_clean`
FROM
`phpbb_users` WHERE user_id = 1
Result:
"user_id" "username" "username_clean"
"1" "Anonymous" "anonymous"

Related

How can we redirect to previous page after login in cibonfire?

How can we redirect to previous page after login in cibonfire?
If some module require login to view, than the code there will check for login and if it is not logged in, it will redirect to login page. After login we want to get back to same module. How can we do so.
Thanks
Before your checking ,A user is already loged in ,Add
$this->session->set_userdata('page_url', current_url());
Add in your login function ,After checking the login data.
if($this->session->userdata('page_url'))
redirect($this->session->userdata('page_url'));
else
redirect('default home page');
At the end of your controller function add this line
redirect('your_view_here', $any_variables_here);
I use sessions for logging in and for navegation tasks like that, because it just makes life a lot simpler. In my controller functions I drop in a line of code like the following:
$this->load_segs(func_get_args(), strtolower(__CLASS__).'/'.__FUNCTION__);
Here's the load segements function:
function load_segs($params, $src){
if ( ! is_array($params) || ! isset($src)){
return FALSE;
}
foreach ($params as $key => $value){
//only include values that don't need encoding
if ($value != urlencode($value)){
break;
}
$src .= '/'.htmlentities($value, ENT_QUOTES, 'UTF-8');
}
$this->session->set_userdata('return', $src);
return $src;
}
You can retrieve the information as follows:
$return = html_entity_decode($this->session->userdata('return'));
redirect($return);

In yii how to insert record in table by overriding existing entry [duplicate]

In yii i am creating project. After validation of user's entered email, i am displaying password.php file which is having textfield for entering new password.
Password.php=
<?php $form=$this->beginWidget('CActiveForm', array(
'id'=>'email-form',
'enableClientValidation'=>true,
));
echo CHtml::textField('Enter new password');
echo CHtml::textField('Repeat password');
echo CHtml::submitButton('Submit');
$this->endWidget();
When user will enter new password and click on submit button i want to insert this new password into User table's password field, in such a way that it overright old password.
In controller i had created method as-
public function actionCreate(){
if(isset($_POST['email']))
{
$record=User2::model()->find(array(
'select'=>'userId, securityQuestionId, primaryEmail',
'condition'=>'primaryEmail=:email',
'params'=>array(':email'=>$_POST['email']))
);
if($record===null) {
echo "Email invalid";
}
else {
echo "email exists";
$this->render('Password');
if(isset($_POST['Password']))
{
$command = Yii::app()->db->createCommand();
$command->insert('User', array(
'password'=>$_POST['password'] ,
//'params'=>array(':password'=>$_POST['password'])
}
}
}
else{
$this->render('emailForm'); //show the view with the password field
}
But its not inserting new password. So How can i implement this...Please help me
First of all the way you are handling the form is certainly not Yii-ish which means it's not really the way to go.
The way you should handle this is by creating an object which extends from the CFormModel and put all your logic code in there instead of in the controller.
Now, if you want to continue working with your piece of code, then it would be best to place the following piece of code
$this->render('Password');
BELOW the if isset password stuff.
For your problem, the reason why your password isn't being updated is because the query you created is not being executed. If we take a look here then we can see that the following piece of code should be added:
$command->execute();
Which will execute your piece of sql.
Something like this...
$user = User::find('email = :email', ':email' => $_POST['email']);
if( empty($user) )
return;
$user->password = $_POST['password'];
$user->save();
You can't get password like this $_POST['Password'], because you haven't set this post variable.
You had to use:
echo CHtml::textField('password');
echo CHtml::textField('repeatPassword');
echo CHtml::hiddenField('email', $email);
'password' and 'repeatPassword' are names of POST vars
And in your controller you have too many mistakes, try this (check for typos):
if(isset($_POST['email']))
{
$record=User2::model()->find(array(
'select'=>'userId, securityQuestionId, primaryEmail',
'condition'=>'primaryEmail=:email',
'params'=>array(':email'=>$_POST['email']))
);
if($record===null) {
echo "Email invalid";
}
else {
if(isset($_POST['password']) && isset($_POST['repeatPassword']) && ($_POST['password'] === $_POST['repeatPassword']))
{
$record->password = $_POST['password'];
if ($record->save()) {
$this->render('saved');
}
}
$this->render('Password' array('email'=>$_POST['email']));
}
}
}
else{
$this->render('emailForm'); //show the view with the password field
}
In your code if(isset($_POST['Password'])) won't ever execute, because after sending password you haven't set email variable. So you just $this->render('emailForm');. Thus we set it by CHtml::hiddenField('email', $email);
Upd. I strongly recommend you to read this guide. It will save a lot of time for you.

Joomla 2.5 module permissions

I simply want to make a module visible dependent on whether a user belongs to a custom set of groups - including NOT visible if (s)he belongs to a particular group(s). For example, adverts show for public and registered but not a custom "premium" group. A shoutbox should appear for registered and premium but not "not logged in". Thus, the "guest" and "special" groups are pretty useless as far as I can tell. Am I missing something really simple?
If I have to use a 3rd party component/module to achieve this then a free or cheap one would be most beneficial.
Thanks.
One way to achieve this is to edit and create new access levels. To cover up the examples you gave in the question, the following could work:
You need to get the guests out of the root parent group called Public. You can do this by the following three steps:
Using the User Manager, create a new group called "Guest" with Public as parent.
Open up the User Manager Options.
Change Guest User Group to your new group Guest.
The guests on your site will from now on be put into the Guest group. Now you could create a access level for the advert. So create a new access level, name it something like "Non premium users" and add Guest and Registered. Now apply this access level to the module and it should work. Note that the premium group cannot have Registered as a parent.
Next is the access level for the shoutbox. I see two options for this access level. One of them is to create a new access level and add Registered and Premium to it. A simpler approach though is to add the Premium group to the already existing access level called Registered.
Helpful ACL Links:
Allowing Guest-Only Access to Menu Items and Modules
Joomla ACL: Access Levels
None of the ACL levels work 100% of the time for me, I had to hack the template I was using and add in some code...
<?php
// make sure user is an accepted user group
jimport( 'joomla.user.helper' );
$user =& JFactory::getUser();
$userId = $user->get( 'id' );
$groups = JUserHelper::getUserGroups($userId);
// print_r($groups);
/*
3 Author
4 Editor
5 Publisher
6 Manager
7 Administrator
8 Super Users
*/
$menu = '' ;
if (in_array("3", $groups)) {
// echo "<!-- Author Group Found! -->";
// echo '<!-- USER ID: ' . $userId . ' -->';
$menu .= "
<a href='http://yourdomain.com/authors-area'>Authors Area</a>
" ;
} elseif(in_array("4", $groups)) {
$menu .= "
<a href='http://yourdomain.com/editors-area'>Editors Area</a>
" ;
} elseif(in_array("5", $groups)) {
$menu .= "
<a href='http://yourdomain.com/publishers-area'>Publishers Area</a>
" ;
} elseif(in_array("6", $groups)) {
$menu .= "
<a href='http://yourdomain.com/managers-area'>Managers Area</a>
" ;
} elseif(in_array("7", $groups)) {
$menu .= "
<a href='http://yourdomain.com/administrators-area'>Administrators Area</a>
" ;
} elseif(in_array("8", $groups)) {
$menu .= "
<a href='http://yourdomain.com/superusers-area'>Super Users Area</a>
" ;
} else {
$null = '' ; ;
}
?>

cakephp flash error not working

i've created a login in system where an activated user can log in but a user who's account hasnt been activated wont be able to log in. The problem is that no flash message is outputted when the user tries to log in with a deactivated account, so a user wouldn't know why the page keeps refreshing on the login page.
heres my login function
if ($this->request->is('post')){
if ($this->request->data['User']['password'] == 'qazwsx'){
if ($this->Auth->login()){
$username = $this->request->data['User']['username'];
if (0 === $this->User->find('count',array('conditions'=>array('activated'=>1,'username'=> $username)))) {
$this->Session->setFlash('Sorry, your account is not validated yet.');
$this->redirect($this->referer());
}
$this->Auth->user('id');
$this->redirect($this->Auth->redirect('eboxs/home'));
}
}
else {
$this->Session->setFlash('Username or password is incorrect');
}
}else{
$this->Session->setFlash('Welcome, please login');
}
}
I havent included my view cause so far with flash messages i havent had to call them
Weird Authentification way you're doing there.
Like you've been already told in the comments, check, wherever the user is redirected ($this->redirect), there is a
<?php echo $this->Session->flash(); ?>
in that view.
Also with that method, the user is logged in anyway. You've to manually log out that user again, before you show him the flash message / redirect him.
You can also just write:
<?php
...
$this->Auth->scope = array('User.activated' => 1);
if ($this->Auth->login()) {
// logged-in logic
} else {
// not logged-in logic
}
?>
This would save you some lines of code.

Check if Admin is Logged in Within Observer

I'm attempting to check if the administrator is logged in from an observer. The problem is that while this is easy to do when viewing the admin module, viewing the frontend is another story.
There are several similar questions, but unfortunately none of them provide a working solution for Magento 1.6.2.
I wasn't able to successfully get isLoggedIn() to return true in the admin/session class. I also found out that there is a cookie for both frontend and adminhtml, which may help.
The accepted answer in this related question seems to suggest this may not be possible:
Magento - Checking if an Admin and a Customer are logged in
Another related question, with a solution that didn't help my specific case:
Magento : How to check if admin is logged in within a module controller?
It is possible. What you need to do is switch the session data. You can do this with the following code:
$switchSessionName = 'adminhtml';
if (!empty($_COOKIE[$switchSessionName])) {
$currentSessionId = Mage::getSingleton('core/session')->getSessionId();
$currentSessionName = Mage::getSingleton('core/session')->getSessionName();
if ($currentSessionId && $currentSessionName && isset($_COOKIE[$currentSessionName])) {
$switchSessionId = $_COOKIE[$switchSessionName];
$this->_switchSession($switchSessionName, $switchSessionId);
$whateverData = Mage::getModel('mymodule/session')->getWhateverData();
$this->_switchSession($currentSessionName, $currentSessionId);
}
}
protected function _switchSession($namespace, $id = null) {
session_write_close();
$GLOBALS['_SESSION'] = null;
$session = Mage::getSingleton('core/session');
if ($id) {
$session->setSessionId($id);
}
$session->start($namespace);
}
Late Answer but if as I found it on google:
This it not possible.
Why? Because the default session name in the frontend is frontend and the session name in the backend is admin. Because of this, the session data of the admin is not available in the frontend.
have you tried this :
Mage::getSingleton('admin/session', array('name' => 'adminhtml'))->isLoggedIn();
how about this ( I am not sure it will work or not )
require_once 'app/Mage.php';
umask(0);
$apps = Mage::app('default');
Mage::getSingleton('core/session', array('name'=>'adminhtml'));
$adminSession = Mage::getSingleton('admin/session');
$adminSession->start();
if ($adminSession->isLoggedIn()) {
// check admin
}

Resources