新增用户登陆IP,登陆时间

dep_wangsr
RuoYi 7 years ago committed by Limy
parent 4c92ebf4bf
commit a7aeb93823

@ -51,6 +51,8 @@ create table sys_user (
user_type char(1) default 'N' comment '类型:Y默认用户,N非默认用户', user_type char(1) default 'N' comment '类型:Y默认用户,N非默认用户',
status int(1) default 0 comment '帐号状态:0正常,1禁用', status int(1) default 0 comment '帐号状态:0正常,1禁用',
refuse_des varchar(500) default '' comment '拒绝登录描述', refuse_des varchar(500) default '' comment '拒绝登录描述',
login_ip varchar(100) default '' comment '最后登陆IP',
login_date datetime comment '最后登陆时间',
create_by varchar(64) default '' comment '创建者', create_by varchar(64) default '' comment '创建者',
create_time datetime comment '创建时间', create_time datetime comment '创建时间',
update_by varchar(64) default '' comment '更新者', update_by varchar(64) default '' comment '更新者',
@ -61,8 +63,8 @@ create table sys_user (
-- ---------------------------- -- ----------------------------
-- 初始化-用户信息表数据 -- 初始化-用户信息表数据
-- ---------------------------- -- ----------------------------
insert into sys_user values(1, 106, 'admin', '若依', 'ry@163.com', '15888888888', '1', '', '29c67a30398638269fe600f73a054934', '111111', 'Y', 0, '正常', 'admin', '2018-03-16 11-33-00', 'ry', '2018-03-16 11-33-00'); insert into sys_user values(1, 106, 'admin', '若依', 'ry@163.com', '15888888888', '1', '', '29c67a30398638269fe600f73a054934', '111111', 'Y', 0, '正常', '127.0.0.1', '2018-03-16 11-33-00', 'admin', '2018-03-16 11-33-00', 'ry', '2018-03-16 11-33-00');
insert into sys_user values(2, 108, 'ry', '若依', 'ry@qq.com', '15666666666', '1', '', '8e6d98b90472783cc73c17047ddccf36', '222222', 'N', 0, '正常', 'admin', '2018-03-16 11-33-00', 'ry', '2018-03-16 11-33-00'); insert into sys_user values(2, 108, 'ry', '若依', 'ry@qq.com', '15666666666', '1', '', '8e6d98b90472783cc73c17047ddccf36', '222222', 'N', 0, '正常', '127.0.0.1', '2018-03-16 11-33-00', 'admin', '2018-03-16 11-33-00', 'ry', '2018-03-16 11-33-00');
-- ---------------------------- -- ----------------------------
-- 3、岗位信息表 -- 3、岗位信息表

@ -3,7 +3,6 @@ package com.ruoyi.common.utils;
import java.text.ParseException; import java.text.ParseException;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.Date; import java.util.Date;
import org.apache.commons.lang3.time.DateFormatUtils; import org.apache.commons.lang3.time.DateFormatUtils;
/** /**
@ -23,6 +22,16 @@ public class DateUtils
public static String YYYY_MM_DD_HH_MM_SS = "yyyy-MM-dd HH:mm:ss"; public static String YYYY_MM_DD_HH_MM_SS = "yyyy-MM-dd HH:mm:ss";
/**
* Date
*
* @return Date()
*/
public static Date getNowDate()
{
return new Date();
}
/** /**
* , yyyy-MM-dd * , yyyy-MM-dd
* *

@ -32,7 +32,6 @@ import com.ruoyi.project.system.user.domain.User;
* *
* @author ruoyi * @author ruoyi
*/ */
@Aspect @Aspect
@Component @Component
@EnableAsync @EnableAsync

@ -10,9 +10,11 @@ import com.ruoyi.common.exception.user.CaptchaException;
import com.ruoyi.common.exception.user.UserBlockedException; import com.ruoyi.common.exception.user.UserBlockedException;
import com.ruoyi.common.exception.user.UserNotExistsException; import com.ruoyi.common.exception.user.UserNotExistsException;
import com.ruoyi.common.exception.user.UserPasswordNotMatchException; import com.ruoyi.common.exception.user.UserPasswordNotMatchException;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.MessageUtils; import com.ruoyi.common.utils.MessageUtils;
import com.ruoyi.common.utils.ServletUtils; import com.ruoyi.common.utils.ServletUtils;
import com.ruoyi.common.utils.SystemLogUtils; import com.ruoyi.common.utils.SystemLogUtils;
import com.ruoyi.common.utils.security.ShiroUtils;
import com.ruoyi.project.system.user.domain.User; import com.ruoyi.project.system.user.domain.User;
import com.ruoyi.project.system.user.service.IUserService; import com.ruoyi.project.system.user.service.IUserService;
@ -89,8 +91,8 @@ public class LoginService
SystemLogUtils.log(username, CommonConstant.LOGIN_FAIL, MessageUtils.message("user.blocked", user.getRefuseDes())); SystemLogUtils.log(username, CommonConstant.LOGIN_FAIL, MessageUtils.message("user.blocked", user.getRefuseDes()));
throw new UserBlockedException(user.getRefuseDes()); throw new UserBlockedException(user.getRefuseDes());
} }
SystemLogUtils.log(username, CommonConstant.LOGIN_SUCCESS, MessageUtils.message("user.login.success")); SystemLogUtils.log(username, CommonConstant.LOGIN_SUCCESS, MessageUtils.message("user.login.success"));
recordLoginInfo(user);
return user; return user;
} }
@ -112,4 +114,14 @@ public class LoginService
return true; return true;
} }
/**
*
*/
public void recordLoginInfo(User user)
{
user.setLoginIp(ShiroUtils.getIp());
user.setLoginDate(DateUtils.getNowDate());
userService.updateUser(user);
}
} }

