+ Start a Discussion
MehaMeha 

Session in Site.com

Hi

I have made a website using the free domain of site.com and I have used the default SiteLogin functionality which redirects to my custom visualforce pages on successful login. I am facing the following issues:-

1. As soon as I login, I want my user session to start unless I logout. While I am in my session, I want my respective Customer Portal username to be available as a global variable which can be used across all Visualforce pages. Is this possible? Even if I am able to maintain session for a single user, even that will be enough for me according to my requirements. 

2. I have made multiple Customer Portal users through SiteRegister visualforce page, but no matter which user logs in, current user is the default user and administrator of the force.com account. 
Can you please provide me a code through which after a user logs in, his session is maintained across all visualforce pages till he logs out. While he is logged in, the current user is the user who is logged and not the user of force.com developer account.

 

3. Since my homepage of my site is login page, I don't want users to access my other custom visualforce pages unless they are logged in. The problem is, I am able to successfully log in but all my visualforce pages can be accessed by just appending the URL of my Site.com domain irrespective of the fact that a user is logged in or not. I want my site to check if a customer portal user is logged in before providing access to all the visualforce pages in my website.

 

4. I also have a small doubt. Why isn't the Logout link displayed if I open the page through Site.com and is visible if I open by https://c.ap1.visual.force.com/apex/ChangePassword? 

Pls. help!

Best Answer chosen by Admin (Salesforce Developers) 
MehaMeha

Finally got a solution :)

 

For all those people who want to register and free force.com site and maintain a session for users, I request you to first create a fresh developer.force.com account even if you have one and follow the following steps.

WORDS OF WISDOM

Instead of finding out why the problem is occurring in your existing portal and debugging it, create a new one and copy all your objects through workbench, copy and paste visualforce pages and apex classes to your new force.com account.

STEPS

  1. Customer Portal -> Settings -> Activate the portal, Enable Self Registration, Set Default New User License as Customer Portal Manager Standard, Set Default User Role as User and Default New User Profile as Customer Portal Manager Standard.
  2.  Create an Account and copy its Account ID
  3. Manage Users->Roles->Company size based sample-> Set up Roles->Either Add Role or Assign to existing role the above account created.
  4. Develop->Sites->Search availability and register a domain
  5. Edit the Site Details by providing name and other details. To start with keep the homepage as SiteLogin, Change Password as ChangePassword page and Profile Page as MyProfilePage.
  6. Activate the Site
  7. Click on Site Name and go to Login Settings->Edit->Select the customer portal so created
  8. Now the site is activated and login is enabled
  9. Go to SiteRegisterController page->Edit -> Replace the default PORTAL_ACCOUNT_ID with the above copied Account ID
  10. Go to MyProfileController->Edit->Comment the if condition which throws exception in case of Guest User.
  11. Go to SiteLoginController , change the return value of the login method with ‘return Page.MyProfilePage;’
  12. Go to Develop ->Sites->Click on Site URL
  13. If all the steps are done correctly, the Site will show hyperlinks for NewUser, ForgotPassword and Login on the Header as well as on the Output Panel.
  14. Click on New User, enter the details and on clicking submit you will be redirected to the Login page. Enter your username and password registered. If all the above steps are done correctly, you will be directed to the MyProfilePage which will show you the logged in user credentials alongwith change password button and a logout button.
  15. Copy paste the same URL on another browser or private browsing or incognito window and you will see the message of authentication required.
  16. If you click on Logout, you will be redirected to the login page again.

All Answers

MehaMeha

Finally got a solution :)

 

For all those people who want to register and free force.com site and maintain a session for users, I request you to first create a fresh developer.force.com account even if you have one and follow the following steps.

WORDS OF WISDOM

Instead of finding out why the problem is occurring in your existing portal and debugging it, create a new one and copy all your objects through workbench, copy and paste visualforce pages and apex classes to your new force.com account.

STEPS

  1. Customer Portal -> Settings -> Activate the portal, Enable Self Registration, Set Default New User License as Customer Portal Manager Standard, Set Default User Role as User and Default New User Profile as Customer Portal Manager Standard.
  2.  Create an Account and copy its Account ID
  3. Manage Users->Roles->Company size based sample-> Set up Roles->Either Add Role or Assign to existing role the above account created.
  4. Develop->Sites->Search availability and register a domain
  5. Edit the Site Details by providing name and other details. To start with keep the homepage as SiteLogin, Change Password as ChangePassword page and Profile Page as MyProfilePage.
  6. Activate the Site
  7. Click on Site Name and go to Login Settings->Edit->Select the customer portal so created
  8. Now the site is activated and login is enabled
  9. Go to SiteRegisterController page->Edit -> Replace the default PORTAL_ACCOUNT_ID with the above copied Account ID
  10. Go to MyProfileController->Edit->Comment the if condition which throws exception in case of Guest User.
  11. Go to SiteLoginController , change the return value of the login method with ‘return Page.MyProfilePage;’
  12. Go to Develop ->Sites->Click on Site URL
  13. If all the steps are done correctly, the Site will show hyperlinks for NewUser, ForgotPassword and Login on the Header as well as on the Output Panel.
  14. Click on New User, enter the details and on clicking submit you will be redirected to the Login page. Enter your username and password registered. If all the above steps are done correctly, you will be directed to the MyProfilePage which will show you the logged in user credentials alongwith change password button and a logout button.
  15. Copy paste the same URL on another browser or private browsing or incognito window and you will see the message of authentication required.
  16. If you click on Logout, you will be redirected to the login page again.
This was selected as the best answer
Amritesh SinghAmritesh Singh

Hey,

 

I have similar requirement.But i am not using default pages n also dont want to use.I have my own login page and after login i am doing several action.

Now how can i create my own session management using apex for site.

 

Above process is not for me..so please don't suggest me this 

 

Thnks n waiting for some idea

MehaMeha
Are you using the free force.com site version?? If yes, you cannot do session maintenance for users without purchasing Customer Portal License. These licenses are different from the usual licenses you purchase as it is not included in them. By the above technique, you can see the gist of how session is being maintained.
I haven't tried this, but you can see how session is being maintained if you create a new user for that time being and not otherwise and deduce it in similar fashion in your project as well.

I have done session maintenance using cookies, because I used the free version only. If you want me to share the code with you. Please share your email id.
Amritesh SinghAmritesh Singh

HI Meha,

 

Thanks for ur reply.

 

yes i am using force.com site n  have Custom portal license.

what i am doing in my sites,giving access to my contacts and then after login they can create some records n all.

I have done every thing except session management.

 

U can share ur code here,my email id : amritesh444@gmail.com

 

thanks 

Amol ChAmol Ch
Hi Meha,

I'm also using the free version of force.com site. I'm stuk on how to manage the session. You written that, you done the session maintenance using cookies. Can you please share your code on amolchapte@gmail.com