use of org.b3log.symphony.repository.UserRepository in project symphony by b3log.
the class SymphonyServletListener method resolveSkinDir.
/**
* Resolve skin (template) for the specified HTTP servlet request.
*
* @param request the specified HTTP servlet request
*/
private void resolveSkinDir(final HttpServletRequest request) {
Stopwatchs.start("Resolve skin");
request.setAttribute(Keys.TEMAPLTE_DIR_NAME, (Boolean) request.getAttribute(Common.IS_MOBILE) ? "mobile" : "classic");
try {
final UserQueryService userQueryService = beanManager.getReference(UserQueryService.class);
final UserRepository userRepository = beanManager.getReference(UserRepository.class);
final OptionRepository optionRepository = beanManager.getReference(OptionRepository.class);
final JSONObject optionLang = optionRepository.get(Option.ID_C_MISC_LANGUAGE);
final String optionLangValue = optionLang.optString(Option.OPTION_VALUE);
if ("0".equals(optionLangValue)) {
Locales.setLocale(request.getLocale());
} else {
Locales.setLocale(Locales.getLocale(optionLangValue));
}
JSONObject user = userQueryService.getCurrentUser(request);
if (null == user) {
final Cookie[] cookies = request.getCookies();
if (null == cookies || 0 == cookies.length) {
return;
}
try {
for (final Cookie cookie : cookies) {
if (!Sessions.COOKIE_NAME.equals(cookie.getName())) {
continue;
}
final String value = Crypts.decryptByAES(cookie.getValue(), Symphonys.get("cookie.secret"));
if (StringUtils.isBlank(value)) {
break;
}
final JSONObject cookieJSONObject = new JSONObject(value);
final String userId = cookieJSONObject.optString(Keys.OBJECT_ID);
if (Strings.isEmptyOrNull(userId)) {
break;
}
user = userRepository.get(userId);
if (null == user) {
return;
} else {
break;
}
}
} catch (final Exception e) {
LOGGER.log(Level.ERROR, "Read cookie failed", e);
}
if (null == user) {
return;
}
}
request.setAttribute(Keys.TEMAPLTE_DIR_NAME, (Boolean) request.getAttribute(Common.IS_MOBILE) ? user.optString(UserExt.USER_MOBILE_SKIN) : user.optString(UserExt.USER_SKIN));
request.setAttribute(UserExt.USER_AVATAR_VIEW_MODE, user.optInt(UserExt.USER_AVATAR_VIEW_MODE));
request.setAttribute(User.USER, user);
final Locale locale = Locales.getLocale(user.optString(UserExt.USER_LANGUAGE));
Locales.setLocale(locale);
} catch (final Exception e) {
LOGGER.log(Level.ERROR, "Resolves skin failed", e);
} finally {
Stopwatchs.end();
}
}
use of org.b3log.symphony.repository.UserRepository in project symphony by b3log.
the class UserChannel method updateUserOnlineFlag.
private void updateUserOnlineFlag(final String userId, final boolean online) {
final LatkeBeanManager beanManager = LatkeBeanManagerImpl.getInstance();
final UserRepository userRepository = beanManager.getReference(UserRepository.class);
final Transaction transaction = userRepository.beginTransaction();
try {
final JSONObject user = userRepository.get(userId);
user.put(UserExt.USER_ONLINE_FLAG, online);
user.put(UserExt.USER_LATEST_LOGIN_TIME, System.currentTimeMillis());
userRepository.update(userId, user);
transaction.commit();
} catch (final Exception e) {
if (transaction.isActive()) {
transaction.rollback();
}
LOGGER.log(Level.ERROR, "Update user error", e);
} finally {
JdbcRepository.dispose();
}
}
Aggregations