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
kutts18kutts18 

Authentication Problem

My site home page has a button, onclick of which it should goto my custom login screen.

The problem is when i click the button, instead of going to my custom login page, it goes

to native error page saying.

 

Authorization Required 

ou must first log in or register before accessing this page.
If you have forgotten your password, click Forgot Password to reset it. 

 

Below is the code i am using

 

VF

---

 

<apex:page showHeader="false" controller="SanjuCntrl">

 <apex:form >
                <apex:commandButton action="{!loginPage}" value="Enter" id="theButton" image="{!$Resource.mylogo}"/>
            </apex:form>

</apex:page>

 

 

 

Controller

-----------

 

public class SanjuCntrl{

public PageReference loginPage() {
PageReference pr = Page.SanjuLogin;
pr.setredirect(true);
return pr;
}

}

 

 

 I want to authorise user only in the secon page (ie My custom login screen).

 

Thanks

Sanju

Best Answer chosen by Admin (Salesforce Developers) 
aalbertaalbert

1. Is the page titled SanjuLogin enabled as part of the Site?  If it is not enabled as part of the Site, it requires authentication to access it.

 

2. If the username and password passed into the Site.Login method are correct for a Portal User associated to the Portal which is associated to the Site, then the user will be redirected to the 3rd parameter, startURL, passed into the site.login call. So set the 'startURL' parameter to your custom login page.

All Answers

kutts18kutts18

I havent got the solution for above problem, but 

as of now i have made the my home VF page to custom login page.

 

My custom loginpage with controller SiteLoginController.

In the SiteLoginController the authentication method is gven as

 

public PageReference login() {
String startUrl = System.currentPageReference().getParameters().get('startURL');
return Site.login(username, password, startUrl);
}

 

My question would be

 

1. From this method how will i know whether User is a valid user or not?

2.If valid user how would i re-direct user to the custom welcome pag?

 

Thanks in advance.

 

 

aalbertaalbert

1. Is the page titled SanjuLogin enabled as part of the Site?  If it is not enabled as part of the Site, it requires authentication to access it.

 

2. If the username and password passed into the Site.Login method are correct for a Portal User associated to the Portal which is associated to the Site, then the user will be redirected to the 3rd parameter, startURL, passed into the site.login call. So set the 'startURL' parameter to your custom login page.

This was selected as the best answer
kutts18kutts18

Thanks for that information.

 

> Now i have set my Active Site Home Page to SanjuLogin.So when you type the site url, SanjuLoginpage is displayed.

 

> The problem is, even after giving the valid user name (my user id & password), even after being a system

    administrator, it still shows me the error message. 

 

Error:  Your login attempt has failed. Make sure the username and password are correct.

 

 

    Does it mean that force.com id and portal user id are different?

    If it is so, how would i add myself as a portal user?

 

 

 

 What i want to do exactly is

 

1. User will type the site url

2. Custom Login page (SanjuLogin) is displayed

3. User provides his userid & password and submits.

4. If userid valid, then go to custom menu (sanju) page

    else display the error message in login page itself.

 

 

 

 

Here is my current code

 

 SanjuLogin VF Page

 

<apex:page controller="SiteLoginController">

<apex:pageMessages id="error"/>

<apex:panelGrid columns="2" style="margin-top:1em;">

<apex:form id="loginForm" forceSSL="true">

<apex:outputLabel value="{!$Label.site.username}" for="username"/>

<apex:inputText id="username" value="{!username}"/>

<apex:outputLabel value="{!$Label.site.password}" for="password"/>

<apex:inputSecret id="password" value="{!password}"/>

<apex:outputText value=""/>

<apex:commandButton action="{!login}" value="{!$Label.site.login_button}" id="loginButton"/>

</apex:form>

</apex:panelGrid>

</apex:page>

  SiteLoginController apex class

 

/**
* An apex page controller that exposes the site login functionality
*/
public class SiteLoginController {
public String username {get; set;}
public String password {get; set;}

public PageReference login() {
String startUrl = '/apex/sanju';
return Site.login(username, password, startUrl);
}

public SiteLoginController () {}

public static testMethod void testSiteLoginController () {
// Instantiate a new controller with all parameters in the page
SiteLoginController controller = new SiteLoginController ();
controller.username = 'test@salesforce.com';
controller.password = '123456';

System.assertEquals(controller.login(),null);
}
}

 

<apex:page showHeader="false" controller="SanjuCntrl" title="SANJU'S SFA 
APPLICATION">

<div align="center">
<center>
<table border="0" width="979" height="76" bgcolor="#000000">
<tr>
<td width="979" height="76">
<p align="center"><b><font size="7" color="#00FF00">SANJU'S SFA
APPLICATION</font></b> </p>
</td>
</tr>
</table>
</center>
</div>
<div align="center">
<center>
<table border="0" width="979" height="439" bgcolor="#000000">
<tr>
<td width="182" height="439"></td>
<td width="781" height="439">
<p align="center">
<!-- Menu yet to be created -->
</p>
</td>
</tr>
</table>
</center>
</div>

</apex:page>

 

aalbertaalbert

Lets first verify that you are logging in as a Portal User.

Once you have enabled a Customer Portal, create a Contact and then click on the "Enable Customer Portal User" button on the Contact Detail page layout. It will take you to the User creation page and complete that form (probably makes sense to set the email address to your email so you get the 'reset password'email notifications). Reset the password, then try your Force.com Site Login page again. 

 

 

kutts18kutts18

It worked! Thank you so much. I been trying it for two days now.

Now i know you have add a user in Contacts, and then enable it for portal

inorder to access our site.

 

The next problem is for this portal user, custom objects are not getting displayed?

 

For eg. i have a custom object BlogPost__c. I need to display the data in my

custom page sanju.

 

aalbertaalbert

Each custom object has a property to enable it for use within customer portal. Make sure that is checked. Go to the custom object definition (Setup | Create | Objects) and click edit next to the specific object(s) you want to enable for the portal. 

 

Next, each portal user is associated a portal profile. Make sure that profile has the proper CRUD permissions to the objects you need. Go to Setup | Administration Setup | Manage Users | Profiles to see the profiles. 

 

kutts18kutts18

It all worked out fine.

Thanks for all your support.

 

One more doubt i have.

 

I have a link in my VF page 

<a class="title" href="/apex/newBlogEdit?id={!post.Id}" target="_top">
{!post.Name}</a>
This link takes the user to edit page.

But when the link is clicked it shows the message

 

 http://sanju-developer-edition.na6.force.com/sanju/ is under construction
 Stay tuned. Please email us if you need to get in touch.

 

 

I have observed that, when page transition is done through

controller using PageReference, the page transits correctly

but if we call the page directly without using controller

method, then native page is getting displayed saying

"under construction". 

 

What will the possible cause?

BulentBulent
You need to add {!$Site.Prefix}/ at the beginning of your url. Your site has a path /sanju/ but you are not using the path in your link