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
Obaid KhanObaid Khan 

login script not working

Hi friends ... this script not work.. nor displaying logs kindly suggest 

Component :- 

<aura:component controller="frLoginController"
                implements="flexipage:availableForAllPageTypes,lightning:actionOverride,flexipage:availableForAllPageTypes,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:appHostable" >
    <ltng:require styles="/resource/SLDS0110/assets/styles/salesforce-lightning-design-system-ltng.css" />
    <aura:attribute name="recordId" type="String" />   
    
    <aura:registerEvent name="createRecordEvent" type="c:createRecordEvent"/>
    <aura:handler event="force:refreshView" action="{!c.isRefreshed}" /> 

          <div class="slds-form-element">
                    <label class="slds-form-element__label" for="UserName">Username1</label>
                    <div class="slds-form-element__control">
                        <input type="text" id="UserName" class="slds-input" value="meera@gmail.com" />
                    </div>
                </div>
                <div class="slds-form-element">
                    <label class="slds-form-element__label" for="password">Password</label>
                    <div class="slds-form-element__control">
                        <input type="password" id="Password" class="slds-input" value="123" />
                    </div>
                </div>
        <div class="slds-form-element__control">
                    <button class="slds-button slds-button_brand LoginBtn" label="Login" title="Login" iconPosition = "Left" onclick="{!c.loginChk}">Login</button>
                        <div class="slds-form-element slds-m-top_small">
                            <a href="javascript:void(0)" onclick="{!c.createRecord}">Sign Up</a> |
                            <a href="javascript:void(0)">Forgot Password ?</a>
                        </div>
                    </div>

=========================
Controller :- 

  loginChk : function(component, event, helper)
    { 
         console.log('Controller handle click...');
        var Username = component.get("v.Username"); 
        var Password = component.get("v.Password");
        action.setParams({Password : Password});
        action.setParams({Username : Username});
       var action = component.get("c.loginCheck");  
        action.setCallback(this, function(response) {
                                                                        var state = response.getState();
                                                                            if (state === "SUCCESS"){ 
                                                                                system.debug('Success');  
                                                                                                        }else if (state === "ERROR") { 
                                                                                                                            system.debug('Error'); 
                                                                                                        }else{
                                                                                                                 console.log("Unknown Error") ;
                                                                                                                }
                                                                        }); 
                      
                                 $A.enqueueAction(action);
                           },                   
        isRefreshed: function(component, event, helper) {
                            location.reload();
        },

============================ 

Apex

public class frLoginController {

   @AuraEnabled
    public static List < FirstCode__FrRegistration__c > loginCheck(String Password,String Username) {
        //return [SELECT FirstCode__Password__c,FirstCode__Username__c FROM FirstCode__FrRegistration__c where FirstCode__Password__c=:Password && FirstCode__Username__c=:Username];
        return [SELECT FirstCode__Password__c, FirstCode__Username__c FROM FirstCode__FrRegistration__c where FirstCode__Password__c=:Password and FirstCode__Username__c=:Username];
}

}
Raj VakatiRaj Vakati
Can you explan what you are trying to do and this is not the complete code .. 
Obaid KhanObaid Khan
am trying to login ... if username and pswd match the show success else not...from object FirstCode__FrRegistration__c
Naveen KNNaveen KN
As per the code, it always gets the response from the server, may be null or the credentials in a positive scenario.  

are you getting any error on the UI?  Try to set console.log in multiple places of a client-side controller and confirm which line you are seeing an issue. 

For this requirement, I recommend returning 'record exists' or any other attribute from apex code to the client-side controller. based on the attribute value add your condition check for further logic.
  
Naveen
Obaid KhanObaid Khan
but unfortunately ia m not geting any log for this code ... every time ia m runing this and no logs genrate .. suggest please 
Naveen KNNaveen KN
are you saying the below line is not logging message in the console?

console.log('Controller handle click...'); 

then it is a problem with the click handler. in case if you are seeing the above one in the console, keep the console.log in multiple places and see the output. 

Naveen

 
Obaid KhanObaid Khan
yes  u tru .. and tried puting multiple times but no success.. also am having  new registration link on aboce same component  and ia m able to enter new users with that  successfull but still for that too no log generationfor that ..
 
Naveen KNNaveen KN

Obaid, always use lightning base components, replace <input tags with <lightning:input. 

I am able to get the button handler at the controller side. attaching the alert message here. 

 codengine.in

Tested code. 
UI
<aura:component implements="flexipage:availableForAllPageTypes,lightning:actionOverride,flexipage:availableForAllPageTypes,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:appHostable">
    <aura:attribute name="recordId" type="String" />    
    <div class="slds-form-element">
        <label class="slds-form-element__label" for="UserName">Username1</label>
        <div class="slds-form-element__control">
            <lightning:input type="text" id="UserName" class="slds-input" value="meera@gmail.com" />
        </div>
    </div>
    <div class="slds-form-element">
        <label class="slds-form-element__label" for="password">Password</label>
        <div class="slds-form-element__control">
            <lightning:input type="password" id="Password" class="slds-input" value="123" />
        </div>
    </div>
    <div class="slds-form-element__control">
        <lightning:button class="slds-button slds-button_brand LoginBtn" label="Login" title="Login" iconPosition = "Left" onclick="{!c.loginChk}"/>
        <div class="slds-form-element slds-m-top_small">
            <a href="javascript:void(0)" onclick="{!c.createRecord}">Sign Up</a> |
            <a href="javascript:void(0)">Forgot Password ?</a>
        </div>
    </div>
</aura:component>

Controller
({
    loginChk: function(component, event, helper) {
		alert('test from codengine.in - v1');
    },
})

add alerts or console.log at different places and check the output from apex

Naveen
 
Obaid KhanObaid Khan
Hi Naveen, 

Thanks bro.. yes it works .. but now i am having  friend.app and map this page with that app through lightning app builder ...and now when trying to access this using that  it doesnt ...please suggest 
Obaid KhanObaid Khan
on developer console on friend.app click preview it works .. but when trying through app launcher-> all apps -> firend ... no success 
Obaid KhanObaid Khan
Also this ffiend.app is lightning app page created through developer console File-> New->Lightning Application 
Naveen KNNaveen KN
I am not exactly sure of what is the issue. add more details when you report any issue. code or screenshots would help us to help you further. Mark the answer as resolved in case if anything helped you and describe your new issue here or in new thread. 

Naveen
Team codengine.in
Obaid KhanObaid Khan
i am accessing this component through this friend.app  using app launcher .. and its not giving any console log nor this login functionality works ...i am using this lightning  login component using app builder and launching through app launcher as in screen shot ... using this its not giving any logs in developer console nor in browser .... nor this login script works ....
Obaid KhanObaid Khan
and issue is my above login script doesnt work when iam building it using Lightning app builder and using it through ap launcher and also through this  am unable to get logs to get it work