jfianl 登录状态验证,未登录打开登录页面,登录成功后跳转到请求页面

项目中的一个需求,1、当用户提交预约信息时,如果未登录跳装到用户登录(注册)界面。 2、当登录(注册)成功后,跳转到请求页面

思路:1、增加登录状态验证拦截器,验证登录状态,如果未登录,获取请求路径,并保存在requset中,跳转登录(注册)页面

         2、前台form中 增加 hiddent  input  。value为request中的请求路径

   3、后台登录controller中验证,如登录(注册)成功则跳转到 请求路径

代码:1、

public class LoginInterceptor implements Interceptor {

    @Override

    public void intercept(ActionInvocation ai) {

        Controller c = ai.getController();

        String uid = c.getCookie("eyeuid");

        String time = c.getCookie("eyetime");

        if (Db.findFirst("select * from eye_memberlogin where memberId = ? and time = ?",uid,time)==null || RecordFactory.getActiveMember(Integer.parseInt(uid))==null){

            HttpServletRequest req = c.getRequest();

            String redirectURL = req.getServletPath()+"?"+req.getQueryString();

            c.setAttr("redirectURL",redirectURL);

            c.render("/register.html");

        }else {

            c.setSessionAttr("eyeuid",uid);

            c.setAttr("m", RecordFactory.newMember(Integer.parseInt(uid)));

            ai.invoke();

        }

    }

}

<form action="${path}/member/login" method="post" >

        <input type="hidden" name="redirectURL" value="${redirectURL}"/>

         ...............

        <input type="submit" class="all-abtn Wp100" value="登录">

     </form>

3

public void login(){

        keepPara();

        String uid = getPara("phone");

        String upwd = getPara("upwd");

        Record member = RecordFactory.getMember(uid,upwd);

        if (member==null){

            setAttr("errMsg","用户名或密码不正确");

            render("/login.html");

            return;

        }

        if (member.getInt("memberState")!=0){

            setAttr("errMsg","该用户已停用或作废,如有疑问请联系客服");

            render("/login.html");

            return;

        }

        EyeUtil.setCookie(this, member);

        redirect(getPara("redirectURL","/index"));

    }

 

你可能感兴趣的:(验证)