Kawai Wiki

Compare Revisions

Ignore whitespace Rev 187 → Rev 188

/trunk/src/main/java/org/kawai/action/LoginAction.java
4,75 → 4,97
import org.kawai.model.User;
import org.mentawai.action.BaseLoginAction;
 
/**
* Action class LoginAction.
*
* @author Sergio Oliveira
*
*/
public class LoginAction extends BaseLoginAction {
 
public class LoginAction extends BaseLoginAction {
private final UserDAO userDAO;
public LoginAction(UserDAO userDAO) {
this.userDAO = userDAO;
}
@Override
public String execute() {
if (!isPost()) return ERROR;
String username = input.getString("username");
String password = input.getString("password");
boolean isOk = true;
if (username == null || username.trim().equals("")) {
addError("username", "Please enter an username!");
output.setValue("showForm", "login");
isOk = false;
}
if (password == null || password.trim().equals("")) {
addError("password", "Please enter a password!");
output.setValue("showForm", "login");
isOk = false;
}
if (!isOk) return ERROR;
User u = userDAO.findByUsername(username);
if (u == null) {
addError("username", "Username unknown!");
output.setValue("showForm", "login");
return ERROR;
}
if (u.getPassword().equalsIgnoreCase(password)) {
setSessionObj(u);
setSessionGroups(u.getGroup());
String name = input.getString("name");
if (name != null) output.setValue("name", name);
String lang = input.getString("lang");
if (lang != null) output.setValue("lang", lang);
return SUCCESS;
} else {
addError("password", "Incorrect password!");
output.setValue("showForm", "login");
return ERROR;
}
}
}
/**
* Attribute userDAO of LoginAction.
*/
private final UserDAO userDAO;
 
/**
* Parametric constructor.
* @param userDAO UserDAO
*/
public LoginAction(UserDAO userDAO) {
this.userDAO = userDAO;
}
 
/**
* {@inheritDoc}
*/
@Override
public String execute() {
 
if (!isPost()) {
return ERROR;
}
 
String username = input.getString("username");
 
String password = input.getString("password");
 
boolean isOk = true;
 
if (username == null || username.trim().equals("")) {
 
addError("username", "Please enter an username!");
output.setValue("showForm", "login");
 
isOk = false;
}
 
if (password == null || password.trim().equals("")) {
 
addError("password", "Please enter a password!");
output.setValue("showForm", "login");
 
isOk = false;
}
 
if (!isOk) {
return ERROR;
}
 
User u = userDAO.findByUsername(username);
 
if (u == null) {
 
addError("username", "Username unknown!");
output.setValue("showForm", "login");
 
return ERROR;
}
 
if (u.getPassword().equalsIgnoreCase(password)) {
 
setSessionObj(u);
setSessionGroups(u.getGroup());
 
String name = input.getString("name");
if (name != null) {
output.setValue("name", name);
}
 
String lang = input.getString("lang");
if (lang != null) {
output.setValue("lang", lang);
}
 
return SUCCESS;
 
} else {
 
addError("password", "Incorrect password!");
output.setValue("showForm", "login");
 
return ERROR;
}
}
 
}