Forum for discussing general topics related to Couch.
5 posts Page 1 of 1
Hi!

I would like to check certain variables once someone logs in. Like I want him to verify his personal data, I would set the corresponding variable to 0. When he logs in afterwards he would then be redirected to the correpsonding form where he would have to check if everything is up to date or not. My current solution does what I want, but it checks every time, meaning with every visit on any page, the status of those variables. Is there any way to include this within cms:process_login so that it'll happen only when he actually logs in?

Code: Select all
<cms:if k_logged_in >
               <cms:if k_user_access_level lt '10'>
                  <cms:pages masterpage="users/index.php" id=k_user_id>
                     <cms:set user_verified_data=user_verify_data 'global'/>
                     <cms:set user_verified_training=user_verify_training 'global'/>
                     <cms:set user_verified_settings=user_verify_privacy 'global'/>
                     <cms:set user_verified_etiquette=user_etiquette 'global'/>
                  </cms:pages>
               
                  <cms:if user_verified_data != '1'>
                     <cms:if k_matched_route='edit_view_info'>
                     <cms:else/>
                        <cms:redirect url="<cms:route_link masterpage='users/index.php' 'edit_view_info' rt_slash='' />" />
                     </cms:if>
                  <cms:else_if user_verified_training != '1' />
                     <cms:if k_matched_route='edit_view_training'>
                     <cms:else/>
                        <cms:redirect url="<cms:route_link masterpage='users/index.php' 'edit_view_training' rt_slash='' />" />
                     </cms:if>
                  <cms:else_if user_verified_settings != '1' />
                     <cms:if k_matched_route='edit_view_account'>
                     <cms:else/>
                        <cms:redirect url="<cms:route_link masterpage='users/index.php' 'edit_view_account' rt_slash='' />" />
                     </cms:if>
                  <cms:else_if user_verified_etiquette != '1' />
                     <cms:if k_template_name='users/confirm-etiquette.php'>
                     <cms:else/>
                        <cms:redirect url="<cms:link masterpage='users/confirm-etiquette.php' />" />
                     </cms:if>
                  </cms:if>
               </cms:if>
               
               <ul id="loginopt">
                  <li class="sep-li">Hello <b><cms:show k_user_title/></b></li>
                  <li><a href="/users/profile/" class="sep-li">Profile</a></li>
                  <cms:if k_user_access_level ge '7' ><li><a href=".../couch/" class="sep-li">Couch</a></li></cms:if>
                  <li><a href="<cms:logout_link />">Logout</a></li>
               </ul>
               <cms:else />
       
               <!-- show the login form -->
               <cms:form method='post' anchor='0'>
                  <cms:if k_success >
                     <cms:process_login redirect="1"/>
                  </cms:if>
               <ul id="loginform">
                  <h2>Login</h2>
                  <li><cms:input type='text' name='k_user_name' placeholder="Benutzer"/></li>
                  <li><cms:input type='password' name='k_user_pwd' placeholder="Passwort"/></li>
                  <li><input type="submit" value="Login" name="submit" class="small fit"/></li>
                  <cms:if k_error >
                     <li><font color='#be2226'><cms:show k_error /></font></li>
                     <cms:redirect url='.../users/login/' />
                  </cms:if>
               </ul>
               </cms:form>
               </cms:if>
Hi,

I think the right place for the additional checks would be right after you use cms:process_login to effect the login -
Code: Select all
<cms:if k_success >
    <cms:process_login redirect="1"/>
</cms:if>

However, in the code above, since the 'redirect' is set to '1', the control will never arrive at any next statement but will redirect from within the tag.

So, we set the redirect to '0' as shown below and now we can put additional statements there.
One more thing would be required. Please notice that we are calling upon PHP to set the info about the new login into context (this would have happened automatically had the page refreshed)
Code: Select all
<cms:if k_success >
    <cms:process_login redirect="0"/>
   
    <cms:if k_success >
        <cms:php>
            global $FUNCS;
            $FUNCS->set_userinfo_in_context();
        </cms:php>
       
        ... move your additional logic here. Make sure to redirect eventually ..
        <cms:if k_logged_in >
            ...
        </cms:if>

    </cms:if>
</cms:if>

Does this help?
I fear not - since it appears to run everytime as well, not only during the actual process of logging in. On the other hand it might have been a bad idea anyhow - at least in terms of my logic (there are different variables I want to check. Having the check only while logging in might serve only one of those... or I'll put something in between - just got ideas ;) )

Anyhow, in the meanwhile I discovered something else, but I'm reluctant to open another thread for it. For some reason the time k_page_modification_date throws out is an hour short. I have set the time zone from the beginning as +1 (germany). Even "localizing" doesn't help to correct the time. Any ideas?
I fear not - since it appears to run everytime as well, not only during the actual process of logging in.
Not sure why it would run every time - if your code is within the form's success condition, it will run only when the form is successfully submitted.

Please double-check the placement of your code.
If necessary PM me the full code.

Thanks.
Sometimes it takes a couple of years to understand things ;)... I had handled it in another way, but now I was facing the same problem again.

The little bit I'm missing is how to properly redirect to the page I initially wanted to access. Some parts of the site are restricted, so one gets redirected to the login page, with a URL like this ".../users/login/?redirect=%2Fresources%2Fconferences%2F". I put another <process_login/> into the code, which does the trick, but I'm not sure if that's how it should be ;)

Code: Select all
<cms:process_login redirect="0"/>

<cms:if k_success >

   <cms:php>
      global $FUNCS;
      $FUNCS->set_userinfo_in_context();
   </cms:php>

   <cms:db_persist
      _masterpage=k_user_template
      _mode='edit'
      _page_id=k_user_id

      user_last_login="<cms:date format='Y-m-d H:i:s'/>"
   />
   
   <cms:process_login/>
   
   <cms:if k_logged_in >
   </cms:if>

</cms:if>


And, if I still may ask, why did you put "<cms:if k_logged_in>" within the success condition? I'm just curious here :D.
5 posts Page 1 of 1

Who is online

In total there are 3 users online :: 0 registered, 0 hidden and 3 guests
(based on users active over the past 5 minutes)

Users browsing this forum: No registered users and 3 guests

cron