⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 signaction.java

📁 Java/J2EE框架Jdon-Framework系统的源代码
💻 JAVA
字号:
/*
 * Copyright 2003-2005 the original author or authors.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * 
 */
package com.jdon.framework.samples.jpetstore.presentation.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.beanutils.PropertyUtils;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;
import org.apache.struts.action.ActionMessages;
import org.apache.struts.actions.DispatchAction;

import com.jdon.controller.WebAppUtil;
import com.jdon.framework.samples.jpetstore.domain.Account;
import com.jdon.framework.samples.jpetstore.presentation.form.AccountForm;
import com.jdon.framework.samples.jpetstore.service.AccountService;
import com.jdon.framework.samples.jpetstore.service.ProductManager;
import com.jdon.strutsutil.FormBeanUtil;
import com.jdon.util.Debug;

/**
 * @author <a href="mailto:banqiao@jdon.com">banq </a>
 *  
 */
public class SignAction extends DispatchAction {
    private final static String module = SignAction.class.getName();
    
    public ActionForward signon(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response) throws Exception  {

        AccountService accountService = (AccountService) WebAppUtil.getService(
                "accountService", request);
        ProductManager catalogService = (ProductManager) WebAppUtil.getService(
                "productManager", request);
        AccountForm accountForm = (AccountForm) form;

        Account account = accountService.getAccount(accountForm.getUsername(),
                accountForm.getPassword());
           
        if (account != null) {
            
            try {
                Debug.logVerbose("signon.. account:" + account.getUsername(), module);
                PropertyUtils.copyProperties(accountForm, account);
                accountForm.setAuthenticated(true);
                accountForm.setPassword(null);
                
            } catch (Exception e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
        if (accountForm.isAuthenticated())
            return mapping.findForward("success");            
        else{
            ActionMessages errors = new ActionMessages();
            ActionMessage error = new ActionMessage("errors.signon");
            errors.add(ActionMessages.GLOBAL_MESSAGE, error);
            saveErrors(request, errors);
            return mapping.findForward("failure");
        }
    }
    

    
    public ActionForward signoff(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
    throws Exception {
        Debug.logVerbose("signoff ", module);
        AccountForm accountForm = (AccountForm) form;
        request.getSession().invalidate();
        accountForm.setAuthenticated(false);
        accountForm = null;
                
        return mapping.findForward("success"); 

    }
    
    public ActionForward signcheck(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
    throws Exception {     
        Debug.logVerbose("signcheck.... ", module);        
        AccountForm accountForm = (AccountForm) form;
        if ((accountForm == null) || (!accountForm.isAuthenticated())){
            ActionMessages errors = new ActionMessages();
            ActionMessage error = new ActionMessage("errors.sign");
            errors.add(ActionMessages.GLOBAL_MESSAGE, error);
            saveErrors(request, errors);
            return mapping.findForward("failure");
        }else{
            String backurl = request.getParameter("backurl");
            if (backurl != null){
                ActionForward af = new ActionForward(backurl);
                return af;
            }
            return mapping.findForward("success");
        }

    }
        
    

}

⌨️ 快捷键说明

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