/*
Copyright (C) 2001 Kevin E. Gilpin (kevin.gilpin@alum.mit.edu)
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package dovetail.example.survey.beans;
import dovetail.example.survey.site.auth.RegisterForm;
import dovetail.example.survey.schema.SurveySchema;
import agonism.dovetail.db.WrapParameterSource;
import agonism.dovetail.site.Form;
import agonism.dovetail.site.FormElement;
import agonism.dovetail.site.NewRecord;
import agonism.dovetail.site.RequestError;
import agonism.dovetail.site.IAction;
import agonism.util.Log;
import agonism.util.Utils;
import org.log4j.Category;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Date;
public class Register
implements IAction
{
private static final Category C = Category.getInstance(Register.class.getName());
public boolean process(Form f)
{
RegisterForm form = (RegisterForm)f;
String userID = (String)form.getUserIDElement().getValue();
String confirmPassword = (String)form.getConfirmPasswordElement().getValue();
String password = (String)form.getPasswordElement().getValue();
userID = Utils.nullify(userID);
password = Utils.nullify(password);
confirmPassword = Utils.nullify(confirmPassword);
RequestError error = null;
String errorMsg = null;
if ( userID == null || password == null )
{
error = new RequestError(form, "You must submit a userID and a password");
}
else if ( !((Boolean)form.getReadTermsElement().getValue()).booleanValue() )
{
error = new RequestError(form, form.getReadTermsElement(), "Please read and accept the Terms of Use");
}
else if ( !((Boolean)form.getReadPrivacyElement().getValue()).booleanValue() )
{
error = new RequestError(form, form.getReadPrivacyElement(), "Please read and accept the Privacy Policy");
}
else if ( !password.equals(confirmPassword) )
{
error = new RequestError(form, new FormElement[]{ form.getPasswordElement(), form.getConfirmPasswordElement() }, "Password and Confirmation Password don't match");
}
if ( error != null )
{
form.getContext().reportError(error);
return false;
}
else
{
WrapParameterSource source = new WrapParameterSource(form.getContext().getParameterSource());
source.put(SurveySchema.instance().getRegisteredUserTable().getRegisteredDateCol(), new Date());
NewRecord nr = new NewRecord(SurveySchema.instance().getRegisteredUserTable());
// Any errors in the record creation will be reported by the NewRecord object
if ( nr.create(form.getPage().getConnection(), form, source) )
{
form.getContext().setSessionValue("userID", source.getValue(SurveySchema.instance().getRegisteredUserTable().getUserIDCol()));
return true;
}
else
{
return false;
}
}
}
}