Search in sources :

Example 1 with Session

use of com.willshex.blogwt.shared.api.datatype.Session in project blogwt by billy1380.

the class DownloadJsonServlet method doGet.

/* (non-Javadoc)
	 * 
	 * @see com.willshex.gson.web.service.server.JsonServlet#doGet() */
@Override
protected void doGet() throws IOException {
    String action = REQUEST.get().getParameter("action");
    String request = REQUEST.get().getParameter("request");
    if (request == null && "download".equals(action)) {
        Session userSession = ServletHelper.session(REQUEST.get());
        if (userSession != null) {
            String idParam = REQUEST.get().getParameter(ENTITY_ID_KEY);
            if (idParam != null) {
                Long id = Long.valueOf(idParam);
                GeneratedDownload generatedDownload = GeneratedDownloadServiceProvider.provide().getGeneratedDownload(id);
                if (generatedDownload.userKey.getId() == userSession.userKey.getId()) {
                    Filter filter = Filter.fromStack(Stack.parse(generatedDownload.parameters));
                    String fileName = StringUtils.urldecode(generatedDownload.parameters).replace(Filter.QUERY + "/", "").replace("/", "_").replace("&", "_").replace(" ", "_") + "." + DownloadGeneratorProvider.extension(filter.type).get();
                    RESPONSE.get().setContentType(DownloadGeneratorProvider.contentType(filter.type).get());
                    RESPONSE.get().setHeader("content-disposition", "inline; filename=\"" + fileName + "\"");
                    RESPONSE.get().getOutputStream().write(GcsHelper.load(GeneratedDownloadHelper.path(generatedDownload, filter)));
                } else {
                    RESPONSE.get().sendError(403, "Access denied, cannot download other user's file");
                }
            }
        } else {
            RESPONSE.get().sendError(403, "Access denied, cannot download file without logging in");
        }
    } else {
        super.doGet();
    }
}
Also used : GeneratedDownload(com.willshex.blogwt.shared.api.datatype.GeneratedDownload) Filter(com.willshex.blogwt.shared.page.search.Filter) Session(com.willshex.blogwt.shared.api.datatype.Session)

Example 2 with Session

use of com.willshex.blogwt.shared.api.datatype.Session in project blogwt by billy1380.

the class SessionController method sessionForApiCall.

public Session sessionForApiCall() {
    Session session = null;
    if (this.session != null && this.session.id != null) {
        session = new Session();
        session.id = this.session.id;
    } else {
        String id = Cookies.getCookie(COOKIE_KEY_ID);
        if (id != null) {
            session = new Session();
            session.id = Long.valueOf(id);
        }
    }
    return session;
}
Also used : Session(com.willshex.blogwt.shared.api.datatype.Session)

Example 3 with Session

use of com.willshex.blogwt.shared.api.datatype.Session in project blogwt by billy1380.

the class SessionValidator method lookup.

/**
 * @param session
 * @param name
 * @return
 * @throws InputValidationException
 */
public static Session lookup(Session session, String name) throws InputValidationException {
    if (session == null)
        throwServiceError(InputValidationException.class, ApiError.InvalidValueNull, TYPE + ": " + name);
    boolean isIdLookup = false;
    if (session.id != null) {
        isIdLookup = true;
    }
    if (!isIdLookup)
        throwServiceError(InputValidationException.class, ApiError.DataTypeNoLookup, TYPE + ": " + name);
    Session lookupSession = null;
    if (isIdLookup) {
        lookupSession = SessionServiceProvider.provide().getSession(session.id);
    }
    if (lookupSession == null)
        throwServiceError(InputValidationException.class, ApiError.DataTypeNotFound, TYPE + ": " + name);
    return lookupSession;
}
Also used : InputValidationException(com.willshex.gson.web.service.server.InputValidationException) Session(com.willshex.blogwt.shared.api.datatype.Session)

Example 4 with Session

use of com.willshex.blogwt.shared.api.datatype.Session in project blogwt by billy1380.

the class SessionService method addSession.

/* (non-Javadoc)
	 * 
	 * @see com.willshex.blogwt.server.services.session.ISessionService
	 * #addSession(com.willshex.blogwt.shared.api.datatypes.Session) */
@Override
public Session addSession(Session session) {
    if (session.created == null) {
        session.created = new Date();
    }
    session.userKey = Key.create(session.user);
    if (session.longTerm == null) {
        session.longTerm = Boolean.FALSE;
    }
    if (session.expires == null) {
        session.expires = DateTimeHelper.millisFromNow(Boolean.TRUE.equals(session.longTerm) ? MILLIS_DAYS : MILLIS_MINUTES);
    }
    Key<Session> key = provide().save().entity(session).now();
    session.id = keyToId(key);
    return session;
}
Also used : Date(java.util.Date) Session(com.willshex.blogwt.shared.api.datatype.Session)

Example 5 with Session

use of com.willshex.blogwt.shared.api.datatype.Session in project blogwt by billy1380.

the class Request method fromJson.

@Override
public void fromJson(JsonObject jsonObject) {
    super.fromJson(jsonObject);
    if (jsonObject.has("accessCode")) {
        JsonElement jsonAccessCode = jsonObject.get("accessCode");
        if (jsonAccessCode != null) {
            accessCode = jsonAccessCode.getAsString();
        }
    }
    if (jsonObject.has("session")) {
        JsonElement jsonSession = jsonObject.get("session");
        if (jsonSession != null) {
            session = new Session();
            session.fromJson(jsonSession.getAsJsonObject());
        }
    }
}
Also used : JsonElement(com.google.gson.JsonElement) Session(com.willshex.blogwt.shared.api.datatype.Session)

Aggregations

Session (com.willshex.blogwt.shared.api.datatype.Session)10 Date (java.util.Date)3 JsonElement (com.google.gson.JsonElement)2 GWT (com.google.gwt.core.client.GWT)1 AnchorElement (com.google.gwt.dom.client.AnchorElement)1 Document (com.google.gwt.dom.client.Document)1 Element (com.google.gwt.dom.client.Element)1 ImageElement (com.google.gwt.dom.client.ImageElement)1 ClickEvent (com.google.gwt.event.dom.client.ClickEvent)1 ClickHandler (com.google.gwt.event.dom.client.ClickHandler)1 SafeHtmlTemplates (com.google.gwt.safehtml.client.SafeHtmlTemplates)1 SafeHtml (com.google.gwt.safehtml.shared.SafeHtml)1 SafeHtmlUtils (com.google.gwt.safehtml.shared.SafeHtmlUtils)1 SafeUri (com.google.gwt.safehtml.shared.SafeUri)1 UiBinder (com.google.gwt.uibinder.client.UiBinder)1 UiField (com.google.gwt.uibinder.client.UiField)1 Event (com.google.gwt.user.client.Event)1 EventListener (com.google.gwt.user.client.EventListener)1 Anchor (com.google.gwt.user.client.ui.Anchor)1 HTMLPanel (com.google.gwt.user.client.ui.HTMLPanel)1