Package in.partake.controller.action.event

Source Code of in.partake.controller.action.event.EventPasscodeAction

package in.partake.controller.action.event;

import in.partake.base.PartakeException;
import in.partake.controller.action.AbstractPartakeAction;
import in.partake.model.IPartakeDAOs;
import in.partake.model.access.DBAccess;
import in.partake.model.dao.DAOException;
import in.partake.model.dao.PartakeConnection;
import in.partake.model.dto.Event;
import in.partake.resource.MessageCode;

import org.apache.commons.lang.StringUtils;

import play.mvc.Result;

// TODO(mayah): Maybe we have to reconsider how to do this.
public class EventPasscodeAction extends AbstractPartakeAction {
    private String eventId;

    public static Result get() throws DAOException, PartakeException {
        return new EventPasscodeAction().execute();
    }

    public Result doExecute() throws DAOException, PartakeException {
        eventId = getValidEventIdParameter();

        String passcode = getParameter("passcode");

        if (passcode == null)
            return render(views.html.events.passcode.render(context(), eventId));

        Event event = new EventPasscodeTransaction(eventId).execute();
        if (event == null)
            return renderNotFound();

        String pass = StringUtils.trim(passcode);

        if (!pass.equals(event.getPasscode())) {
            context().addMessage(MessageCode.MESSAGE_PASSCODE_INVALID);
            return render(views.html.events.passcode.render(context(), eventId));
        }

        // TODO: Reconsider Session.
        session().put(eventId, passcode);
        return renderRedirect("/events/" + eventId);
    }

    public String getEventId() {
        return eventId;
    }
}

class EventPasscodeTransaction extends DBAccess<Event> {
    private String eventId;

    public EventPasscodeTransaction(String eventId) {
        this.eventId = eventId;
    }

    @Override
    protected Event doExecute(PartakeConnection con, IPartakeDAOs daos) throws DAOException, PartakeException {
        return daos.getEventAccess().find(con, eventId);
    }
}
TOP

Related Classes of in.partake.controller.action.event.EventPasscodeAction

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.