auth.jsp

来自「Jive是基于JSP/JAVA技术构架的一个大型BBS论坛系统,这是Jive论坛」· JSP 代码 · 共 367 行 · 第 1/2 页

JSP
367
字号
<%/** *	$RCSfile: auth.jsp,v $ *	$Revision: 1.9 $ *	$Date: 2002/07/02 20:38:01 $ */%><%@ page import="java.net.*,                 java.util.*,                 com.jivesoftware.forum.*,                 com.jivesoftware.forum.util.*"%><%@ include file="global.jsp" %><%  // Get parameters    String username = ParamUtils.getParameter(request,"username");    String password = ParamUtils.getParameter(request,"password");    boolean autoLogin = ParamUtils.getBooleanParameter(request,"autoLogin");    boolean login = ParamUtils.getBooleanParameter(request,"login");    boolean logout = ParamUtils.getBooleanParameter(request,"logout");    boolean unauth = ParamUtils.getBooleanParameter(request, "unauth");    boolean cancel = request.getParameter("cancel") != null;    // Vars to indicate either logging in or logging out was successful:    boolean loginSuccess = false;    boolean logoutSuccess = false;    // Error variables    boolean usernamePasswordError = false;    // Cancel if requested - redirect to the main forums page.    if (cancel) {        response.sendRedirect("index.jsp");        return;    }    // Logout if requested    if (logout) {        try {            session.removeAttribute(AuthorizationFactory.SESSION_AUTHORIZATION);            SkinUtils.deleteCookie(response,                SkinUtils.getCookie(request,AuthorizationFactory.COOKIE_AUTOLOGIN));            logoutSuccess = true;        }        catch (Exception e) {}    }    // Login if requested    if (login) {		if (username == null || password == null) {			usernamePasswordError = true;		}		if (!usernamePasswordError) {			try {                // Try to create an auth token based on the username and                // password. If this fails, an exception is thrown, otherwise                // a valid authorization token will be returned.                authToken = AuthorizationFactory.getAuthorization(username,password);                // Put the valid token in the session                session.setAttribute(AuthorizationFactory.SESSION_AUTHORIZATION, authToken);                // Optionally set a cookie with the user's username and password                if (autoLogin) {                    SkinUtils.setCookie(response,AuthorizationFactory.COOKIE_AUTOLOGIN,                        AuthorizationFactory.encryptAuthInfo(username, password));                }				loginSuccess = true;                // If "unauth" is true, we need to redirect back to some page                // because we came to this page via an UnauthorizedException.                // Get the target page:                String target = (String)session.getAttribute("jive.redirect");                if (target != null && !"".equals(target)) {                    response.sendRedirect(target);                    return;                }			}			catch (UnauthorizedException ue) {				usernamePasswordError = true;			}		}    }    // Check if new account creation is enabled:    boolean newAccounts = !"false".equals(JiveGlobals.getJiveProperty("skin.default.newAccountCreationEnabled"));%><%  String title = SkinUtils.getLocalizedString("skin.default.login.title",locale); %><%@ include file="header.jsp" %><%  // If the current user is not a guest, that means they're already logged in    // so display a message that says so.    // Note, the "isGuest" and "pageUser" vars are from global.jsp    if (!isGuest && !logoutSuccess && !unauth) {        // Put the current user's username in a list. This is passed into the        // getLocalizedString(..) method below.        List usernameDisplay = new ArrayList(1);        usernameDisplay.add("<b>" + pageUser.getUsername() + "</b>");%>    <table cellpadding="0" cellspacing="0" border="0" width="100%">    <tr>        <td valign="top" width="98%">        <%-- breadcrumbs --%>        <font face="<%= JiveGlobals.getJiveProperty("skin.default.fontFace") %>"         color="<%= JiveGlobals.getJiveProperty("skin.default.linkColor") %>">        <b>        <a href="<%= JiveGlobals.getJiveProperty("skin.default.homeURL") %>"         ><%= SkinUtils.getLocalizedString("skin.default.global.home",locale) %></a>        &raquo;        <a href="index.jsp" title="<%= SkinUtils.getLocalizedString("skin.default.global.go_back_to_forum_list",locale) %>"         ><%= SkinUtils.getLocalizedString("skin.default.global.forums",locale) %></a>        &raquo;        <a href="auth.jsp" class="header" title="<%= SkinUtils.getLocalizedString("skin.default.login.login_jive",locale) %>"        ><%= SkinUtils.getLocalizedString("skin.default.global.login",locale) %></a>        </b>        </font><p>        <font size="<%= JiveGlobals.getJiveProperty("skin.default.fontSize") %>"         face="<%= JiveGlobals.getJiveProperty("skin.default.fontFace") %>"         color="<%= JiveGlobals.getJiveProperty("skin.default.textColor") %>">        <%= SkinUtils.getLocalizedString("skin.default.login.already_logged_in_as", usernameDisplay) %>        </font>        <ul>            <li><font size="<%= JiveGlobals.getJiveProperty("skin.default.fontSize") %>"                 face="<%= JiveGlobals.getJiveProperty("skin.default.fontFace") %>"                 color="<%= JiveGlobals.getJiveProperty("skin.default.textColor") %>">                <a href="auth.jsp?logout=true"                 ><%= SkinUtils.getLocalizedString("skin.default.global.logout",locale) %></a>                </font>            <li><font size="<%= JiveGlobals.getJiveProperty("skin.default.fontSize") %>"                 face="<%= JiveGlobals.getJiveProperty("skin.default.fontFace") %>"                 color="<%= JiveGlobals.getJiveProperty("skin.default.textColor") %>">                <a href="index.jsp"                 >Go back to the main forum page</a>                </font>        </ul>        </td>        <td width="1%"><img src="images/blank.gif" width="10" height="1" border="0"></td>        <td valign="top" width="1%" align="center">        <%@ include file="loginbox.jsp" %>        </td>    </tr>    </table><%  }    // Otherwise, the user is not logged in already so show a login prompt:    else {        // Make the link to the new account page (this is embedded in one of        // the i18n strings).        List newAccountLink = new ArrayList(2);        newAccountLink.add("<a href=\"account.jsp\">");        newAccountLink.add("</a>");%>    <table cellpadding="0" cellspacing="0" border="0" width="100%">    <tr>        <td valign="top">        <%-- breadcrumbs --%>        <font face="<%= JiveGlobals.getJiveProperty("skin.default.fontFace") %>"         color="<%= JiveGlobals.getJiveProperty("skin.default.linkColor") %>">        <b>        <a href="<%= JiveGlobals.getJiveProperty("skin.default.homeURL") %>"         ><%= SkinUtils.getLocalizedString("skin.default.global.home",locale) %></a>        &raquo;        <a href="index.jsp" title="<%= SkinUtils.getLocalizedString("skin.default.global.go_back_to_forum_list",locale) %>"         ><%= SkinUtils.getLocalizedString("skin.default.global.forums",locale) %></a>        &raquo;        <a href="auth.jsp" class="header" title="<%= SkinUtils.getLocalizedString("skin.default.login.login_jive",locale) %>"        ><%= SkinUtils.getLocalizedString("skin.default.global.login",locale) %></a>        </b>        </font>        </td>    </tr>    </table><p><%      // We need to either show the user:        //  1) that they successfully logged in        //  2) that they successfully logged out        //  3) or the login box        // Indicate to the user they've successfully logged in:        if (loginSuccess) {%>

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?