@ -22,7 +22,7 @@ public interface ConfigMapper
/** /**
* *
* *
* @param configName * @param configKey
* @return * @return
*/ */
public Config selectConfigByKey(String configKey); public Config selectConfigByKey(String configKey);

@ -22,7 +22,7 @@ public interface IConfigService
/** /**
* *
* *
* @param configName * @param configKey
* @return * @return
*/ */
public String selectConfigByKey(String configKey); public String selectConfigByKey(String configKey);
@ -78,7 +78,7 @@ public interface IConfigService
/** /**
* *
* *
* @param dept * @param config
* @return * @return
*/ */
public String checkConfigKeyUnique(Config config); public String checkConfigKeyUnique(Config config);

@ -1,6 +1,7 @@
package com.ruoyi.project.system.user.domain; package com.ruoyi.project.system.user.domain;
import java.util.Arrays; import java.util.Arrays;
import java.util.Date;
import org.apache.shiro.crypto.SecureRandomNumberGenerator; import org.apache.shiro.crypto.SecureRandomNumberGenerator;
import com.ruoyi.framework.web.domain.BaseEntity; import com.ruoyi.framework.web.domain.BaseEntity;
import com.ruoyi.project.system.dept.domain.Dept; import com.ruoyi.project.system.dept.domain.Dept;
@ -41,6 +42,10 @@ public class User extends BaseEntity
private int status; private int status;
/** 拒绝登录描述 */ /** 拒绝登录描述 */
private String refuseDes; private String refuseDes;
/** 最后登陆IP */
private String loginIp;
/** 最后登陆时间 */
private Date loginDate;
/** 部门对象 */ /** 部门对象 */
private Dept dept; private Dept dept;
/** 角色组 */ /** 角色组 */
@ -199,6 +204,26 @@ public class User extends BaseEntity
this.refuseDes = refuseDes; this.refuseDes = refuseDes;
} }
public String getLoginIp()
{
return loginIp;
}
public void setLoginIp(String loginIp)
{
this.loginIp = loginIp;
}
public Date getLoginDate()
{
return loginDate;
}
public void setLoginDate(Date loginDate)
{
this.loginDate = loginDate;
}
public Dept getDept() public Dept getDept()
{ {
return dept; return dept;

@ -30,7 +30,7 @@ public interface UserMapper
/** /**
* *
* *
* @param userName * @param phoneNumber
* @return * @return
*/ */
public User selectUserByPhoneNumber(String phoneNumber); public User selectUserByPhoneNumber(String phoneNumber);

@ -30,7 +30,7 @@ public interface IUserService
/** /**
* *
* *
* @param userName * @param phoneNumber
* @return * @return
*/ */
public User selectUserByPhoneNumber(String phoneNumber); public User selectUserByPhoneNumber(String phoneNumber);
@ -103,7 +103,7 @@ public interface IUserService
/** /**
* *
* *
* @param phonenumber * @param user
* @return * @return
*/ */
public String checkPhoneUnique(User user); public String checkPhoneUnique(User user);
@ -112,7 +112,7 @@ public interface IUserService
/** /**
* email * email
* *
* @param email * @param user
* @return * @return
*/ */
public String checkEmailUnique(User user); public String checkEmailUnique(User user);

@ -5,6 +5,7 @@ import java.util.List;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import com.ruoyi.common.constant.UserConstants; import com.ruoyi.common.constant.UserConstants;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.StringUtils; import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.security.ShiroUtils; import com.ruoyi.common.utils.security.ShiroUtils;
import com.ruoyi.framework.shiro.service.PasswordService; import com.ruoyi.framework.shiro.service.PasswordService;
@ -152,7 +153,7 @@ public class UserServiceImpl implements IUserService
{ {
user.setUpdateBy(ShiroUtils.getLoginName()); user.setUpdateBy(ShiroUtils.getLoginName());
// 修改用户信息 // 修改用户信息
count = userMapper.updateUser(user); count = updateUser(user);
// 删除用户与角色关联 // 删除用户与角色关联
userRoleMapper.deleteUserRoleByUserId(userId); userRoleMapper.deleteUserRoleByUserId(userId);
// 新增用户与角色管理 // 新增用户与角色管理
@ -201,7 +202,7 @@ public class UserServiceImpl implements IUserService
{ {
user.randomSalt(); user.randomSalt();
user.setPassword(passwordService.encryptPassword(user.getLoginName(), user.getPassword(), user.getSalt())); user.setPassword(passwordService.encryptPassword(user.getLoginName(), user.getPassword(), user.getSalt()));
return userMapper.updateUser(user); return updateUser(user);
} }
/** /**

@ -18,6 +18,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<result property="userType" column="user_type" /> <result property="userType" column="user_type" />
<result property="status" column="status" /> <result property="status" column="status" />
<result property="refuseDes" column="refuse_des" /> <result property="refuseDes" column="refuse_des" />
<result property="loginIp" column="login_ip" />
<result property="loginDate" column="login_date" />
<result property="createBy" column="create_by" /> <result property="createBy" column="create_by" />
<result property="createTime" column="create_time" /> <result property="createTime" column="create_time" />
<result property="updateBy" column="update_by" /> <result property="updateBy" column="update_by" />
@ -46,7 +48,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</select> </select>
<select id="selectUserByLoginName" parameterType="String" resultMap="UserResult"> <select id="selectUserByLoginName" parameterType="String" resultMap="UserResult">
select u.user_id, u.dept_id, u.login_name, u.user_name, u.email, u.phonenumber, u.sex, u.avatar, u.password, u.salt, u.status, u.refuse_des, u.create_time, select u.user_id, u.dept_id, u.login_name, u.user_name, u.email, u.phonenumber, u.sex, u.avatar, u.password, u.salt, u.status, u.refuse_des, u.login_ip, u.login_date, u.create_time,
d.dept_id, d.parent_id, d.dept_name, d.order_num, d.status as dept_status d.dept_id, d.parent_id, d.dept_name, d.order_num, d.status as dept_status
from sys_user u from sys_user u
left join sys_dept d on u.dept_id = d.dept_id left join sys_dept d on u.dept_id = d.dept_id
@ -55,7 +57,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</select> </select>
<select id="selectUserByPhoneNumber" parameterType="String" resultMap="UserResult"> <select id="selectUserByPhoneNumber" parameterType="String" resultMap="UserResult">
select u.user_id, u.dept_id, u.login_name, u.user_name, u.email, u.phonenumber, u.sex, u.avatar, u.password, u.salt, u.status, u.refuse_des, u.create_time, select u.user_id, u.dept_id, u.login_name, u.user_name, u.email, u.phonenumber, u.sex, u.avatar, u.password, u.salt, u.status, u.refuse_des, u.login_ip, u.login_date, u.create_time,
d.dept_id, d.parent_id, d.dept_name, d.order_num, d.status as dept_status d.dept_id, d.parent_id, d.dept_name, d.order_num, d.status as dept_status
from sys_user u from sys_user u
left join sys_dept d on u.dept_id = d.dept_id left join sys_dept d on u.dept_id = d.dept_id
@ -64,7 +66,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</select> </select>
<select id="selectUserByEmail" parameterType="String" resultMap="UserResult"> <select id="selectUserByEmail" parameterType="String" resultMap="UserResult">
select u.user_id, u.dept_id, u.login_name, u.user_name, u.email, u.phonenumber, u.sex, u.avatar, u.password, u.salt, u.status, u.refuse_des, u.create_time, select u.user_id, u.dept_id, u.login_name, u.user_name, u.email, u.phonenumber, u.sex, u.avatar, u.password, u.salt, u.status, u.refuse_des, u.login_ip, u.login_date, u.create_time,
d.dept_id, d.parent_id, d.dept_name, d.order_num, d.status as dept_status d.dept_id, d.parent_id, d.dept_name, d.order_num, d.status as dept_status
from sys_user u from sys_user u
left join sys_dept d on u.dept_id = d.dept_id left join sys_dept d on u.dept_id = d.dept_id
@ -85,7 +87,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</select> </select>
<select id="selectUserById" parameterType="Long" resultMap="UserResult"> <select id="selectUserById" parameterType="Long" resultMap="UserResult">
select u.user_id, u.dept_id, u.login_name, u.user_name, u.email, u.phonenumber, u.sex, u.avatar, u.password, u.salt, u.status, u.refuse_des, u.create_time, select u.user_id, u.dept_id, u.login_name, u.user_name, u.email, u.phonenumber, u.sex, u.avatar, u.password, u.salt, u.status, u.refuse_des, u.login_ip, u.login_date, u.create_time,
d.dept_id, d.parent_id, d.dept_name, d.order_num, d.status as dept_status d.dept_id, d.parent_id, d.dept_name, d.order_num, d.status as dept_status
from sys_user u from sys_user u
left join sys_dept d on u.dept_id = d.dept_id left join sys_dept d on u.dept_id = d.dept_id
@ -118,6 +120,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="salt != null and salt != ''">salt = #{salt},</if> <if test="salt != null and salt != ''">salt = #{salt},</if>
<if test="status !=null">status = #{status},</if> <if test="status !=null">status = #{status},</if>
<if test="refuseDes != null and refuseDes != ''">refuse_des = #{refuseDes},</if> <if test="refuseDes != null and refuseDes != ''">refuse_des = #{refuseDes},</if>
<if test="loginIp != null and loginIp != ''">login_ip = #{loginIp},</if>
<if test="loginDate != null">login_date = #{loginDate},</if>
<if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if> <if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if>
update_time = sysdate() update_time = sysdate()
</set> </set>

@ -345,6 +345,7 @@ $(function() {
} }
} }
// 点击选项卡菜单
$('.menuTabs').on('click', '.menuTab', activeTab); $('.menuTabs').on('click', '.menuTab', activeTab);
//刷新iframe //刷新iframe

@ -36,7 +36,7 @@
<div class="col-sm-4"> <div class="col-sm-4">
<div class="text-center"> <div class="text-center">
<img alt="image" class="img-circle m-t-xs img-responsive" th:src="(${user.avatar} == '') ? '/img/profile.jpg' : '/profile/' + ${user.avatar}"> <img alt="image" class="img-circle m-t-xs img-responsive" th:src="(${user.avatar} == '') ? '/img/profile.jpg' : '/profile/' + ${user.avatar}">
<div class="m-t-xs font-bold">CEO</div> <div class="m-t-xs font-bold">[[${user.loginIp}]]</div>
</div> </div>
</div> </div>
<div class="col-sm-8"> <div class="col-sm-8">
@ -46,7 +46,7 @@
<p><i class="fa fa-group"></i> [[${user.dept.deptName}]] / [[${#strings.defaultString(postGroup,'无岗位')}]]</p> <p><i class="fa fa-group"></i> [[${user.dept.deptName}]] / [[${#strings.defaultString(postGroup,'无岗位')}]]</p>
<p><i class="fa fa-transgender"></i> [[${user.sex}]]</p> <p><i class="fa fa-transgender"></i> [[${user.sex}]]</p>
<p><i class="fa fa-envelope-o"></i> [[${user.email}]]</p> <p><i class="fa fa-envelope-o"></i> [[${user.email}]]</p>
<p><i class="fa fa-calendar"></i> [[${user.createDateTimeStr}]]</p> <p><i class="fa fa-calendar"></i> [[${#dates.format(user.loginDate, 'yyyy-MM-dd HH:mm:ss')}]]</p>
</div> </div>
<div class="clearfix"></div> <div class="clearfix"></div>
</a> </a>

Loading…
Cancel
Save