Problems, need help? Have a tip or advice? Post it here.
7 posts Page 1 of 1
I am having a site which has a front end design in the root folder and a backend in another folder (this backend is different from couch folder).

This backend, i am referring to, is accessible after login only.

Let us consider the following folder structure:
Project (folder)
- assets (folder)
- backend (folder)
- couch (folder)
- index.php (site frontend)

Now the first issue i face is, there is an index.php in the backend folder. this file has the code:
Code: Select all
<cms:if k_logged_out>
   <cms:redirect "<cms:login_link />" />
</cms:if>


When I logout it takes me to the login page. but if i try to access the url
localhost/Project/backend/index.php

I get the message "Page not found", while this page exists in the couch panel. By my understanding it should actually be redirected to the login page, but does not.

The second issue is that, when a user logs in, there are two conditions to be checked, viz:
1. If the user profile is filled completely it should login and redirect to the backend/index.php page
2. If the user profile is NOT completely filled, it should login and redirect to the users/profile.php page for that user.
Where can I place these conditions in the users/login.php for them to work?

The third issue is that, when go to the logout link, in the navbar of the backend/index.php, on mouse over it shows me the logout link but when clicked once it doesnot logout, while if i click the second time it logs out. This i suppose should happen the first time itself

Looking forward to all help and expert opinions possible.

Regards,
GXCPL (CTR Support)
Image
where innovation meets technology
.
The second issue is that, when a user logs in, there are two conditions to be checked, viz:
1. If the user profile is filled completely it should login and redirect to the backend/index.php page
2. If the user profile is NOT completely filled, it should login and redirect to the users/profile.php page for that user.
Where can I place these conditions in the users/login.php for them to work?


The logic to verify 'completeness' can be placed after 'process_login' tag. See the Midware » process_login (Tips) with codesample.
The logic to verify 'completeness' can be placed after 'process_login' tag. See the Midware » process_login (Tips) with codesample.


@trendoman,
The very code sample solved my issue #2. Ihave seen this code sample earlier too, and have it bookmarked, but was all confused. Thanks for the help pointing me there.

Just another small query my current code is:
Code: Select all
<cms:process_login redirect="0"/>
                                        <cms:if k_success>
                                            <cms:php>
                                            global $FUNCS;
                                            $FUNCS->set_userinfo_in_context();
                                            </cms:php>

                                            <cms:pages masterpage=k_user_template id=k_user_id limit='1'>
                                                <cms:if (user_fullname eq '') && (user_mobile eq '') && (user_nature_of_business eq '-') && (user_location eq '') && (user_pincode eq '')>
                                                    <cms:redirect url="profile.php?<cms:pages masterpage=k_user_template id=k_user_id>user_fullname=<cms:show user_fullname />&user_mobile=<cms:show user_mobile />&user_pincode=<cms:show user_pincode /></cms:pages>" />
                                                <cms:else />
                                                    <cms:redirect url="<cms:link 'app/index.php' />" />
                                                </cms:if>
                                            </cms:pages>
                                        </cms:if>


I feel this part is not exactly solving the issue at hand so how can I rephrase it, so that if any one of the field is missing, then it redirects to the profile.php else to index.php. I tried OR (||) but even if all fields are filled it ends up on profile.php. Unable to understand why!
Code: Select all
<cms:if (user_fullname eq '') && (user_mobile eq '') && (user_nature_of_business eq '-') && (user_location eq '') && (user_pincode eq '')>


Any take on #1 and #3? I am a new joinee here at GXCPL and am learning things from Aashish Sir and Priya Ma'am, but due to their non availability I took to the forum. And it indeed helped.

Thanks once again!

Regards,
GXCPL (CTR Support)
Image
where innovation meets technology
Please then introduce yourself :) Do you have a GitHub profile?

genxcoders wrote: I am a new joinee here at GXCPL and am learning things from Aashish Sir and Priya Ma'am, but due to their non availability I took to the forum. And it indeed helped.

Thanks once again!

Regards,
GXCPL (CTR Support)
genxcoders wrote: Just another small query my current code is:


I suggest you validate the correctness of the passed parameters to the <cms:pages>, especially that "k_user_id" var. Having enabled "extended-users" addon, the values are all messed up.

In the posted example the method $FUNCS->set_userinfo_in_context(); sets the "k_user_id" as a shortcut to $AUTH->user->id (functions.php, L1486), that is the ID which users have in database.

"Extended" addon sets "k_extended_user_id" as $AUTH->user->id, and replaces (imho, very stupidly) "k_user_id" with $pg_id, i.e. the associated page id (extended/extended-users.php L183). (Imho, enabling the addon one should've explicitly do the other thing around → by using "k_extended_user_id" to access the bound page data; instead, in the end, we have to read PHP source to know the difference).

So, the code stops working normally for "extended" use-case unless you do the same replacement via additionally calling the method set_custom_fields_in_context():
Code: Select all
<cms:php>
   global $FUNCS, $KUSER;
   $FUNCS->set_userinfo_in_context();
   $KUSER->set_custom_fields_in_context();
</cms:php>


I will add this info to my documentation page.

Hopefully this mod will set your id parameter of <cms:pages> to the correct value and the page will be found, fields will be checked correctly. Make sure to use <cms:dump> (or param return_sql='1' of <cms:pages>) to validate that indeed the page requested is the one that is expected.

Sometimes fields may have a space in the content, so the validation ="" will fail. Try with a loose comparison like this –
Code: Select all
<cms:if user_fullname && user_mobile && user_nature_of_business ne '-' && user_location && user_pincode>
// fully inputted
<cms:else_if "<cms:not user_fullname />" />
// full name is missing
<cms:else_if "<cms:not user_mobile />" />
// mobile is missing
... etc
<cms:else />
// something is missing
</cms:if>
The issue #1 must be investigated further. If you are new to CouchCMS, then it is time to learn how it wants you to spend a lot of time debugging the code especially where redirects and form submissions happen. The mentioned Page not found error is thrown at least 15 times in CouchCMS on various occasions. You would not believe this nonsense unless you search that message in your codebase editor.

Mind that tag <cms:login_link/> may even output javascript:void(0) instead of a link (although you are on the safe side here being logged out). See Midware » login_link doc. Anyways, maybe a simple variable "k_login_link" will be better? Try to not redirect before making sure the tag outputs correct link and nothing else is messing with the request.

When in doubt - cover your code with tests, e.g.:
Code: Select all
<cms:if k_logged_out>
   <cms:log "current login link: =<cms:login_link />=" />
   <cms:redirect "<cms:login_link />" />
</cms:if>


The issue #3 is impossible to think of without source code. Since you did not post any code for that issue, I suspect you are 100% sure it is quite ok. In such case I recommend to replace your mouse as the LMB is obviously failing you. :)
trendoman wrote: Please then introduce yourself :) Do you have a GitHub profile?


Hi I am Arjun. I am here at GXCPL as a CTR Support Representative (Connect to Resolve).
We are allowed to use company logins for company projects and working. Hence on GitHub I can connect through "genxcoders".

Regards,
GXCPL (CTR Support)
Image
where innovation meets technology
7 posts Page 1 of 1