https 迷之跳转到http 求大神解答
login.js
$(function() {
validateRule();
$('.imgcode').click(function() {
var url = ctx + "captcha/next?w=120&h=60&s=" + Math.random();
$(".imgcode").attr("src", url);
});
});
$.validator.setDefaults({
submitHandler: function() {
login();
}
});
function login() {
$.modal.loading($("#btnSubmit").data("loading"));
var username = $.common.trim($("input[name='username']").val());
var password = $.common.trim($("input[name='password']").val());
var validateCode = $("input[name='validateCode']").val();
var rememberMe = $("input[name='rememberme']").is(':checked');
$.ajax({
type: "post",
url: ctx + "login/login",
data: {
"username": username,
"password": password,
"validateCode" : validateCode,
"rememberMe": rememberMe
},
success: function(r) {
if (r.code == 0) {
location.href = ctx + 'index';
} else {
$.modal.closeLoading();
$('.imgcode').click();
$(".code").val("");
$.modal.msg(r.msg);
}
}
});
}
function validateRule() {
var icon = "<i class='fa fa-times-circle'></i> ";
$("#signupForm").validate({
rules: {
username: {
required: true
},
password: {
required: true
}
},
messages: {
username: {
required: icon + "请输入您的用户名",
},
password: {
required: icon + "请输入您的密码",
}
}
})
}
package io.nutz.nutzsite.module.sys.controllers;
import io.nutz.nutzsite.common.base.Globals;
import io.nutz.nutzsite.common.base.Result;
import io.nutz.nutzsite.common.manager.AsyncManager;
import io.nutz.nutzsite.common.manager.factory.AsyncFactory;
import io.nutz.nutzsite.common.utils.ShiroUtils;
import io.nutz.nutzsite.common.utils.Toolkit;
import io.nutz.nutzsite.module.sys.models.User;
import io.nutz.nutzsite.module.sys.services.UserService;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.*;
import org.apache.shiro.subject.Subject;
import org.apache.shiro.util.ThreadContext;
import org.nutz.ioc.loader.annotation.Inject;
import org.nutz.ioc.loader.annotation.IocBean;
import org.nutz.lang.Lang;
import org.nutz.lang.Strings;
import org.nutz.mvc.Mvcs;
import org.nutz.mvc.annotation.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
/**
* @author haiming
*/
@At("/login")
@IocBean
public class LoginController {
@Inject
private UserService userService;
@Inject
private AsyncFactory asyncFactory;
@GET
@At({"","/loginPage"})
@Ok("re")
public String loginPage(HttpServletRequest req) {
req.setAttribute("base", Globals.AppBase);
User user = ShiroUtils.getSysUser();
if (Lang.isNotEmpty(user)) {
return ">>:/index";
}
return "th:/login.html";
}
@Ok("json")
@Fail("http:500")
@POST
@At("/login")
public Result login(@Param("username")String username,
@Param("password")String password,
@Param("rememberMe")boolean rememberMe,
@Param("validateCode")String validateCode,
HttpServletRequest req) {
// session是否有效
HttpSession session = Mvcs.getHttpSession(false);
if (session == null) {
return Result.error("当前回话已过期,请刷新后重试");
}
// 比对验证码
String _captcha = (String) session.getAttribute(Toolkit.captcha_attr);
if (Strings.isBlank(_captcha) || !Toolkit.checkCaptcha(_captcha,validateCode)) {
return Result.error("验证码错误");
}
try {
Subject subject = SecurityUtils.getSubject();
ThreadContext.bind(subject);
subject.login(new UsernamePasswordToken(username,password,rememberMe));
User user = (User) subject.getPrincipal();
AsyncManager.me().execute(asyncFactory.recordLogininfor(user.getLoginName(), true,req,"登录成功"));
userService.recordLoginInfo(user);
return Result.success("login.success");
} catch (LockedAccountException e) {
AsyncManager.me().execute(asyncFactory.recordLogininfor(username, false,req,"账号锁定"));
return Result.error(3, "login.error.locked");
} catch (UnknownAccountException e) {
AsyncManager.me().execute(asyncFactory.recordLogininfor(username, false,req,"用户不存在"));
return Result.error(4, "login.error.user");
} catch (AuthenticationException e) {
AsyncManager.me().execute(asyncFactory.recordLogininfor(username, false,req,"密码错误"));
return Result.error(5, "login.error.user");
} catch (Exception e) {
AsyncManager.me().execute(asyncFactory.recordLogininfor(username, false,req,"登录系统异常"));
return Result.error(6, "login.error.system");
}
}
@At
@Ok("re")
public String logout() {
Subject subject = SecurityUtils.getSubject();
if (subject.isAuthenticated()) {
subject.logout();
}
return ">>:/login";
}
@At
@Ok("th:/error/unauth.html")
public void unauth() {
}
}
为什么它非要跳转 从https 跳转 http
T T