Skip to main content
I have to create the login page with User name and pass word in salesforce lightning (Like Naukri home page).

I have created  the fields, but i am not able to do in controller for login button.

<div class="slds Naukri">

    <ui:inputtext aura:id="User" label=" User Name " class="" value="" maxlength="30" placeholder="Enter Email Id" required="false" size="20"/> <br/>

        <ui:inputSecret aura:id="pwd" label=" Password " class="" value="" maxlength="10" placeholder="Enter upto 10 character" required="false" size="20"/> <br/>

            <div class="slds-float--right slds-button_brand">

                <div class="slds-grid buttons">   

            <lightning:button variant="brand" label="Login" onclick="{!c.handleLoginButtomClick}" />

        </div>

    </div>

 </div>

Can you please help me in this.

Regards,

Sarma
7 Antworten
  1. 22. Okt. 2019, 10:17
    Hi Sarma,

    Please refer below code to create login page:

    Aura component:-

     

    <aura:component implements="flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId" access="global" controller="LoginPageClass">

           <aura:attribute name = "Empiduser" type = "String"/>

         <aura:attribute name = "Empidpwd" type = "String"/>

        <div class="slds-form-element slds-align_absolute-center slds-m-top_x-large">

            <div class="slds-col slds-size_6-of-12">

                <form>

                    <div class="slds-align_absolute-center slds-m-top_small slds-text-heading_large">

                        <span>Login Page</span>

                    </div>

                    

                    <div class="slds-form-element__control">

                        <lightning:input label="User Name" name="abc" id="username" placeholder="User Name" value="{!v.Empiduser}" />

                    </div>

                    

                    <div class="slds-form-element__control">

                        <lightning:input label="Password" type="password" name="abc" id="password"  placeholder="Password" value="{!v.Empidpwd}" />

                    </div>

                    <div class="slds-align_absolute-center" style="height:4rem">

                        <lightning:button variant="success" label="Login" onclick="{!c.loginPage}"/>

                    </div>

                </form>

            </div>

        </div>

    </aura:component>

    Controller class:-

     

    public class LoginPageClass {

        @auraEnabled

        public static String getcontact(String username,String userpassw ){

            List<Contact> lcont=new List<Contact>([select Username__c,Password__c from Contact where Username__c=:username  Limit 1]);

            if(lcont.size()==0){

                return 'User dose not exit!';

            }

            else{

                if(lcont[0].Password__c==userpassw ){

                    return 'Login successfully';

                }

                else{

                    return 'Invalid Password';

                }  

            }

        }

    }

    Handler js file:-

     

    ({

        loginPage : function(component, event, helper) {

            var action = component.get("c.getcontact");

            

            var userid = component.get("v.Empiduser"); 

            var pass= component.get("v.Empidpwd");

            

            if($A.util.isEmpty(userid ) || $A.util.isUndefined(userid )){

                alert('Please Enter User Name!');

                return;

            }   

             if($A.util.isEmpty(pass) || $A.util.isUndefined(pass)){

                alert('Please Enter Password!');

                return;

            } 

              action.setParams({

                  username:userid ,

                  userpassw:pass

            });

              action.setCallback(this,function(a){

                  var rtnValue = a.getReturnValue();

                  alert(rtnValue);

                  console.log('The field list is :'+JSON.stringify(a.getReturnValue()));

              });

             $A.enqueueAction(action);

             component.set("v.userid ",'');

             component.set("v.pass",'');

        }

    })

    I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.

    Thanks and Regards,

    Deepali Kulshrestha

    www.kdeepali.com