<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title><![CDATA[PunBB Forums — Login Integration]]></title>
		<link>https://punbb.informer.com/forums/topic/22837/login-integration/</link>
		<atom:link href="https://punbb.informer.com/forums/feed/rss/topic/22837/" rel="self" type="application/rss+xml" />
		<description><![CDATA[The most recent posts in Login Integration.]]></description>
		<lastBuildDate>Wed, 21 Jul 2010 09:58:20 +0000</lastBuildDate>
		<generator>PunBB</generator>
		<item>
			<title><![CDATA[Re: Login Integration]]></title>
			<link>https://punbb.informer.com/forums/post/136330/#p136330</link>
			<description><![CDATA[<p>(English translation)</p><p>Hello</p><p>I found some code to display a logon form on all the pages on a site. I&#039;m not the author of this code; I simply found it on a mod; Can&#039;t recall which, but it works. Its author will know who he is.</p><p>Before the doctype of the document, add the following lines:<br /></p><div class="codebox"><pre><code>&lt;?php
 
// Add these lines in the very top of your code
define(&#039;FORUM_ROOT&#039;, &#039;./forum/&#039;);
require FORUM_ROOT.&#039;include/common.php&#039;; 
?&gt;</code></pre></div><p>Next, where you want the logon form to be displayed, add the following code. Logged-on members can also see the avatar:<br /></p><div class="codebox"><pre><code>&lt;?php
// If user is logged display some informations about it
if (!$forum_user[&#039;is_guest&#039;])
{
    require FORUM_ROOT.&#039;lang/&#039;.$forum_user[&#039;language&#039;].&#039;/index.php&#039;;
    if ($forum_config[&#039;o_users_online&#039;] == &#039;1&#039;)
    {
        // Fetch users online info and generate strings for output
        $query = array(
            &#039;SELECT&#039;    =&gt; &#039;o.user_id, o.ident&#039;,
            &#039;FROM&#039;        =&gt; &#039;online AS o&#039;,
            &#039;WHERE&#039;        =&gt; &#039;o.idle=0&#039;,
            &#039;ORDER BY&#039;    =&gt; &#039;o.ident&#039;
        );
        $result = $forum_db-&gt;query_build($query) or error(__FILE__, __LINE__);
        $num_guests = 0;
        $users = array();

        while ($forum_user_online = $forum_db-&gt;fetch_assoc($result))
        {

            if ($forum_user_online[&#039;user_id&#039;] &gt; 1)
                $users[] = &#039;&lt;a href=&quot;&#039;.forum_link($forum_url[&#039;user&#039;], $forum_user_online[&#039;user_id&#039;]).&#039;&quot;&gt;&#039;.forum_htmlencode($forum_user_online[&#039;ident&#039;]).&#039;&lt;/a&gt;&#039;;
            else
                ++$num_guests;
            
        }

        // If there are registered users logged in, list them
        if (count($users) &gt; 0)
            //$users_online = &#039;&lt;p&gt;&lt;strong&gt;&#039;.$forum_user[&#039;Online&#039;].&#039;&lt;/strong&gt; &#039;.implode(&#039;, &#039;, $users).&#039;&lt;/p&gt;&#039;;&lt;!--Décommenter cette ligne pour afficher les utilisateurs en ligne--&gt;

        $stats_online[] = &#039;Membres en ligne: &lt;strong&gt;&#039;.count($users).&#039;&lt;/strong&gt;&lt;br /&gt;&#039;;
        $stats_online[] = &#039;Visiteurs en ligne: &lt;strong&gt;&#039;.$num_guests.&#039;&lt;/strong&gt;&#039;;
    }
    
    $avatar = generate_avatar_markup($forum_user[&#039;id&#039;]);
?&gt;
&lt;?php echo Bienvenue ?&gt;: &lt;strong&gt;&lt;?php echo forum_htmlencode($forum_user[&#039;username&#039;]) ?&gt;  &lt;/strong&gt; &lt;br /&gt;
&lt;?php echo $links[&#039;logout&#039;] = &#039;&lt;span id=&quot;navlogout&quot;&gt;&lt;a href=&quot;&#039;.forum_link($forum_url[&#039;logout&#039;], array($forum_user[&#039;id&#039;], generate_form_token(&#039;logout&#039;.$forum_user[&#039;id&#039;]))).&#039;&quot;&gt;&#039;.$lang_common[&#039;Logout&#039;].&#039;&lt;/a&gt;&lt;/span&gt; | &#039;;?&gt;
&lt;?php echo $links[&#039;profile&#039;] = &#039;&lt;span id=&quot;navprofile&quot;&#039;.((substr(FORUM_PAGE, 0, 7) == &#039;profile&#039;) ? &#039; class=&quot;isactive&quot;&#039; : &#039;&#039;).&#039;&gt;&lt;a href=&quot;&#039;.forum_link($forum_url[&#039;user&#039;], $forum_user[&#039;id&#039;]).&#039;&quot;&gt;&#039;.$lang_common[&#039;Profile&#039;].&#039;&lt;/a&gt;&lt;/span&gt; | &#039;;?&gt;
&lt;?php echo $links[&#039;userlist&#039;] = &#039;&lt;span id=&quot;navuserlist&quot;&#039;.((FORUM_PAGE == &#039;userlist&#039;) ? &#039; class=&quot;isactive&quot;&#039; : &#039;&#039;).&#039;&gt;&lt;a href=&quot;&#039;.forum_link($forum_url[&#039;users&#039;]).&#039;&quot;&gt;&#039;.$lang_common[&#039;User list&#039;].&#039;&lt;/a&gt;&lt;/span&gt;&#039;;?&gt;
&lt;?php if ($avatar != &#039;&#039;) : ?&gt;
            &lt;?php echo $avatar ?&gt;
&lt;?php else : ?&gt;
&lt;?php endif; ?&gt;
            &lt;ul class=&quot;stats-online&quot;&gt;
                &lt;?php echo implode(&quot;\n\t\t\t&quot;, $stats_online) ?&gt;
            &lt;/ul&gt;
        
            &lt;?php //if (isset($users_online)) : echo $users_online; endif; ?&gt;&lt;!--Décommenter cette ligne pour afficher les utilisateurs en ligne--&gt;

&lt;?php

}


// Else user is not logged, display login form
else
{
    $cur_panel[&#039;title&#039;] = $lang_common[&#039;Login&#039;];

    require_once FORUM_ROOT.&#039;lang/&#039;.$forum_user[&#039;language&#039;].&#039;/login.php&#039;;
    $form_action = forum_link($forum_url[&#039;login&#039;]);
?&gt;
    &lt;?php echo Bienvenue ?&gt;: &lt;strong&gt;&lt;?php echo $lang_login[&#039;Guest&#039;] ?&gt;&lt;/strong&gt;    &lt;br /&gt;
    &lt;?php echo $lang_login[&#039;Please login&#039;] ?&gt;&lt;br /&gt;
    &lt;a href=&quot;&lt;?php echo forum_link($forum_url[&#039;register&#039;]) ?&gt;&quot;&gt;&lt;?php echo $lang_login[&#039;Register&#039;] ?&gt;&lt;/a&gt;
    &lt;a href=&quot;&lt;?php echo forum_link($forum_url[&#039;request_password&#039;]) ?&gt;&quot;&gt;&lt;?php echo $lang_login[&#039;New password&#039;] ?&gt;&lt;/a&gt;&lt;br /&gt;
    &lt;form method=&quot;post&quot; action=&quot;&lt;?php echo $form_action ?&gt;&quot;&gt;
        &lt;div class=&quot;hidden&quot;&gt;
            &lt;input type=&quot;hidden&quot; name=&quot;form_sent&quot; value=&quot;1&quot; /&gt;
            &lt;input type=&quot;hidden&quot; name=&quot;redirect_url&quot; value=&quot;&lt;?php echo get_current_url() ?&gt;&quot; /&gt;
            &lt;input type=&quot;hidden&quot; name=&quot;csrf_token&quot; value=&quot;&lt;?php echo generate_form_token($form_action) ?&gt;&quot; /&gt;
        &lt;/div&gt;
        &lt;div class=&quot;panel-input&quot;&gt;
            &lt;?php echo $lang_login[&#039;Username&#039;] ?&gt;
            &lt;input type=&quot;text&quot; name=&quot;req_username&quot; size=&quot;13&quot; /&gt;&lt;br /&gt;
        &lt;/div&gt;
        &lt;div class=&quot;panel-input&quot;&gt;
            &lt;?php echo $lang_login[&#039;Password&#039;] ?&gt;
            &lt;input type=&quot;password&quot; name=&quot;req_password&quot; size=&quot;13&quot; /&gt;&lt;br /&gt;
        &lt;/div&gt;
        &lt;div&gt;
            &lt;label for=&quot;fld-remember-me&quot;&gt;&lt;span class=&quot;fld-label&quot;&gt;&lt;?php echo $lang_login[&#039;Remember me&#039;] ?&gt;&lt;/span&gt;&amp;nbsp;&lt;input type=&quot;checkbox&quot; id=&quot;fld-remember-me&quot; name=&quot;save_pass&quot; value=&quot;1&quot; /&gt;&lt;/label&gt;
            &lt;span class=&quot;submit&quot;&gt;&lt;input type=&quot;submit&quot; name=&quot;login&quot; value=&quot;&lt;?php echo $lang_common[&#039;Login&#039;] ?&gt;&quot; /&gt;&lt;/span&gt;
        &lt;/div&gt;
            
            
&lt;/form&gt;&lt;?php

}

// this variable is also used for display statistics on forums page
unset($stats_list);

?&gt;</code></pre></div><p>Obviously, this code requires adding the extra links contained in the navlinks. Personally, I don&#039;t need more than that.</p><p>To the login file of your &quot;language pack&quot; (?), add the following lines (translate according to your needs):<br /></p><div class="codebox"><pre><code>&#039;Guest&#039;                                =&gt;    &#039;Visiteur&#039;,
&#039;Welcome&#039;                            =&gt;    &#039;Bienvenue&#039;,
&#039;Please login&#039;                        =&gt;    &#039;Déjà inscrit? Connectez-vous.&#039;,
&#039;Register&#039;                            =&gt;    &#039;S\&#039;enregistrer&#039;,
&#039;New password&#039;                        =&gt;    &#039;Redéfinir mot de passe&#039;</code></pre></div><p>Finally, you&#039;ll have to create some CSS based on the theme of your site. This code works fine. It could require some thorough code inspection, but I don&#039;t know PHP.</p>]]></description>
			<author><![CDATA[null@example.com (littlebigfred)]]></author>
			<pubDate>Wed, 21 Jul 2010 09:58:20 +0000</pubDate>
			<guid>https://punbb.informer.com/forums/post/136330/#p136330</guid>
		</item>
		<item>
			<title><![CDATA[Re: Login Integration]]></title>
			<link>https://punbb.informer.com/forums/post/135692/#p135692</link>
			<description><![CDATA[<p>Bonjour.</p><p>Bien j&#039;ai trouvé un morceau de code qui permets de disposer une boite de connexion sur toutes les pages du site, je ne suis pas l&#039;auteur de ce code je l&#039;ai trouvé sur une mod je ne sais plus laquelle mais cela fonctionne.</p><p>Son auteur se reconnaitra.</p><br /><p>Avant le doctype de votre document&nbsp; il fait ajouter les lignes suivantes.<br /></p><div class="codebox"><pre><code>&lt;?php
 
// Add these lines in the very top of your code
define(&#039;FORUM_ROOT&#039;, &#039;./forum/&#039;);
require FORUM_ROOT.&#039;include/common.php&#039;; 
?&gt;</code></pre></div><p><strong>Puis a l&#039;endroit ou vous voulez voir apparaitre la case de connexion ajoutez le code suivant, les membres peuvent voir aussi l&#039;avatar s&#039;ils sont connectés.</strong><br /></p><div class="codebox"><pre><code>&lt;?php
// If user is logged display some informations about it
if (!$forum_user[&#039;is_guest&#039;])
{
    require FORUM_ROOT.&#039;lang/&#039;.$forum_user[&#039;language&#039;].&#039;/index.php&#039;;
    if ($forum_config[&#039;o_users_online&#039;] == &#039;1&#039;)
    {
        // Fetch users online info and generate strings for output
        $query = array(
            &#039;SELECT&#039;    =&gt; &#039;o.user_id, o.ident&#039;,
            &#039;FROM&#039;        =&gt; &#039;online AS o&#039;,
            &#039;WHERE&#039;        =&gt; &#039;o.idle=0&#039;,
            &#039;ORDER BY&#039;    =&gt; &#039;o.ident&#039;
        );
        $result = $forum_db-&gt;query_build($query) or error(__FILE__, __LINE__);
        $num_guests = 0;
        $users = array();

        while ($forum_user_online = $forum_db-&gt;fetch_assoc($result))
        {

            if ($forum_user_online[&#039;user_id&#039;] &gt; 1)
                $users[] = &#039;&lt;a href=&quot;&#039;.forum_link($forum_url[&#039;user&#039;], $forum_user_online[&#039;user_id&#039;]).&#039;&quot;&gt;&#039;.forum_htmlencode($forum_user_online[&#039;ident&#039;]).&#039;&lt;/a&gt;&#039;;
            else
                ++$num_guests;
            
        }

        // If there are registered users logged in, list them
        if (count($users) &gt; 0)
            //$users_online = &#039;&lt;p&gt;&lt;strong&gt;&#039;.$forum_user[&#039;Online&#039;].&#039;&lt;/strong&gt; &#039;.implode(&#039;, &#039;, $users).&#039;&lt;/p&gt;&#039;;&lt;!--Décommenter cette ligne pour afficher les utilisateurs en ligne--&gt;

        $stats_online[] = &#039;Membres en ligne: &lt;strong&gt;&#039;.count($users).&#039;&lt;/strong&gt;&lt;br /&gt;&#039;;
        $stats_online[] = &#039;Visiteurs en ligne: &lt;strong&gt;&#039;.$num_guests.&#039;&lt;/strong&gt;&#039;;
    }
    
    $avatar = generate_avatar_markup($forum_user[&#039;id&#039;]);
?&gt;
&lt;?php echo Bienvenue ?&gt;: &lt;strong&gt;&lt;?php echo forum_htmlencode($forum_user[&#039;username&#039;]) ?&gt;  &lt;/strong&gt; &lt;br /&gt;
&lt;?php echo $links[&#039;logout&#039;] = &#039;&lt;span id=&quot;navlogout&quot;&gt;&lt;a href=&quot;&#039;.forum_link($forum_url[&#039;logout&#039;], array($forum_user[&#039;id&#039;], generate_form_token(&#039;logout&#039;.$forum_user[&#039;id&#039;]))).&#039;&quot;&gt;&#039;.$lang_common[&#039;Logout&#039;].&#039;&lt;/a&gt;&lt;/span&gt; | &#039;;?&gt;
&lt;?php echo $links[&#039;profile&#039;] = &#039;&lt;span id=&quot;navprofile&quot;&#039;.((substr(FORUM_PAGE, 0, 7) == &#039;profile&#039;) ? &#039; class=&quot;isactive&quot;&#039; : &#039;&#039;).&#039;&gt;&lt;a href=&quot;&#039;.forum_link($forum_url[&#039;user&#039;], $forum_user[&#039;id&#039;]).&#039;&quot;&gt;&#039;.$lang_common[&#039;Profile&#039;].&#039;&lt;/a&gt;&lt;/span&gt; | &#039;;?&gt;
&lt;?php echo $links[&#039;userlist&#039;] = &#039;&lt;span id=&quot;navuserlist&quot;&#039;.((FORUM_PAGE == &#039;userlist&#039;) ? &#039; class=&quot;isactive&quot;&#039; : &#039;&#039;).&#039;&gt;&lt;a href=&quot;&#039;.forum_link($forum_url[&#039;users&#039;]).&#039;&quot;&gt;&#039;.$lang_common[&#039;User list&#039;].&#039;&lt;/a&gt;&lt;/span&gt;&#039;;?&gt;
&lt;?php if ($avatar != &#039;&#039;) : ?&gt;
            &lt;?php echo $avatar ?&gt;
&lt;?php else : ?&gt;
&lt;?php endif; ?&gt;
            &lt;ul class=&quot;stats-online&quot;&gt;
                &lt;?php echo implode(&quot;\n\t\t\t&quot;, $stats_online) ?&gt;
            &lt;/ul&gt;
        
            &lt;?php //if (isset($users_online)) : echo $users_online; endif; ?&gt;&lt;!--Décommenter cette ligne pour afficher les utilisateurs en ligne--&gt;

&lt;?php

}


// Else user is not logged, display login form
else
{
    $cur_panel[&#039;title&#039;] = $lang_common[&#039;Login&#039;];

    require_once FORUM_ROOT.&#039;lang/&#039;.$forum_user[&#039;language&#039;].&#039;/login.php&#039;;
    $form_action = forum_link($forum_url[&#039;login&#039;]);
?&gt;
    &lt;?php echo Bienvenue ?&gt;: &lt;strong&gt;&lt;?php echo $lang_login[&#039;Guest&#039;] ?&gt;&lt;/strong&gt;    &lt;br /&gt;
    &lt;?php echo $lang_login[&#039;Please login&#039;] ?&gt;&lt;br /&gt;
    &lt;a href=&quot;&lt;?php echo forum_link($forum_url[&#039;register&#039;]) ?&gt;&quot;&gt;&lt;?php echo $lang_login[&#039;Register&#039;] ?&gt;&lt;/a&gt;
    &lt;a href=&quot;&lt;?php echo forum_link($forum_url[&#039;request_password&#039;]) ?&gt;&quot;&gt;&lt;?php echo $lang_login[&#039;New password&#039;] ?&gt;&lt;/a&gt;&lt;br /&gt;
    &lt;form method=&quot;post&quot; action=&quot;&lt;?php echo $form_action ?&gt;&quot;&gt;
        &lt;div class=&quot;hidden&quot;&gt;
            &lt;input type=&quot;hidden&quot; name=&quot;form_sent&quot; value=&quot;1&quot; /&gt;
            &lt;input type=&quot;hidden&quot; name=&quot;redirect_url&quot; value=&quot;&lt;?php echo get_current_url() ?&gt;&quot; /&gt;
            &lt;input type=&quot;hidden&quot; name=&quot;csrf_token&quot; value=&quot;&lt;?php echo generate_form_token($form_action) ?&gt;&quot; /&gt;
        &lt;/div&gt;
        &lt;div class=&quot;panel-input&quot;&gt;
            &lt;?php echo $lang_login[&#039;Username&#039;] ?&gt;
            &lt;input type=&quot;text&quot; name=&quot;req_username&quot; size=&quot;13&quot; /&gt;&lt;br /&gt;
        &lt;/div&gt;
        &lt;div class=&quot;panel-input&quot;&gt;
            &lt;?php echo $lang_login[&#039;Password&#039;] ?&gt;
            &lt;input type=&quot;password&quot; name=&quot;req_password&quot; size=&quot;13&quot; /&gt;&lt;br /&gt;
        &lt;/div&gt;
        &lt;div&gt;
            &lt;label for=&quot;fld-remember-me&quot;&gt;&lt;span class=&quot;fld-label&quot;&gt;&lt;?php echo $lang_login[&#039;Remember me&#039;] ?&gt;&lt;/span&gt;&amp;nbsp;&lt;input type=&quot;checkbox&quot; id=&quot;fld-remember-me&quot; name=&quot;save_pass&quot; value=&quot;1&quot; /&gt;&lt;/label&gt;
            &lt;span class=&quot;submit&quot;&gt;&lt;input type=&quot;submit&quot; name=&quot;login&quot; value=&quot;&lt;?php echo $lang_common[&#039;Login&#039;] ?&gt;&quot; /&gt;&lt;/span&gt;
        &lt;/div&gt;
            
            
&lt;/form&gt;&lt;?php

}

// this variable is also used for display statistics on forums page
unset($stats_list);

?&gt;</code></pre></div><p><strong>Bien sur il faudrait ajouter a ce code les liens supplementaires contenus dans la navlinks, personellement je n&#039;ais pas besoin de plus.</strong></p><p>Ajouter au fichier login de votre pack langage les lignes suivantes (traduisez selon vos besoins) <br /></p><div class="codebox"><pre><code>&#039;Guest&#039;                                =&gt;    &#039;Visiteur&#039;,
&#039;Welcome&#039;                            =&gt;    &#039;Bienvenue&#039;,
&#039;Please login&#039;                        =&gt;    &#039;Déjà inscrit? Connectez-vous.&#039;,
&#039;Register&#039;                            =&gt;    &#039;S\&#039;enregistrer&#039;,
&#039;New password&#039;                        =&gt;    &#039;Redéfinir mot de passe&#039;</code></pre></div><p>Enfin un code CSS devra etre creé selon les besoins de chacun,sur le thème du site.</p><p>Ce code fonctionne parfaitement, il est possible de faire un nettoyage de code approfondi car je n&#039;y connais rien en php.</p>]]></description>
			<author><![CDATA[null@example.com (Clyd)]]></author>
			<pubDate>Thu, 17 Jun 2010 18:57:12 +0000</pubDate>
			<guid>https://punbb.informer.com/forums/post/135692/#p135692</guid>
		</item>
		<item>
			<title><![CDATA[Re: Login Integration]]></title>
			<link>https://punbb.informer.com/forums/post/134661/#p134661</link>
			<description><![CDATA[<p>Hi, please can you explain step by step how you integrated the registrations? Thank you.</p>]]></description>
			<author><![CDATA[null@example.com (nwuese)]]></author>
			<pubDate>Mon, 05 Apr 2010 16:10:20 +0000</pubDate>
			<guid>https://punbb.informer.com/forums/post/134661/#p134661</guid>
		</item>
		<item>
			<title><![CDATA[Re: Login Integration]]></title>
			<link>https://punbb.informer.com/forums/post/133738/#p133738</link>
			<description><![CDATA[<p>if you find out the code, can u please post. i want the same thing.</p><p>thanks</p>]]></description>
			<author><![CDATA[null@example.com (SuperMAG)]]></author>
			<pubDate>Sun, 07 Feb 2010 09:07:29 +0000</pubDate>
			<guid>https://punbb.informer.com/forums/post/133738/#p133738</guid>
		</item>
		<item>
			<title><![CDATA[Re: Login Integration]]></title>
			<link>https://punbb.informer.com/forums/post/133721/#p133721</link>
			<description><![CDATA[<p>I think this could be the issue, I tried to do the same once before but I ran into an error about this </p><p>&lt;input type=&quot;hidden&quot; name=&quot;csrf_token&quot; value=&quot;5d6873d60498923b36391b783160d6370eec5daf&quot; /&gt;</p><p>If im correct each login creates a different value and no matter if your session is correct unless you have the same csrf_token script you will not be logged in, </p><p>I&#039;m not sure the developers want us to post how to hack the login on the forum so If and when you figure it out message me :-)</p>]]></description>
			<author><![CDATA[null@example.com (todhend)]]></author>
			<pubDate>Sat, 06 Feb 2010 16:03:18 +0000</pubDate>
			<guid>https://punbb.informer.com/forums/post/133721/#p133721</guid>
		</item>
		<item>
			<title><![CDATA[Login Integration]]></title>
			<link>https://punbb.informer.com/forums/post/133704/#p133704</link>
			<description><![CDATA[<p>I&#039;ve been searching the forums on how to integrate punbb with my current site&#039;s login and registration system.&nbsp; I&#039;ve successfully integrated the registrations, but I can&#039;t get the login process to integrate.&nbsp; I am trying to have users login at mysite.com, and have them automatically logged in to mysite.com/punbb.&nbsp; I&#039;ve tried adapting the code found here: <a href="http://punbb.informer.com/forums/topic/17973/login-integration-logging-in-on-an-existing-site-and-punbb/">http://punbb.informer.com/forums/topic/ … and-punbb/</a>.</p><p>I can log in via my site, but it won&#039;t log in to the punbb forums.&nbsp; Here is my entire code:</p><div class="codebox"><pre><code>&lt;?php 

defined(&#039;C5_EXECUTE&#039;) or die(_(&quot;Access Denied.&quot;));
Loader::library(&#039;authentication/open_id&#039;);
//Punbb code
define(&#039;FORUM_ROOT&#039;, &#039;./punbb/&#039;);



class LoginController extends Controller { 
    
    public $helpers = array(&#039;form&#039;);
    private $openIDReturnTo;
    public function on_start() {
        $this-&gt;error = Loader::helper(&#039;validation/error&#039;);
        if (USER_REGISTRATION_WITH_EMAIL_ADDRESS == true) {
            $this-&gt;set(&#039;uNameLabel&#039;, t(&#039;Email Address&#039;));
        } else {
            $this-&gt;set(&#039;uNameLabel&#039;, t(&#039;Username&#039;));
        }
        if (strlen($_GET[&#039;uName&#039;])) { // pre-populate the username if supplied
            $this-&gt;set(&quot;uName&quot;,$_GET[&#039;uName&#039;]);
        }
        
        $this-&gt;openIDReturnTo = BASE_URL . View::url(&quot;/login&quot;, &quot;complete_openid&quot;); 
    }
    
    /* automagically run by the controller once we&#039;re done with the current method */
    /* method is passed to this method, the method that we were just finished running */
    public function on_before_render() {
        if ($this-&gt;error-&gt;has()) {
            $this-&gt;set(&#039;error&#039;, $this-&gt;error);
        }
    }
    
    public function complete_openid_email() {
        $email = $this-&gt;post(&#039;uEmail&#039;);
        $vals = Loader::helper(&#039;validation/strings&#039;);
        $valc = Loader::helper(&#039;concrete/validation&#039;);
        if (!$vals-&gt;email($email)) {
            $this-&gt;error-&gt;add(t(&#039;Invalid email address provided.&#039;));
        } else if (!$valc-&gt;isUniqueEmail($email)) {
            $this-&gt;error-&gt;add(t(&quot;The email address %s is already in use. Please choose another.&quot;, $_POST[&#039;uEmail&#039;]));
        }    
    
        if (!$this-&gt;error-&gt;has()) {
            // complete the openid record with the provided email
            if (isset($_SESSION[&#039;uOpenIDRequested&#039;])) {
                $oa = new OpenIDAuth();
                $ui = $oa-&gt;registerUser($_SESSION[&#039;uOpenIDRequested&#039;], $email);
                User::loginByUserID($ui-&gt;getUserID());
                $this-&gt;finishLogin();
            }
        }
    }
    
    public function view() {
        $this-&gt;clearOpenIDSession();
    }
    
    private function clearOpenIDSession() {
        unset($_SESSION[&#039;uOpenIDError&#039;]);
        unset($_SESSION[&#039;uOpenIDRequested&#039;]);
        unset($_SESSION[&#039;uOpenIDExistingUser&#039;]);
    }
    
    public function complete_openid() {
        $v = Loader::helper(&#039;validation/numbers&#039;);
        $oa = new OpenIDAuth();
        $oa-&gt;setReturnURL($this-&gt;openIDReturnTo);
        $oa-&gt;complete();
        $response = $oa-&gt;getResponse();
        if ($response-&gt;code == OpenIDAuth::E_CANCEL) {
            $this-&gt;error-&gt;add(t(&#039;OpenID Verification Cancelled&#039;));
            $this-&gt;clearOpenIDSession();
        } else if ($response-&gt;code == OpenIDAuth::E_FAILURE) {
            $this-&gt;error-&gt;add(t(&#039;OpenID Authentication Failed: %s&#039;, $response-&gt;message));
            $this-&gt;clearOpenIDSession();
        } else {
            switch($response-&gt;code) {
                case OpenIDAuth::S_USER_CREATED:
                case OpenIDAuth::S_USER_AUTHENTICATED:
                    if ($v-&gt;integer($response-&gt;message)) {
                        User::loginByUserID($response-&gt;message);
                        $this-&gt;finishLogin();
                    }
                    break;
                case OpenIDAuth::E_REGISTRATION_EMAIL_INCOMPLETE:
                    // we don&#039;t have an email address, but the account is valid
                    // valid display identifier comes back in message
                    $_SESSION[&#039;uOpenIDRequested&#039;] = $response-&gt;message;
                    $_SESSION[&#039;uOpenIDError&#039;] = OpenIDAuth::E_REGISTRATION_EMAIL_INCOMPLETE;
                    break; 
                case OpenIDAuth::E_REGISTRATION_EMAIL_EXISTS:
                    // an email address came back with us from the openid server
                    // but that email already exists
                    $_SESSION[&#039;uOpenIDRequested&#039;] = $response-&gt;openid;
                    $_SESSION[&#039;uOpenIDExistingUser&#039;] = $response-&gt;user;
                    $_SESSION[&#039;uOpenIDError&#039;] = OpenIDAuth::E_REGISTRATION_EMAIL_EXISTS;
                    break;
            }
        }
        $this-&gt;set(&#039;oa&#039;, $oa);        
    }
    
    public function account_deactivated() {
        $this-&gt;error-&gt;add(t(&#039;This user is inactive. Please contact us regarding this account.&#039;));
    }
    
    public function do_login() { 
        $ip = Loader::helper(&#039;validation/ip&#039;);
        $vs = Loader::helper(&#039;validation/strings&#039;);
        
        $loginData[&#039;success&#039;]=0;
        
        try {
            if (!$ip-&gt;check()) {                
                throw new Exception($ip-&gt;getErrorMessage());
            }
            if (OpenIDAuth::isEnabled() &amp;&amp; $vs-&gt;notempty($this-&gt;post(&#039;uOpenID&#039;))) {
                $oa = new OpenIDAuth();
                $oa-&gt;setReturnURL($this-&gt;openIDReturnTo);
                $return = $oa-&gt;request($this-&gt;post(&#039;uOpenID&#039;));
                $resp = $oa-&gt;getResponse();
                if ($resp-&gt;code == OpenIDAuth::E_INVALID_OPENID) {
                    throw new Exception(t(&#039;Invalid OpenID.&#039;));
                }
            }
            
            if ((!$vs-&gt;notempty($this-&gt;post(&#039;uName&#039;))) || (!$vs-&gt;notempty($this-&gt;post(&#039;uPassword&#039;)))) {
                if (USER_REGISTRATION_WITH_EMAIL_ADDRESS) {
                    throw new Exception(t(&#039;An email address and password are required.&#039;));
                } else {
                    throw new Exception(t(&#039;A username and password are required.&#039;));
                }
            }
            
            $u = new User($this-&gt;post(&#039;uName&#039;), $this-&gt;post(&#039;uPassword&#039;));
            if ($u-&gt;isError()) {
                switch($u-&gt;getError()) {
                    case USER_NON_VALIDATED:
                        throw new Exception(t(&#039;This account has not yet been validated. Please check the email associated with this account and follow the link it contains.&#039;));
                        break;
                    case USER_INVALID:
                        if (USER_REGISTRATION_WITH_EMAIL_ADDRESS) {
                            throw new Exception(t(&#039;Invalid email address or password.&#039;));
                        } else {
                            throw new Exception(t(&#039;Invalid username or password.&#039;));                        
                        }
                        break;
                    case USER_INACTIVE:
                        throw new Exception(t(&#039;This user is inactive. Please contact us regarding this account.&#039;));
                        break;
                }
            } else {
            
                if (OpenIDAuth::isEnabled() &amp;&amp; $_SESSION[&#039;uOpenIDExistingUser&#039;] &gt; 0) {
                    $oa = new OpenIDAuth();
                    if ($_SESSION[&#039;uOpenIDExistingUser&#039;] == $u-&gt;getUserID()) {
                        // the account we logged in with is the same as the existing user from the open id. that means
                        // we link the account to open id and keep the user logged in.
                        $oa-&gt;linkUser($_SESSION[&#039;uOpenIDRequested&#039;], $u);
                    } else {
                        // The user HAS logged in. But the account they logged into is NOT the same as the one
                        // that links to their OpenID. So we log them out and tell them so.
                        $u-&gt;logout();
                        throw new Exception(t(&#039;This account does not match the email address provided.&#039;));
                    }

//Punbb Code
include &#039;punbb/include/common.php&#039;;    //Include this file so that $pun_user[&#039;is_guest&#039;] can be used and that (some?) functions from punbb/include/functions.php can also be used in this script


if (($websitelogin==true) &amp;&amp; ($forum_user[&#039;is_guest&#039;])) {

    
 $username =$this-&gt;post(&#039;uEmail&#039;);  //Get the username of the logged in user and put it in a variable     ($user-&gt;Username comes from code from the website which is intended to get login integration with punbb through this script)
    
    $queryFromPunbb = &quot;SELECT * FROM pun1_users WHERE username=&#039;$username&#039;&quot;;    //get the row with the id from the logged in user. This id is the primary key of the punbb_users table in the punbb database
    $result = mysql_query($queryFromPunbb, $conn) or die (mysql_error());    //Run the query
    $row = mysql_fetch_array($result) or die(mysql_error());    //Put the result of the query in an array called $row  
    
    $user_id = $row[&#039;id&#039;];    //Put the id from the $row array into the variable $user_id
    $hashedPassword = forum_hash($this-&gt;post(&#039;uPassword&#039;));    //hash the user&#039;s password using the punbb hash function 
    $expirationTime = time()+24*60*60;
    
    forum_setcookie($user_id, $hashedPassword, $expirationTime); //Set the punBB cookie, which is called punbb_cookie
    

}

                }
                
                $loginData[&#039;success&#039;]=1;
                $loginData[&#039;msg&#039;]=t(&#039;Login Successful&#039;);    
                $loginData[&#039;uID&#039;] = intval($u-&gt;getUserID());
                if($_REQUEST[&#039;remote&#039;] &amp;&amp; intval($_REQUEST[&#039;timestamp&#039;])){ 
                    $loginData[&#039;auth_token&#039;] =     UserInfo::generateAuthToken( $u-&gt;getUserName(), intval($_REQUEST[&#039;timestamp&#039;]) );
                    //is this user in a support group? 
                    foreach( RemoteMarketplaceHelper::getSupportGroups() as $group){
                        if($u-&gt;inGroup($group)){
                            $inValidSupportGroup=1;
                            break;
                        }

    


                    }
                    $loginData[&#039;in_support_group&#039;] = intval($inValidSupportGroup);
                }
            }

            $loginData = $this-&gt;finishLogin($loginData);





            
        } catch(Exception $e) {
            $ip-&gt;logSignupRequest();
            if ($ip-&gt;signupRequestThreshholdReached()) {
                $ip-&gt;createIPBan();
            }
            $this-&gt;error-&gt;add($e);
            $loginData[&#039;error&#039;]=$e-&gt;getMessage();
        }
        
        if( $_REQUEST[&#039;format&#039;]==&#039;JSON&#039; ){
            $jsonHelper=Loader::helper(&#039;json&#039;); 
            echo $jsonHelper-&gt;encode($loginData);
            die;
        }



    }



    protected function finishLogin( $loginData=array() ) {
        $u = new User();
        if ($this-&gt;post(&#039;uMaintainLogin&#039;)) {
            $u-&gt;setUserForeverCookie();
        }
        $rcID = $this-&gt;post(&#039;rcID&#039;);
        $nh = Loader::helper(&#039;validation/numbers&#039;);

        //set redirect url
        if ($nh-&gt;integer($rcID)) {
            $nh = Loader::helper(&#039;navigation&#039;);
            $rc = Page::getByID($rcID);
            $url = $nh-&gt;getLinkToCollection($rc, true);
            $loginData[&#039;redirectURL&#039;] = $url;
        }elseif( strlen($rcID) ){
            $loginData[&#039;redirectURL&#039;] = $rcID;
        }
        
        //full page login redirect (non-ajax login)
        if( strlen($loginData[&#039;redirectURL&#039;]) &amp;&amp; $_REQUEST[&#039;format&#039;]!=&#039;JSON&#039; ){ 
            header(&#039;Location: &#039; . $loginData[&#039;redirectURL&#039;]);
            exit;    
        }
        
        //not sure why there&#039;s this second redirect approach, but oh well...
        if ($this-&gt;post(&#039;redirect&#039;) != &#039;&#039; &amp;&amp; $this-&gt;isValidExternalUrl($this-&gt;post(&#039;redirect&#039;))) {
            $loginData[&#039;redirectURL&#039;]=$this-&gt;post(&#039;redirect&#039;);
        }
        
        $dash = Page::getByPath(&quot;/dashboard&quot;, &quot;RECENT&quot;);
        $dbp = new Permissions($dash);        
        
        Events::fire(&#039;on_user_login&#039;,$this);
        
        //End JSON Login
        if($_REQUEST[&#039;format&#039;]==&#039;JSON&#039;) 
            return $loginData;        
        
        //should administrator be redirected to dashboard?  defaults to yes if not set. 
        $adminToDash=intval(Config::get(&#039;LOGIN_ADMIN_TO_DASHBOARD&#039;));      
        
        //Full page login, standard redirection            
        if ($loginData[&#039;redirectURL&#039;]) {
            //make double secretly sure there&#039;s no caching going on
            header(&quot;Cache-Control: no-store, no-cache, must-revalidate&quot;);
            header(&quot;Pragma: no-cache&quot;);
            header(&#039;Expires: Fri, 30 Oct 1998 14:19:41 GMT&#039;); //in the past        
            $this-&gt;externalRedirect( $loginData[&#039;redirectURL&#039;] );
        }else if ( $dbp-&gt;canRead() &amp;&amp; $adminToDash ) {
            $this-&gt;redirect(&#039;/dashboard&#039;);
        } else {
            //options set in dashboard/users/registration
            $login_redirect_cid=intval(Config::get(&#039;LOGIN_REDIRECT_CID&#039;));
            $login_redirect_mode=Config::get(&#039;LOGIN_REDIRECT&#039;);        
            
            //redirect to user profile
            if( $login_redirect_mode==&#039;PROFILE&#039; &amp;&amp; ENABLE_USER_PROFILES ){             
                $this-&gt;redirect( &#039;/profile/&#039;, $u-&gt;uID );                 
                
            //redirect to custom page    
            }elseif( $login_redirect_mode==&#039;CUSTOM&#039; &amp;&amp; $login_redirect_cid &gt; 0 ){ 
                $redirectTarget = Page::getByID( $login_redirect_cid ); 
                if(intval($redirectTarget-&gt;cID)&gt;0) $this-&gt;redirect( $redirectTarget-&gt;getCollectionPath() );
                else $this-&gt;redirect(&#039;/home&#039;);        
                        
            //redirect home
            }else $this-&gt;redirect(&#039;/home&#039;);
        }
    }

    public function password_sent() {
        $this-&gt;set(&#039;intro_msg&#039;, $this-&gt;getPasswordSentMsg() );
    }
    
    public function getPasswordSentMsg(){
        return t(&#039;An email containing instructions on reseting your password has been sent to your account address.&#039;);
    }
    
    public function logout() {
        $u = new User();
        $u-&gt;logout();
        $this-&gt;redirect(&#039;/&#039;);

    }
    
    public function forward($cID) {
        $this-&gt;set(&#039;rcID&#039;, $cID);
    }
    
    // responsible for validating a user&#039;s email address
    public function v($hash) {
        $ui = UserInfo::getByValidationHash($hash);
        if (is_object($ui)) {
            $ui-&gt;markValidated();
            $this-&gt;set(&#039;uEmail&#039;, $ui-&gt;getUserEmail());
            $this-&gt;set(&#039;validated&#039;, true);
        }
    }
    
    // responsible for validating a user&#039;s email address
    public function change_password($uHash) {
        $db = Loader::db();
        $h = Loader::helper(&#039;validation/identifier&#039;);
        $e = Loader::helper(&#039;validation/error&#039;);
        
        $ui = UserInfo::getByValidationHash($uHash);        
        if (is_object($ui)){
            $hashCreated = $db-&gt;GetOne(&quot;select uDateGenerated FROM UserValidationHashes where uHash=?&quot;, array($uHash));
            if($hashCreated &lt; (time()-(USER_CHANGE_PASSWORD_URL_LIFETIME))) {
                $h-&gt;deleteKey(&#039;UserValidationHashes&#039;,&#039;uHash&#039;,$uHash);
                throw new Exception( t(&#039;Key Expired. Please visit the forgot password page again to have a new key generated.&#039;) );
            }else{    
            
                if(strlen($_POST[&#039;uPassword&#039;])){
                
                    $userHelper = Loader::helper(&#039;concrete/user&#039;);
                    $userHelper-&gt;validNewPassword($_POST[&#039;uPassword&#039;],$e);
                    
                    if(strlen($_POST[&#039;uPassword&#039;]) &amp;&amp; $_POST[&#039;uPasswordConfirm&#039;]!=$_POST[&#039;uPassword&#039;]){            
                        $e-&gt;add(t(&#039;The two passwords provided do not match.&#039;));
                    }
                    
                    if (!$e-&gt;has()){ 
                        $ui-&gt;changePassword( $_POST[&#039;uPassword&#039;] );                        
                        $h-&gt;deleteKey(&#039;UserValidationHashes&#039;,&#039;uHash&#039;,$uHash);                    
                        $this-&gt;set(&#039;passwordChanged&#039;, true);
                        
                        $u = $ui-&gt;getUserObject();
                        $_POST[&#039;uName&#039;] =  $u-&gt;getUserName();
                        $this-&gt;do_login();
                            
                        return;
                    }else{
                        $this-&gt;set(&#039;uHash&#039;, $uHash);
                        $this-&gt;set(&#039;changePasswordForm&#039;, true);                    
                        $this-&gt;set(&#039;errorMsg&#039;, join( &#039;&lt;br&gt;&#039;, $e-&gt;getList() ) );                    
                    }
                }else{                 
                    $this-&gt;set(&#039;uHash&#039;, $uHash);
                    $this-&gt;set(&#039;changePasswordForm&#039;, true);
                }
            }        
        }else{
            throw new Exception( t(&#039;Invalid Key. Please visit the forgot password page again to have a new key generated.&#039;) );
        }
    }    
    
    public function forgot_password() {
        $loginData[&#039;success&#039;]=0;
    
        $vs = Loader::helper(&#039;validation/strings&#039;);
        $em = $this-&gt;post(&#039;uEmail&#039;);
        try {
            if (!$vs-&gt;email($em)) {
                throw new Exception(t(&#039;Invalid email address.&#039;));
            }
            
            $oUser = UserInfo::getByEmail($em);
            if (!$oUser) {
                throw new Exception(t(&#039;We have no record of that email address.&#039;));
            }            
            
            $mh = Loader::helper(&#039;mail&#039;);
            //$mh-&gt;addParameter(&#039;uPassword&#039;, $oUser-&gt;resetUserPassword());
            $mh-&gt;addParameter(&#039;uName&#039;, $oUser-&gt;getUserName());            
            $mh-&gt;to($oUser-&gt;getUserEmail());
            
            //generate hash that&#039;ll be used to authenticate user, allowing them to change their password
            $h = Loader::helper(&#039;validation/identifier&#039;);
            $uHash = $h-&gt;generate(&#039;UserValidationHashes&#039;, &#039;uHash&#039;);    
            $db = Loader::db();
            $db-&gt;Execute(&quot;DELETE FROM UserValidationHashes WHERE uID=?&quot;, array( $oUser-&gt;uID ) );            
            $db-&gt;Execute(&quot;insert into UserValidationHashes (uID, uHash, uDateGenerated, type) values (?, ?, ?, ?)&quot;, array($oUser-&gt;uID, $uHash, time(),intval(UVTYPE_CHANGE_PASSWORD)));        
            $changePassURL=BASE_URL . View::url(&#039;/login&#039;, &#039;change_password&#039;, $uHash);         
            $mh-&gt;addParameter(&#039;changePassURL&#039;, $changePassURL);
            
            if (defined(&#039;EMAIL_ADDRESS_FORGOT_PASSWORD&#039;)) {
                $mh-&gt;from(EMAIL_ADDRESS_FORGOT_PASSWORD,  t(&#039;Forgot Password&#039;));
            } else {
                $adminUser = UserInfo::getByID(USER_SUPER_ID);
                if (is_object($adminUser)) {
                    $mh-&gt;from($adminUser-&gt;getUserEmail(),  t(&#039;Forgot Password&#039;));
                } else {
                    $mh-&gt;from(&#039;info@concrete5.org&#039;, t(&#039;Forgot Password&#039;));
                }
            }
            $mh-&gt;load(&#039;forgot_password&#039;);
            @$mh-&gt;sendMail();
            
            $loginData[&#039;success&#039;]=1;
            $loginData[&#039;msg&#039;]=$this-&gt;getPasswordSentMsg();

        } catch(Exception $e) {
            $this-&gt;error-&gt;add($e);
            $loginData[&#039;error&#039;]=$e-&gt;getMessage();
        }
        
        if( $_REQUEST[&#039;format&#039;]==&#039;JSON&#039; ){
            $jsonHelper=Loader::helper(&#039;json&#039;); 
            echo $jsonHelper-&gt;encode($loginData);
            die;
        }        
        
        if($loginData[&#039;success&#039;]==1)
            $this-&gt;redirect(&#039;/login&#039;, &#039;password_sent&#039;);    
    }

}</code></pre></div><p>I&#039;m using punbb 1.3.4 and trying to integrate with Concrete5 cms.&nbsp; Thanks to anyone who can help.</p>]]></description>
			<author><![CDATA[null@example.com (rdains)]]></author>
			<pubDate>Fri, 05 Feb 2010 17:36:12 +0000</pubDate>
			<guid>https://punbb.informer.com/forums/post/133704/#p133704</guid>
		</item>
	</channel>
</rss>
