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
deepu.sandeepdeepu.sandeep 

login check

hi 

    i created a vf page called login page and for the first time the user has to register  after registering the user will get the mail of login credentials and then he logs-in. if the user is logging in first time the page has to redirect to password change page and if user is not logging in first time and the page has to redirect to application page. and for the first time after registering if he clicks sign-up button the firsname,lastname,email fields has to insert in to contact.

now my problem is how can i check dat the user is logging for the first time r not and then redirecting pages as said above.

 

i am sending the code waat i hav written can anyone helpme out

 

 

controller

----------------------------------------

public with sharing class logincntrlr {

public contact con;
public String autopassword{get;set;}
public String firstname{get;set;}
public String lastname{get;set;}
public String email{get;set;}

public static String getautopassword(Integer len)
{
Blob blobKey = crypto.generateAesKey(128);
String key = EncodingUtil.convertToHex(blobKey);
System.debug(key);
return key.substring(0,len);
}

public logincntrlr(){
l= new Logins__c();
}

public boolean emailsentflag{get;set;}

public PageReference sendEmail()
{


String autopassword =logincntrlr.getautopassword(6);
l.autopassword__c=autopassword;
l.First_Name__c=firstname;
l.Last_Name__c=lastname;
l.Email__c=email;




ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.INFO, 'Login Details has been mail to your Registered mail Address .'));

Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();

String [] toAddresses = new String[] {l.Email__c};
email.setToAddresses(toAddresses );
email.setSubject('Username & password');
emailsentflag = true;
email.setHtmlBody('Username: ' + l.Email__c +'<br/> password:'+ l.autopassword__c+
'<br/>To log-in<br/> <a href=https://c.ap1.visual.force.com/apex/loginpage><br/>click here.</a>');
Messaging.sendEmail(new Messaging.SingleEmailMessage[] {email});

insert l;
Contact con=new contact(lastname= l.Last_Name__c,firstname=l.First_Name__c,email=l.Email__c);
Insert con;

l= new Logins__c(Contact__c=con.id);

return null;
}

public Logins__c l{get;set;}
public PageReference save()
{
con=[select id,firstname,lastname,email from contact where id=:con.id];
if(l.Email__c==con.email)
{
pagereference p = new pagereference('/apex/confirmpwdpage');
p.setredirect(true);
}
else
{
pagereference p = new pagereference('/apex/endeavor2012regform2');
p.setredirect(true);
}
insert l;

return null;
}


}

 

 

 

 

vf page---------

-----------------------------------

<apex:page controller="logincntrlr" sidebar="false">
<apex:pageMessages />
<apex:form id="theForm"><br /><br /><br />
<apex:pageBlock >
<apex:pageBlockButtons location="bottom">

<table cellpadding="5" align="center" >
<tr><td><b>Already Registered User</b> Sign-in </td>
<td><b>New User</b> Sign-up</td>
</tr>
<tr>
<td>
<table>
<div id="myDiv" style="color:#FF0000;"></div>
<tr>
<td><b><apex:outputLabel for="User Name">User Name:</apex:outputLabel></b></td>
<td><apex:inputField value="{!l.Name}" id="username"/></td>
</tr>

<tr>
<td><b><apex:outputLabel for="Password">Password:</apex:outputLabel></b></td>
<td><b><apex:inputsecret value="{!l.password__c}" id="password"/></b></td>
</tr>
<tr>
<apex:inputHidden value="{!autopassword}" id="randomfield"/>
</tr>
<td></td>
<tr><td>
<apex:commandButton value="Sign-in" action="{!save}" onclick="return validateFields('{!$Component.username}','{!$Component.password}');" id="loginButton" /></td></tr>

</table>

</td>
<td>
<table cellspacing="0">
<tr>
<td><b><apex:outputLabel for="First Name">First Name</apex:outputLabel></b></td>
<td><b><apex:inputtext value="{!firstname}"/></b></td>
</tr>
<tr>
<td><b><apex:outputLabel for="Last Name">Last Name</apex:outputLabel></b></td>
<td><b><apex:inputtext value="{!lastname}" /></b></td>
</tr>
<tr>
<td><b><apex:outputLabel for="EMail">E-Mail:</apex:outputLabel></b></td>
<td><b><apex:inputtext value="{!email}" id="email"/></b></td>
</tr>

<tr><td><apex:commandButton value="Sign-up" action="{!sendEmail}"/></td></tr>
</table>
</td>
</tr>

</table>

<html>
<head>
<script>
function validateFields(username,password)
{
var usrName=document.getElementById(username).value;
var password=document.getElementById(password).value;

var ni1 = document.getElementById('myDiv');
ni1.innerHTML = '';

if(usrName=='' || password=='')
{
ni1.innerHTML = 'Please fill Username and Password';
return false;
}
else
{
return true;
}

}

</script>
</head>
</html>
<script>
if({!emailsentflag})

alert("email sent sucess");
</script>


</apex:pageBlockButtons>
</apex:pageBlock>
</apex:form>
</apex:page>

 

 

How can i do dat any one suggest me

Thanks in advance

Navatar_DbSupNavatar_DbSup

Hi,

 

You can create a number field in your object where you are storing the username and password and set the default value 0 for this new field. When user login in your application then check first the field status if it is 0 then redirect   to change password page and set this value 1 and if it is 1 the redirect to your application page.

 

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