package lbm.examples; import lbm.jsputil.*; import java.util.*; public class LoginJSPBean extends AbstractJSPBean { public static final String PAGE_CODE = 'login'; private String _voterId; private String _password; private Voter _voter = null; public LoginJSPBean() { } public void setVoterId (String newVoterId) { _voterId = newVoterId; } public String getVoterId() { if (_voterId == null) return ''; else return _voterId; } public void setPassword (String newPassword) { _password = newPassword; } public String getPassword() { if (_password == null) return ''; else return _password; } public Voter getVoter () { return _voter; } protected void beanProcess () throws java.io.IOException { if (_voterId == null || _voterId.equals('')) { addErrorMsg('Voter must be entered'); } if (_password == null || _password.equals('')) { addErrorMsg('Password must be entered'); } if (getState() != ERR) { file://If all the fields are entered, try to login the voter Voter voter = VoteDB.login(_voterId, _password); if (voter == null) { addErrorMsg('Unable to authenticate the Voter. Please try again.'); } else { _voter = voter; if (_voter.getVotedForCandidate() != null) { // if the voter has already voted, send the voter to the last page redirect('confirmation.jsp'); } else { // go to the Vote page redirect('vote.jsp'); } } } } protected void beanFirstPassProcess() throws java.io.IOException { } protected void beanFootERProcess() throws java.io.IOException { } protected String getJSPCode() { return PAGE_CODE; } } |