use of net.jforum.exceptions.DatabaseException in project jforum2 by rafaelsteil.
the class ControllerUtils method checkAutoLogin.
/**
* Checks user credentials / automatic login.
*
* @param userSession The UserSession instance associated to the user's session
* @return <code>true</code> if auto login was enabled and the user was sucessfuly
* logged in.
* @throws DatabaseException
*/
protected boolean checkAutoLogin(UserSession userSession) {
String cookieName = SystemGlobals.getValue(ConfigKeys.COOKIE_NAME_DATA);
Cookie cookie = this.getCookieTemplate(cookieName);
Cookie hashCookie = this.getCookieTemplate(SystemGlobals.getValue(ConfigKeys.COOKIE_USER_HASH));
Cookie autoLoginCookie = this.getCookieTemplate(SystemGlobals.getValue(ConfigKeys.COOKIE_AUTO_LOGIN));
if (hashCookie != null && cookie != null && !cookie.getValue().equals(SystemGlobals.getValue(ConfigKeys.ANONYMOUS_USER_ID)) && autoLoginCookie != null && "1".equals(autoLoginCookie.getValue())) {
String uid = cookie.getValue();
String uidHash = hashCookie.getValue();
// Load the user-specific security hash from the database
try {
UserDAO userDao = DataAccessDriver.getInstance().newUserDAO();
String userHash = userDao.getUserAuthHash(Integer.parseInt(uid));
if (userHash == null || userHash.trim().length() == 0) {
return false;
}
String securityHash = MD5.crypt(userHash);
if (securityHash.equals(uidHash)) {
int userId = Integer.parseInt(uid);
userSession.setUserId(userId);
User user = userDao.selectById(userId);
if (user == null || user.getId() != userId || user.isDeleted()) {
userSession.makeAnonymous();
return false;
}
this.configureUserSession(userSession, user);
return true;
}
} catch (Exception e) {
throw new DatabaseException(e);
}
userSession.makeAnonymous();
}
return false;
}
use of net.jforum.exceptions.DatabaseException in project jforum2 by rafaelsteil.
the class ForumStartup method startDatabase.
/**
* Starts the database implementation
* @return <code>true</code> if everthing were ok
* @throws DatabaseException if something were wrong
*/
public static boolean startDatabase() {
try {
if (DBConnection.createInstance()) {
DBConnection.getImplementation().init();
// Check if we're in fact up and running
Connection conn = DBConnection.getImplementation().getConnection();
DBConnection.getImplementation().releaseConnection(conn);
}
} catch (Exception e) {
throw new DatabaseException("Error while trying to start the database: " + e, e);
}
return true;
}
use of net.jforum.exceptions.DatabaseException in project jforum2 by rafaelsteil.
the class GenericConfigDAO method insert.
/**
* @see net.jforum.dao.ConfigDAO#insert(net.jforum.entities.Config)
*/
public void insert(Config config) {
PreparedStatement p = null;
try {
p = JForumExecutionContext.getConnection().prepareStatement(SystemGlobals.getSql("ConfigModel.insert"));
p.setString(1, config.getName());
p.setString(2, config.getValue());
p.executeUpdate();
} catch (SQLException e) {
throw new DatabaseException(e);
} finally {
DbUtils.close(p);
}
}
use of net.jforum.exceptions.DatabaseException in project jforum2 by rafaelsteil.
the class GenericForumDAO method setModerated.
/**
* @see net.jforum.dao.ForumDAO#setModerated(int, boolean)
*/
public void setModerated(int categoryId, boolean status) {
PreparedStatement p = null;
try {
p = JForumExecutionContext.getConnection().prepareStatement(SystemGlobals.getSql("ForumModel.setModerated"));
p.setInt(1, status ? 1 : 0);
p.setInt(2, categoryId);
p.executeUpdate();
} catch (SQLException e) {
throw new DatabaseException(e);
} finally {
DbUtils.close(p);
}
}
use of net.jforum.exceptions.DatabaseException in project jforum2 by rafaelsteil.
the class GenericForumDAO method changeForumOrder.
private Forum changeForumOrder(Forum forum, Forum related) {
int tmpOrder = related.getOrder();
related.setOrder(forum.getOrder());
forum.setOrder(tmpOrder);
PreparedStatement p = null;
try {
p = JForumExecutionContext.getConnection().prepareStatement(SystemGlobals.getSql("ForumModel.setOrderById"));
p.setInt(1, forum.getOrder());
p.setInt(2, forum.getId());
p.executeUpdate();
p.close();
p = null;
p = JForumExecutionContext.getConnection().prepareStatement(SystemGlobals.getSql("ForumModel.setOrderById"));
p.setInt(1, related.getOrder());
p.setInt(2, related.getId());
p.executeUpdate();
return this.selectById(forum.getId());
} catch (SQLException e) {
throw new DatabaseException(e);
} finally {
DbUtils.close(p);
}
}
Aggregations