judgels.jophiel.api.play.PlaySessionService

Here are the examples of the java api judgels.jophiel.api.play.PlaySessionService taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

1 Examples 7

18 Source : JophielClientController.java
with GNU General Public License v2.0
from ia-toki

@Singleton
public final clreplaced JophielClientController extends AbstractJophielClientController {

    private final PlaySessionService sessionService;

    private final ActorChecker actorChecker;

    @Inject
    public JophielClientController(PlaySessionService sessionService, ActorChecker actorChecker) {
        this.sessionService = sessionService;
        this.actorChecker = actorChecker;
    }

    @AddCSRFToken
    public Result login(Http.Request req) {
        Form<LoginForm> form = formFactory.form(LoginForm.clreplaced);
        return showLogin(req, form);
    }

    @RequireCSRFCheck
    @Transactional
    public Result postLogin(Http.Request req) {
        Form<LoginForm> form = formFactory.form(LoginForm.clreplaced).bindFromRequest(req);
        if (form.hasErrors()) {
            return showLogin(req, form);
        }
        LoginForm data = form.get();
        PlaySession session;
        try {
            session = sessionService.logIn(Credentials.of(data.username, data.preplacedword));
        } catch (RemoteException e) {
            if (e.getError().errorName().equals(PlaySessionErrors.ROLE_NOT_ALLOWED.name())) {
                form = form.withGlobalError("User role not allowed to log in.");
            } else if (e.getStatus() == 403) {
                form = form.withGlobalError("Username or preplacedword incorrect.");
            }
            return showLogin(req, form);
        }
        return redirect(getServiceLoginUrl(session.getAuthCode(), getRootUrl(req))).removingFromFlash("localChangesError").withSession(new ImmutableMap.Builder<String, String>().put("version", JophielSessionUtils.getSessionVersion()).put("token", session.getToken()).put("userJid", session.getUserJid()).put("username", session.getUsername()).put("role", session.getRole()).put("avatar", getUserAvatarUrl(session.getUserJid())).build());
    }

    public Result logout(String returnUri) {
        actorChecker.clear();
        return redirect(getServiceLogoutUrl(returnUri)).withNewSession();
    }

    private Result showLogin(Http.Request req, Form<LoginForm> form) {
        HtmlTemplate template = getBaseHtmlTemplate(req);
        template.setSingleColumn();
        template.setContent(loginView.render(form));
        template.setMainreplacedle("Log in");
        template.markBreadcrumbLocation("Log in", routes.JophielClientController.login());
        template.setPagereplacedle("Log in");
        return renderTemplate(template);
    }
}