use of com.willshex.blogwt.shared.api.datatype.Session in project blogwt by billy1380.
the class Response method fromJson.
@Override
public void fromJson(JsonObject jsonObject) {
super.fromJson(jsonObject);
if (jsonObject.has("status")) {
JsonElement jsonStatus = jsonObject.get("status");
if (jsonStatus != null) {
status = StatusType.fromString(jsonStatus.getAsString());
}
}
if (jsonObject.has("error")) {
JsonElement jsonError = jsonObject.get("error");
if (jsonError != null) {
error = new Error();
error.fromJson(jsonError.getAsJsonObject());
}
}
if (jsonObject.has("session")) {
JsonElement jsonSession = jsonObject.get("session");
if (jsonSession != null) {
session = new Session();
session.fromJson(jsonSession.getAsJsonObject());
}
}
}
use of com.willshex.blogwt.shared.api.datatype.Session in project blogwt by billy1380.
the class HeaderPart method onAttach.
/* (non-Javadoc)
*
* @see com.google.gwt.user.client.ui.Composite#onAttach() */
@Override
protected void onAttach() {
super.onAttach();
register(DefaultEventBus.get().addHandlerToSource(LoginEventHandler.TYPE, SessionController.get(), this));
register(DefaultEventBus.get().addHandlerToSource(LogoutEventHandler.TYPE, SessionController.get(), this));
register(DefaultEventBus.get().addHandlerToSource(NavigationChangedEventHandler.TYPE, NavigationController.get(), (p, c) -> {
if (p != null) {
activateItem(p.getPage(), false, this::getItem);
}
activateItem(c.getPage(), true, this::getItem);
btnNavExpand.hide();
GoogleAnalyticsHelper.sendPageView("#" + c.toString());
}));
register(RootPanel.get().addDomHandler(this, ClickEvent.getType()));
register(DefaultEventBus.get().addHandlerToSource(ChangeUserDetailsEventHandler.TYPE, UserController.get(), this));
Session session = SessionController.get().session();
if (session != null && session.user != null) {
setLoggedInUser(session.user);
} else {
configureNavBar(false);
}
}
use of com.willshex.blogwt.shared.api.datatype.Session in project blogwt by billy1380.
the class SessionValidator method lookupCheckAndExtend.
public static Session lookupCheckAndExtend(Session session, String name) throws ServiceException {
Session lookupSession = lookup(session, name);
Date now = new Date();
if (lookupSession.expires.getTime() < now.getTime())
throwServiceError(InputValidationException.class, ApiError.DataTypeNotFound, TYPE + ": " + name);
lookupSession.user = UserServiceProvider.provide().getUser(keyToId(lookupSession.userKey));
UserValidator.suspended(lookupSession.user);
if ((lookupSession.expires.getTime() - now.getTime()) < ISessionService.MILLIS_MINUTES) {
lookupSession = SessionServiceProvider.provide().extendSession(lookupSession);
}
return lookupSession;
}
use of com.willshex.blogwt.shared.api.datatype.Session in project blogwt by billy1380.
the class ServletHelper method session.
public static Session session(HttpServletRequest request) {
ISessionService sessionService = SessionServiceProvider.provide();
Cookie[] cookies = request.getCookies();
String sessionId = null;
Session userSession = null;
if (cookies != null) {
for (Cookie currentCookie : cookies) {
if ("session.id".equals(currentCookie.getName())) {
sessionId = currentCookie.getValue();
break;
}
}
if (sessionId != null) {
userSession = sessionService.getSession(Long.valueOf(sessionId));
if (userSession != null) {
try {
userSession = SessionValidator.lookupCheckAndExtend(userSession, "session");
UserHelper.stripPassword(userSession.user);
UserHelper.populateRolesAndPermissionsFromKeys(userSession.user);
} catch (ServiceException e) {
userSession = null;
}
}
}
}
return userSession;
}
use of com.willshex.blogwt.shared.api.datatype.Session in project blogwt by billy1380.
the class SessionService method getUserSession.
/* (non-Javadoc)
*
* @see com.willshex.blogwt.server.services.session.ISessionService
* #getUserSession(com.willshex.blogwt.shared.api.datatypes.User) */
@Override
public Session getUserSession(User user) {
Session session = PersistenceHelper.one(load().filter("userKey", user));
if (session != null && session.expires.getTime() < new Date().getTime()) {
deleteSession(session);
session = null;
}
return session;
}
Aggregations