function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Sonali GonnadeSonali Gonnade 

How to maintain User login session throughout the application..

Hi,

 

We have created one sample application using  force.com which having user login page with user authentication. The user should not access any other pages without authentication and after successful login user session should be  maintain throughout the application.

Is there any method or parameter which will help to maintain user session.

Is there something about the automatic page redirection to the login page if users are not authenticated? 
Kindly assist.

 

Thanks in advance.

 

 

Ispita_NavatarIspita_Navatar

 

I will give you my approach of doing things , thoughthis can be done in various ways.

 

I would suggest you implement the session maintenance via custom settings . The moment someone logs in  create an instance of custom setting pair say (Id, email, timestmp, random number).

Now whenever the users logs out you will destroy or delete this instance of record.

But as the user is logged in and tries to navigate to other page you send the timestamp and email (this has to be unique as I used this field for unique identification ), via URL and check on the landing page's load event if the email is present as an instance in custom settings if yes allow navigation , if not ask to log in .

Also if  you want to implement login to expire after say x hours you find the difference between timestamp in custom setting and the current timestamp and if it is greater than x hours , ask the user to login again.

 

Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved.

 

 

Sonali GonnadeSonali Gonnade

Thanks a lot for your quick response.

I will try with this approach and in case of any problem let you know.

 

Thanks

Sonali Gonnade

Sonali GonnadeSonali Gonnade

Hi,

 

I am little bit confused about implementing the custom setting for session maintenance.

It would be great if you give one sample example for the same.

 

Thanks in advance for your help.

 

Sonali

Sonali GonnadeSonali Gonnade

Please provide some steps /sample example for custom setting to maintain session.

It would be really helpful for our application.

 

Thanks

Sonali

AsterAster

Hi, the above post is with regard to the logged in user.

 

What if I want to create a public Force.com site with unauthenticated user access and still maintan the session throughout the user's browsing session?

 

i.e. if the users visits the public site and makes some selection, it shoudl be stored in a session till the user closes the browser/browser tab. Since this user is not logged in, we do not know any information about the user and we'll not be able to track the user after the browser closes.

 

Any thoughts on this?

 

Ady

MehaMeha

Registering a Site domain and Maintaining a Session

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(If you don't know how to do this, share your email id and I will mail you the ppt to transfer objects from one salesforce account to another), 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.
MehaMeha

Registering a Site domain and Maintaining a Session

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.