package action;
import bo.Admin;
import dao.AdminDao;
import daoI.IAdminDao;
import java.security.MessageDigest;
import net.sourceforge.stripes.action.ForwardResolution;
import net.sourceforge.stripes.action.Resolution;
public class AdminActionBean extends BaseActionBean {
private Admin admin;
private String parolaVeche;
public Resolution logout() {
getContext().getRequest().getSession(true).setAttribute("admin", 0);
return new ForwardResolution("/WEB-INF/jsp/home.jsp");
}
public Resolution datePersonale() {
IAdminDao adminDao = new AdminDao();
int idAdmin = Integer.parseInt(getContext().getRequest().getSession(true).getAttribute("admin").toString());
Admin adminC = adminDao.getAdminByID(idAdmin);
parolaVeche = adminC.getParola();
setAdmin(adminC);
return new ForwardResolution("/WEB-INF/jsp/adminDatePersonale.jsp");
}
public Resolution submitDatePersonale() {
IAdminDao adminDao = new AdminDao();
Admin adminC = getAdmin();
if (adminC.getParola().equals(getParolaVeche())) {
adminDao.saveOrUpdate(adminC);
} else {
byte[] parolaB = adminC.getParola().getBytes();
try {
MessageDigest algorithm = MessageDigest.getInstance("MD5");
algorithm.reset();
algorithm.update(parolaB);
byte messageDigest[] = algorithm.digest();
StringBuffer hexString = new StringBuffer();
for (int i = 0; i < messageDigest.length; i++) {
hexString.append(Integer.toHexString(0xFF & messageDigest[i]));
}
adminC.setParola(hexString + "");
adminDao.saveOrUpdate(adminC);
} catch (Exception e) {
}
}
return new ForwardResolution("/WEB-INF/jsp/adminDatePersonale.jsp");
}
/**
* @return the admin
*/
public Admin getAdmin() {
return admin;
}
/**
* @param admin the admin to set
*/
public void setAdmin(Admin admin) {
this.admin = admin;
}
/**
* @return the parolaVeche
*/
public String getParolaVeche() {
return parolaVeche;
}
/**
* @param parolaVeche the parolaVeche to set
*/
public void setParolaVeche(String parolaVeche) {
this.parolaVeche = parolaVeche;
}
}