Search in sources :

Example 1 with Reforward

use of org.tinystruct.handler.Reforward in project bible-online by m0ver.

the class error method process.

public void process() throws ApplicationException {
    this.request = (HttpServletRequest) this.context.getAttribute(HTTP_REQUEST);
    this.response = (HttpServletResponse) this.context.getAttribute(HTTP_RESPONSE);
    this.response.setStatus(HttpServletResponse.SC_FORBIDDEN);
    this.reforward = new Reforward(this.request, this.response);
    this.setVariable("from", this.reforward.getFromURL());
    HttpSession session = this.request.getSession();
    if (session.getAttribute("error") != null) {
        ApplicationException exception = (ApplicationException) session.getAttribute("error");
        String message = exception.getRootCause().getMessage();
        if (message != null)
            this.setVariable("exception.message", message);
        else
            this.setVariable("exception.message", "Unknown error");
        this.setVariable("exception.details", this.getDetail(exception).toString());
        this.response.setStatus(Integer.valueOf(exception.getStatus()));
    } else {
        this.reforward.forward();
    }
}
Also used : ApplicationException(org.tinystruct.ApplicationException) HttpSession(javax.servlet.http.HttpSession) Reforward(org.tinystruct.handler.Reforward)

Example 2 with Reforward

use of org.tinystruct.handler.Reforward in project bible-online by m0ver.

the class login method logout.

