}
public WOComponent login() {
EOEditingContext editingContext;
Session session = (Session)session();
editingContext = session.defaultEditingContext();
if (!validated && false) {// captcha disabled for now
errorMessage="The captcha is wrong!";
return null;
}
if (username==null || password==null) {
errorMessage="Please specify both fields!";
return null;
}
People userObject = People.clazz.userWithUsernamePassword(editingContext, username, password);
if(userObject == null) {
errorMessage="Sorry login incorrect!";
return null;
}
if (!userObject.isActive()) {
errorMessage="Sorry your account is inactive!";
return null;
}
session.setUser(userObject);
boolean isAdmin = userObject.isAdmin();
D2W.factory().setWebAssistantEnabled(isAdmin);
String encryptedIDPrimaryKey = ERXCrypto.crypterForAlgorithm(ERXCrypto.BLOWFISH).encrypt(userObject.primaryKey());
WOCookie loginCookie=new WOCookie("BTL", rememberPassword ? encryptedIDPrimaryKey : "-");
loginCookie.setExpires(NSTimestamp.DistantFuture);