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
Rani_RRani_R 

Simple Login Page - Please help.

Hi,

 

I am very new here, i am doing a POC to show our data inside the salesforce website.

 

I will list out what all i have done.

 

1. I created a new app.

2. I created a new tab and a visual source page.

 

Below is the code for my visual source page

 

<apex:page standardController="Account" controller="LoginController">
<apex:pageBlock title="Hello {!$User.FirstName}! Please login">
    <apex:Form >
        <table>
            <tr>
                <td>Username:</td>
                <td><apex:inputField id="userName" value="{!userName}"/></td>                
            </tr>
            <tr>
                <td>Password:</td>
                <td><apex:inputfield id="passWord" value="{!password}"/></td>                
            </tr>
            <tr>
                <td></td>
                <td align="right"><apex:commandButton value="Login" action="{!loginFn}"/></td>
            </tr>
        </table>    
    </apex:Form>
</apex:pageBlock>
</apex:page>

 

 

This is my custom controller


public class LoginController {
    public String userName;
    public String password;
    public LoginController () {
        
    }    
    public void loginFn() {
        
        Http http       = new Http();
        HttpRequest req = new HttpRequest();

        try {        
            req.setEndpoint('http://documentcollaboration.elementfx.com/phpscript/login.php?username='+userName+' &password='+password);
            req.setMethod('POST');
            
            HttpResponse res = http.send(req);
            
        } catch (Exception e) {           
        }
    }    
}

 

When i click on the Login Button, the LoginFn will be called(atleast thats what i hope so)...

 

http://documentcollaboration.elementfx.com/phpscript/login.php?username=Dinesh&password=Dinesh

 

The above link will return an XML like below

 

 <Output><Status>Success</Status><user><username>Dinesh</username><displayname>Dinesh</displayname><email>Dinesh@Dinesh.com</email></user></Output>

Based on the XML i want to display contents accordingly in my visualpage... if the status is success then i want to redirect to an another page, else i want to display an error message.

 

Please help me on how to do this... what should i do.. also is there any error in my apex code or visualforce page?

 

Thanks and Regards,

Rani

bob_buzzardbob_buzzard

You can't use inputfield to capture the user id and password, as these need to be backed by sobject fields rather than controller properties.  You could use input text.  You'll also need public getters/setters for them.

 

E.g.

 

Controller

 

 

  public String userName {get; set;}
  public String password {get; set;}

 

page:

 

 

<tr>
   <td>Username:</td>
   <td><apex:inputText id="userName" value="{!userName}"/></td>                
</tr>
<tr>
   <td>Password:</td>
   <td><apex:inputText id="passWord" value="{!password}"/></td>                
</tr>

 

 

 

 

 

 

Rani_RRani_R

Hi Bob,

 

Thanks, i changed my visualforce page and class.

 

But please help me in my other question,

 

From the HTTP response, how do i manipulate my pages?

 

Should i create two different pages? for successfull login and unsuccessfull login and redirect to them? if so how can i redirect actually from the apex code?

 

Thanks,

Rani

mohimohi

if you are getting xml than you may parse xml using xml dom,than check value of  status as success or failure and may redirect

bob_buzzardbob_buzzard

You can redirect to another page from an apex controller using page references.  Here's an example that assumes you've created a visualforce page called LoginSuccess:

 

 

public PageReference sendToSuccess()
{
   PageReference pr=Page.LoginSuccess;
   pr.setRedirect(true);

   return pr;
}

 

 

 

 

Rani_RRani_R

Thanks bob

 

Say if i have a grid in my page. I want to call a php and fill the grid with the values that i get.

 

In my page i will have a button and some other data and also a grid at the bottom. In that button's action i will call a function in my apex class.

 

From the apex class, i will call the php.... and i will get the result in the http response.. But now how can i fill the grid with the http response? i can redirect to a new page, but how can i fill the grid with the response? the rest of the page should be the same, only the grid should change.

 

how can i do it. Thanks for your help.

 

Rani.

bob_buzzardbob_buzzard

In case anyone stumbles across this thread, this would be achieve in the following way:

 

(1) Back the grid by an apex list of values

(2) Create an apex:commandbutton with an action of the controller method that calls out to the PHP and rebuilds the list of values for the grid

(3) Specify a rerender attribute on the commandbutton that contains the id of the grid - this will cause the grid to be redrawn once the action method completes.