public void logout() {
    HttpServletRequest request = (HttpServletRequest) this.context.getAttribute(HTTP_REQUEST);
    HttpServletResponse response = (HttpServletResponse) this.context.getAttribute(HTTP_RESPONSE);
    try {
        this.passport = new passport(request, response, "waslogined");
        this.passport.logout();
        if (request.getCookies() != null) {
            Cookie[] cookies = request.getCookies();
            int i = 0;
            Cookie cookie;
            while (cookies.length > i) {
                cookie = cookies[i];
                cookie.setMaxAge(0);
                cookie.setValue("");
                response.addCookie(cookie);
                i++;
            }
        }
        Reforward reforward = new Reforward(request, response);
        reforward.setDefault(this.getLink(this.getConfiguration("default.login.page")));
        reforward.forward();
    } catch (ApplicationException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) Cookie(javax.servlet.http.Cookie) ApplicationException(org.tinystruct.ApplicationException) Reforward(org.tinystruct.handler.Reforward) HttpServletResponse(javax.servlet.http.HttpServletResponse)

Example 3 with Reforward

use of org.tinystruct.handler.Reforward in project bible-online by m0ver.

the class login method execute.

public void execute(String provider) throws ApplicationException {
    HttpServletRequest http_request = (HttpServletRequest) this.context.getAttribute(HTTP_REQUEST);
    HttpServletResponse http_response = (HttpServletResponse) this.context.getAttribute(HTTP_RESPONSE);
    Reforward reforward = new Reforward(http_request, http_response);
    this.setVariable("from", reforward.getFromURL());
    System.out.println("From:" + reforward.getFromURL());
    try {
        HttpSession session = http_request.getSession();
        if (session.getAttribute("usr") == null)
            reforward.setDefault(createRequestString(oAuth2Provider.valueOf(provider.toUpperCase())));
    } catch (UnsupportedEncodingException e) {
        // TODO Auto-generated catch block
        throw new ApplicationException(e.getMessage(), e);
    }
    reforward.forward();
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) ApplicationException(org.tinystruct.ApplicationException) HttpSession(javax.servlet.http.HttpSession) Reforward(org.tinystruct.handler.Reforward) HttpServletResponse(javax.servlet.http.HttpServletResponse)

Example 4 with Reforward

use of org.tinystruct.handler.Reforward in project bible-online by m0ver.

the class sender method update.

public boolean update(String id) throws ApplicationException {
    report report = new report();
    report.setId(id);
    report.findOneById();
    bible bible = new bible();
    if (this.getLocale().toString().equalsIgnoreCase(Locale.US.toString())) {
        bible.setTableName("NIV");
    } else if (this.getLocale().toString().equalsIgnoreCase(Locale.UK.toString())) {
        bible.setTableName("KJV");
    } else {
        bible.setTableName(this.getLocale().toString());
    }
    bible.setId(report.getBibleId());
    bible.setContent(report.getUpdatedContent());
    report.setStatus(1);
    if (bible.update() && report.update()) {
        this.request = (HttpServletRequest) this.context.getAttribute(HTTP_REQUEST);
        this.response = (HttpServletResponse) this.context.getAttribute(HTTP_RESPONSE);
        bible.findOneById();
        this.reforward = new Reforward(this.request, this.response);
        this.reforward.setDefault(this.getLink("bible") + "/" + bible.getBookId() + "/" + bible.getChapterId() + "/" + bible.getPartId());
        this.reforward.forward();
        return true;
    }
    return false;
}
Also used : custom.objects.bible(custom.objects.bible) Reforward(org.tinystruct.handler.Reforward) custom.objects.report(custom.objects.report)

Example 5 with Reforward

use of org.tinystruct.handler.Reforward in project bible-online by m0ver.

the class login method validate.

public Object validate() {
    HttpServletRequest request = (HttpServletRequest) this.context.getAttribute(HTTP_REQUEST);
    HttpServletResponse response = (HttpServletResponse) this.context.getAttribute(HTTP_RESPONSE);
    Cookie cookie = StringUtilities.getCookieByName(request.getCookies(), "username");
    if (cookie != null) {
        this.setVariable("username", cookie.getValue());
        String user_field = cookie.getValue() + "<input class=\"text\" id=\"username\" name=\"username\" type=\"hidden\" value=\"" + cookie.getValue() + "\"/>  <a href=\"javascript:void(0)\" onclick=\"restoreField()\">[%login.user.change%]</a>";
        this.setVariable("user_field", user_field);
    } else {
        this.setVariable("username", "");
        this.setVariable("user_field", "<input class=\"text\" id=\"username\" name=\"username\" type=\"text\" value=\"\"/>");
    }
    this.setText("login.tips.text", this.getLink("bible"));
    try {
        Reforward reforward = new Reforward(request, response);
        if (request.getMethod().equalsIgnoreCase("post")) {
            this.passport = new passport(request, response, "waslogined");
            if (this.passport.login()) {
                reforward.forward();
            }
        }
        this.setVariable("from", reforward.getFromURL());
    } catch (ApplicationException e) {
        this.setVariable("error", "<div class=\"error\">" + e.getRootCause().getMessage() + "</div>");
    }
    this.setVariable("action", String.valueOf(this.context.getAttribute("HTTP_HOST")) + this.context.getAttribute("REQUEST_ACTION").toString());
    HttpSession session = request.getSession();
    if (session.getAttribute("usr") != null) {
        this.usr = (User) session.getAttribute("usr");
        this.setVariable("user.status", "");
        this.setVariable("user.profile", "<a href=\"javascript:void(0)\" onmousedown=\"profileMenu.show(event,'1')\">" + this.usr.getEmail() + "</a>");
    } else {
        this.setVariable("user.status", "<a href=\"" + this.getLink("user/login") + "\">" + this.getProperty("page.login.caption") + "</a>");
        this.setVariable("user.profile", "");
    }
    return this;
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) Cookie(javax.servlet.http.Cookie) ApplicationException(org.tinystruct.ApplicationException) HttpSession(javax.servlet.http.HttpSession) Reforward(org.tinystruct.handler.Reforward) HttpServletResponse(javax.servlet.http.HttpServletResponse)

Aggregations

Reforward (org.tinystruct.handler.Reforward)10 ApplicationException (org.tinystruct.ApplicationException)9 HttpSession (javax.servlet.http.HttpSession)6 HttpServletRequest (javax.servlet.http.HttpServletRequest)5 HttpServletResponse (javax.servlet.http.HttpServletResponse)5 User (custom.objects.User)2 custom.objects.bible (custom.objects.bible)2 custom.objects.vocabulary (custom.objects.vocabulary)2 Date (java.util.Date)2 Cookie (javax.servlet.http.Cookie)2 Header (org.apache.http.Header)2 HeaderIterator (org.apache.http.HeaderIterator)2 HttpResponse (org.apache.http.HttpResponse)2 ParseException (org.apache.http.ParseException)2 ClientProtocolException (org.apache.http.client.ClientProtocolException)2 HttpClient (org.apache.http.client.HttpClient)2 HttpGet (org.apache.http.client.methods.HttpGet)2 DefaultHttpClient (org.apache.http.impl.client.DefaultHttpClient)2 Builder (org.tinystruct.data.component.Builder)2 Pager (org.tinystruct.data.component.Pager)2