1.导入依赖包
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<!-- 引入MySQL数据库依赖 -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.47</version>
</dependency>
<!-- 引入druid数据库连接 -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
<version>1.1.12</version>
</dependency>
<!--导入Servlet依赖-->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>4.0.1</version>
</dependency>
<!--SpringMVC、spring-->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>5.1.5.RELEASE</version>
</dependency>
<!--Spring对JDBC的支持:因为mybatis-->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>5.1.5.RELEASE</version>
</dependency>
<!-- 引入MyBatis框架依赖 -->
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId>
<version>3.4.6</version>
</dependency>
<!--MyBatis和Spring整合支持包-->
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis-spring</artifactId>
<version>1.3.2</version>
</dependency>
<!-- 引入JSTL标签类依赖 -->
<dependency>
<groupId>jstl</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
<!--freemaker依赖包-->
<dependency>
<groupId>org.freemarker</groupId>
<artifactId>freemarker</artifactId>
<version>2.3.23</version>
</dependency>
<!--https://mvnrepository.com/artifact/org.springframework/spring-context-support -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
<version>5.2.2.RELEASE</version>
</dependency>
<!--slf4j+logback日志-->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.10</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.1.7</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-core</artifactId>
<version>1.1.7</version>
</dependency>
<!-- EasyExcel核心文件 -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>easyexcel</artifactId>
<version>2.2.3</version>
</dependency>
<!-- fastjson依赖包 -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.51</version>
</dependency>
<!-- 解析上传数据 -->
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
<version>1.4</version>
</dependency>
<!--jackson-->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.9.8</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.9.8</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>2.9.8</version>
</dependency>
<!-- shiro-freemarker-tags start -->
<dependency>
<groupId>net.mingsoft</groupId>
<artifactId>shiro-freemarker-tags</artifactId>
<version>1.0.2</version>
<!--排除-->
<exclusions>
<exclusion>
<groupId>org.apache.shiro</groupId>
<artifactId>shiro-all</artifactId>
</exclusion>
<exclusion>
<groupId>org.freemarker</groupId>
<artifactId>freemarker</artifactId>
</exclusion>
</exclusions>
</dependency>
<!--shiro依赖坐标-->
<dependency>
<groupId>org.apache.shiro</groupId>
<artifactId>shiro-all</artifactId>
<version>1.7.0</version>
</dependency>
2.slf4j+logback日志
logback.xml文件:
<?xml version="1.0" encoding="UTF-8"?>
<!--
scan(非必须)属性:默认为false,true表示扫描配置文件的变化并自动重新配置,默认每隔1分钟扫描一次
scanPeriod(非必须)属性:搭配scan属性使用,设置扫描的间隔时间
-->
<configuration scan="true" scanPeriod="1 seconds">
<!--用于区分不同应用程序的记录-->
<contextName>edu-cloud</contextName>
<!--
设置自定义参数,类似于pom.xml里面的properties标签,下面可以使用${名称}引用此变量
-->
<property name="FILE_PATH" value="logs"></property>
<!--
ConsoleAppender: 控制台输出
STDOUT: 给appender起一个名字
-->
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<!--
pattern: 日志输出的格式化样式
-->
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
<!--解决乱码问题-->
<charset>UTF-8</charset>
</encoder>
</appender>
<!--时间滚动日志生成-->
<appender name="TIME_ROLLING_FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<!-- ThresholdFilter:临界值过滤器,过滤掉 TRACE 和 DEBUG 级别的日志 -->
<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
<level>INFO</level>
</filter>
<encoder>
<charset>UTF-8</charset>
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{0} -%msg%n</pattern>
</encoder>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<!--
设置生成的文件地址和文件名
-->
<fileNamePattern>${FILE_PATH}/log%d{yyyy-MM-dd_HH-mm}.log</fileNamePattern>
<!--最多生成十个,查过十个开始删除-->
<maxHistory>10</maxHistory><!--保存最近30天的日志-->
</rollingPolicy>
<triggeringPolicy class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
<!-- 文件大小触发重写新文件 -->
<MaxFileSize>10MB</MaxFileSize>
</triggeringPolicy>
</appender>
<!--
debug: 指定日志的输出级别,大于debug的级别都会被输出
-->
<root level="debug">
<!--
appender-ref: 指定哪一个appender使用此日志输出级别
-->
<appender-ref ref="STDOUT" />
<appender-ref ref="TIME_ROLLING_FILE" />
</root>
</configuration>
3.配置applicationContext文件
applicationContext.xml文件:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd
">
<!--开启mvc注解驱动-->
<mvc:annotation-driven></mvc:annotation-driven>
<!--扫描注解-->
<context:component-scan base-package="com.zhibang"></context:component-scan>
<!--配置静态资源-->
<mvc:default-servlet-handler></mvc:default-servlet-handler>
<!--<mvc:resources mapping="/**" location="/WEB-INF/"></mvc:resources>-->
<!--配置前后缀-->
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/"></property>
<property name="suffix" value=".html"></property>
</bean>
<!--加载外部资源文件-->
<context:property-placeholder location="classpath*:db.properties"></context:property-placeholder>
<!--配置Druid数据源-->
<bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource">
<property name="driverClassName" value="${ts.driverClass}"></property>
<property name="url" value="${ts.url}"></property>
<property name="username" value="${ts.username}"></property>
<property name="password" value="${ts.userpwd}"></property>
<property name="maxActive" value="${pool.maxActive}"></property>
<property name="initialSize" value="${pool.initialsize}"></property>
<property name="maxWait" value="${pool.maxWait}"></property>
</bean>
<!--配置sqlSessionFactory-->
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource"></property>
<property name="typeAliasesPackage" value="com.zhibang.model"></property>
<property name="mapperLocations" value="classpath*:mappers/*.xml"></property>
<!--<property name="configLocation" value="classpath:mybatis-config.xml"></property>-->
</bean>
<!--向mapper层注入sqlSessionFactory-->
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"></property>
<property name="basePackage" value="com.zhibang.dao"></property>
</bean>
<!--配置事物管理器-->
<!--开启spring事物管理-->
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource"></property>
</bean>
<!--启用spring事物管理注解-->
<tx:annotation-driven transaction-manager="transactionManager"></tx:annotation-driven>
<!-- FreeMarker视图解析器 -->
<bean id="freemarkerResolver" class="org.springframework.web.servlet.view.freemarker.FreeMarkerViewResolver">
<property name="order" value="1" />
<property name="suffix" value=".html" />
<property name="contentType" value="text/html;charset=utf-8" />
<property name="viewClass">
<value>org.springframework.web.servlet.view.freemarker.FreeMarkerView</value>
</property>
<property name="requestContextAttribute" value="request" />
</bean>
<!-- freemarker的配置 -->
<bean id="freemarkerConfig" class="org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer">
<property name="templateLoaderPath">
<value>/WEB-INF/view/</value><!--解析路径-->
</property>
<property name="freemarkerSettings"><!-- 设置FreeMarker环境属性 -->
<props>
<prop key="template_update_delay">5</prop><!--刷新模板的周期,单位为秒 -->
<prop key="default_encoding">UTF-8</prop><!--模板的编码格式 -->
<prop key="locale">UTF-8</prop><!-- 本地化设置 -->
<prop key="datetime_format">yyyy-MM-dd HH:mm:ss</prop>
<prop key="time_format">HH:mm:ss</prop>
<prop key="number_format">0.####</prop>
<prop key="boolean_format">true,false</prop>
<prop key="whitespace_stripping">true</prop>
<prop key="tag_syntax">auto_detect</prop>
<prop key="url_escaping_charset">UTF-8</prop>
<prop key="classic_compatible">true</prop>
<prop key="template_exception_handler">ignore</prop>
<prop key="auto_import">
<!-- 自动装载,引入Freemarker,用于Freemarker Macro引入 -->
/main.html as main
<!--/common/menu.ftl as _menu-->
</prop>
</props>
</property>
</bean>
<!--自定义realm交给Spring IOC 容器管理-->
<bean id="shiroReale" class="com.zhibang.realms.ShiroReale"></bean>
<!--<bean id="authenticator" class="org.apache.shiro.authc.pam.ModularRealmAuthenticator">-->
<!--<property name="realms">-->
<!--<list>-->
<!--<ref bean="shiroReale"/>-->
<!--</list>-->
<!--</property>-->
<!--</bean>-->
<!--<!– 配置多个Realm –>-->
<!--<bean id="authorizer" class="org.apache.shiro.authz.ModularRealmAuthorizer">-->
<!--<property name="realms">-->
<!--<list>-->
<!--<ref bean="shiroReale"/>-->
<!--</list>-->
<!--</property>-->
<!--</bean>-->
<!--缓存管理器交给Soring IOC 容器管理-->
<!--<bean id="cacheManager" class="org.apache.shiro.cache.ehcache.EhCacheManager"></bean>-->
<!--将安全管理器交给Spring IOC 容器管理-->
<bean id="securityManager" class="org.apache.shiro.web.mgt.DefaultWebSecurityManager">
<!--注入自定义realm-->
<property name="realm" ref="shiroReale"></property>
<!--<property name="authenticator" ref="authenticator" />-->
<!--<property name="authorizer" ref="authorizer" />-->
<!--注入缓存管理-->
<!--<property name="cacheManager" ref="cacheManager"></property>-->
</bean>
<!--被web.xml中配置的Filter代理对象代理的类-->
<bean id="shiroFilter" class="org.apache.shiro.spring.web.ShiroFilterFactoryBean">
<!--配置安全管理器-->
<property name="securityManager" ref="securityManager"></property>
<!--如果访问的页面或者是请求地址需要认证才能访问,在没有访问的时候访问了,跳转此地址-->
<property name="loginUrl" value="/tologin"></property>
<!--设置没有授权需要被跳转的地址-->
<property name="unauthorizedUrl" value="/tologin"></property>
<!--设置拦截规则-->
<property name="filterChainDefinitionMap" ref="filterChainDefinitionMap"></property>
</bean>
<!--
3.使用SecurityUtils 将 securityManager 设置到运行环境中
SecurityUtils.setSecurityManager(securityManager);
-->
<!--相当于调用SecurityUtils.setSecurityManager(securityManager);-->
<bean class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
<property name="staticMethod" value="org.apache.shiro.SecurityUtils.setSecurityManager"></property>
<property name="arguments" ref="securityManager"></property>
</bean>
<!--配置一个bean,该bean 实际是一个map,通过实例工厂方法的方式-->
<bean id="filterChainDefinitionMap" factory-bean="filterChainDefinitionMapBuilder" factory-method="buildfilterChainDefinitionMap"></bean>
<bean id="filterChainDefinitionMapBuilder" class="com.zhibang.filter.FilterChainDefinitionMapBuilder"></bean>
</beans>
4.配置web文件
web.xml文件:
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee" version="3.1"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" >
<!--设置欢迎页面-->
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<!--上下文参数-->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath*:applicationContext.xml</param-value>
</context-param>
<!--spring监听器 -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!--前端控制器-->
<servlet>
<servlet-name>yikaoqian</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath*:applicationContext.xml</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>yikaoqian</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<!--配置Druid-->
<servlet>
<servlet-name>druid</servlet-name>
<servlet-class>com.alibaba.druid.support.http.StatViewServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>druid</servlet-name>
<url-pattern>/druid/*</url-pattern>
</servlet-mapping>
<filter>
<filter-name>shiroFilter</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
<!--
参数的意义:
默认targetFilterLifecycle为false,当他为false的时候shiroFilter代理对象默认加入到IOC容器中
并且在IOC容器中遵循IOC的生命周期管理,将其设置为true,让其受tomcat容器生命周期管理
-->
<init-param>
<param-name>targetFilterLifecycle</param-name>
<param-value>true</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>shiroFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>
5.配置filter拦截器
filter配置文件:
package com.zhibang.filter;
import java.util.LinkedHashMap;
public class FilterChainDefinitionMapBuilder {
/**
* 服务对象
*/
// @Autowired
// private static SysUsersService sysUsersService;
public LinkedHashMap<String , String> buildfilterChainDefinitionMap(){
LinkedHashMap<String , String> map = new LinkedHashMap<>();
String name = "管理员";
System.out.println("进了,配置拦截器规则:"+name);
//# anon: shiro的核心过滤器,表示/这个请求,可以匿名访问
map.put("/","anon");
//设置样式不被拦截
// map.put("/jquery/**","anon");
// map.put("/bootstrap/**","anon");
// map.put("/layer/**","anon");
// map.put("/css/**","anon");
//设置登录跳转页面不被拦截
map.put("/tUser/main","anon");
//# authc: shiro的核心过滤器,表示/main必须认证(登陆)才能访问
// map.put("/main","authc");
//# roles: shiro的核心过滤器,表示/main必须拥有admin角色才能访问
// map.put("/main","authc,roles["+name+"]");
//# ** :通配符,表示除了上面配置的拦截,其余的所有请求都需要认证
map.put("/**","authc");
return map;
}
}
6.自定义realms
realms配置文件:
package com.zhibang.realms;
import com.graphbuilder.math.func.PiFunction;
import com.zhibang.model.TPermission;
import com.zhibang.model.TUser;
import com.zhibang.service.TPermissionService;
import com.zhibang.service.TUserService;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.*;
import org.apache.shiro.authz.AuthorizationInfo;
import org.apache.shiro.authz.SimpleAuthorizationInfo;
import org.apache.shiro.realm.AuthorizingRealm;
import org.apache.shiro.session.Session;
import org.apache.shiro.subject.PrincipalCollection;
import org.springframework.beans.factory.annotation.Autowired;
import java.util.*;
public class ShiroReale extends AuthorizingRealm {
/**
* 服务对象
*/
@Autowired
private TUserService tUserService;
@Autowired
private TPermissionService tPermissionService;
/**
* 授权
* 将通过的用户的角色和权限信息设置到对应的用户体上
* @param principalCollection
* @return
*/
@Override
protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principalCollection) {
System.out.println("执行授权.........");
String username = principalCollection.getPrimaryPrincipal().toString();
//模拟从数据库获取当前用户的角色,通过用户名查询该用户拥有的角色名称
List<Map<String, Object>> maps = tUserService.selectRole(username);
HashSet<String> hashSet = new HashSet<>();
Integer uid = 0;
for (Map<String, Object> map : maps) {
uid = Integer.parseInt(map.get("uid").toString());
String r_name = map.get("r_name").toString();
hashSet.add(r_name);
}
//模拟从数据库获取当前用户的权限,通过用户名查询该用户拥有的权限名称
String permissionId = tUserService.getPermissionId(uid);
String[] pid = permissionId.split(",");
List<TPermission> permission = tPermissionService.getPermission(pid);
List<String> list = new ArrayList<>();
for (TPermission tPermission : permission) {
String pname = tPermission.getPname();
list.add(pname);
}
System.out.println("角色名称:"+hashSet);
System.out.println("角色权限:"+list);
SimpleAuthorizationInfo info = new SimpleAuthorizationInfo();
info.addRoles(hashSet);
info.addStringPermissions(list);
//获取session
// ServletRequestAttributes attrs =(ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
// HttpSession session = getRequest().getSession();
// session.setAttribute("authorities",authorities);
// session.setAttribute("role",list);
Session session = SecurityUtils.getSubject().getSession();
session.setAttribute("role", list);
System.out.println("授权完成!");
return info;
}
/**
* 认证
* @param authenticationToken
* @return
* @throws AuthenticationException
*/
@Override
protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken authenticationToken) throws AuthenticationException {
System.out.println("执行认证.........");
UsernamePasswordToken usToken = (UsernamePasswordToken) authenticationToken;
String username = usToken.getUsername();//获取用户输入的用户名
TUser tUser = new TUser();
tUser.setUname(username);
// //使用用户名向数据库中查询数据
TUser tUser1 = tUserService.doLogin(tUser);
String uname = tUser1.getUname();
// //如果用户为空抛出异常在控制器层进行捕获
if(!username.equals(uname)){
throw new AuthenticationException("用户名或密码错误");
}
System.out.println("认证成功!");
// //数据库里面的用户名和密码 ,getname()是ShiroReale的名字
SimpleAuthenticationInfo info = new SimpleAuthenticationInfo(tUser1.getUname(),tUser1.getUpassword(),getName());
return info;
}
}
7.controller控制器
package com.zhibang.controller;
import com.zhibang.model.TPermission;
import com.zhibang.model.TUser;
import com.zhibang.service.TPermissionService;
import com.zhibang.service.TUserService;
import com.zhibang.utils.UserUtils;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.*;
import org.apache.shiro.subject.PrincipalCollection;
import org.apache.shiro.subject.Subject;
import org.springframework.aop.support.AopUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* (TUser)表控制层
*
* @author makejava
* @since 2021-01-09 00:19:28
*/
@Controller
@RequestMapping("tUser")
public class TUserController {
/**
* 服务对象
*/
@Autowired
private TUserService tUserService;
@Autowired
private TPermissionService tPermissionService;
/**
* 通过主键查询单条数据
*
* @param id 主键
* @return 单条数据
*/
@GetMapping("selectOne")
public TUser selectOne(Integer id) {
return this.tUserService.queryById(id);
}
@PostMapping("/main")
@ResponseBody
public Map<String,Object> toLogin(TUser tUser) {
Map<String, Object> map = new HashMap<>();
//获取Shiro实体
Subject subject = SecurityUtils.getSubject();
//使用Shiro提供的API对象封装前端传送过来的请求数据(用户名和密码)
UsernamePasswordToken token = new UsernamePasswordToken(tUser.getUname(),tUser.getUpassword());
System.out.println("进来了");
//调用Shiro提供的方法进行验证
try {
subject.login(token);
}catch (UnknownAccountException uae){
System.out.println("用户名不存在:"+uae.getMessage());
}catch (IncorrectCredentialsException ice){
System.out.println("密码错误:"+ice.getMessage());
}catch (LockedAccountException lae){
System.out.println("用户被锁定:"+lae.getMessage());
}catch (AuthenticationException ae){
// 由自定义Realm抛出,在此捕获
System.out.println("其他异常:"+ae.getMessage());
}
map.put("user", true);
return map;
}
}
8.HTML
<script>
function dologin() {
var uname = $("#uname").val();
var upassword = $("#upassword").val();
// alert(uname)
//非空验证
if (uname == ""){
layer.msg("用户名不能为空", {time:1000, icon:5, shift:6});
return; //结束
}
if(upassword == ""){
layer.msg("密码不能为空", {time:1000, icon:5, shift:6});
return;
}
var index = "";//进度条
$.ajax({
url: "/tUser/main",
type: "post",
data: {
"uname": uname,
"upassword": upassword
},
success: function (res) {
layer.close(index); //关闭加载窗口
console.log("user:" + res.user);
if (res.user){
window.location.href = "main";
}else{
layer.msg("用户名或密码错误!",{time:1000, icon:5, shift:6});
}
},
beforeSend: function(){
index = layer.msg("正在登录中...", {icon:16});
}
});
}
</script>
<form class="form-signin" role="form">
<div class="form-group has-success has-feedback">
<input type="text" class="form-control" id="uname" name="uname" placeholder="请输入登录账号" autofocus>
<span class="glyphicon glyphicon-user form-control-feedback"></span>
</div>
<div class="form-group has-success has-feedback">
<input type="text" class="form-control" name="upassword" id="upassword" placeholder="请输入登录密码" style="margin-top:10px;">
<span class="glyphicon glyphicon-lock form-control-feedback"></span>
</div>
<a class="btn btn-lg btn-success btn-block" onclick="dologin()" > 登录</a>
</form>