mirror of
https://github.com/tencentmusic/supersonic.git
synced 2025-12-11 03:58:14 +00:00
(feature)(auth)Add last_login field to User.
This commit is contained in:
@@ -24,7 +24,7 @@ public class UserWithPassword extends User {
|
|||||||
|
|
||||||
public UserWithPassword(Long id, String name, String displayName, String email, String password,
|
public UserWithPassword(Long id, String name, String displayName, String email, String password,
|
||||||
Integer isAdmin) {
|
Integer isAdmin) {
|
||||||
super(id, name, displayName, email, isAdmin);
|
super(id, name, displayName, email, isAdmin, null);
|
||||||
this.password = password;
|
this.password = password;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ import jakarta.servlet.http.HttpServletRequest;
|
|||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.beans.BeanUtils;
|
import org.springframework.beans.BeanUtils;
|
||||||
|
|
||||||
|
import java.sql.Timestamp;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
@@ -102,7 +103,9 @@ public class DefaultUserAdaptor implements UserAdaptor {
|
|||||||
TokenService tokenService = ContextUtils.getBean(TokenService.class);
|
TokenService tokenService = ContextUtils.getBean(TokenService.class);
|
||||||
try {
|
try {
|
||||||
UserWithPassword user = getUserWithPassword(userReq);
|
UserWithPassword user = getUserWithPassword(userReq);
|
||||||
return tokenService.generateToken(UserWithPassword.convert(user), appKey);
|
String token = tokenService.generateToken(UserWithPassword.convert(user), appKey);
|
||||||
|
updateLastLogin(userReq.getName());
|
||||||
|
return token;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("", e);
|
log.error("", e);
|
||||||
throw new RuntimeException("password encrypt error, please try again");
|
throw new RuntimeException("password encrypt error, please try again");
|
||||||
@@ -267,4 +270,11 @@ public class DefaultUserAdaptor implements UserAdaptor {
|
|||||||
userToken.setExpireDate(userTokenDO.getExpireDateTime());
|
userToken.setExpireDate(userTokenDO.getExpireDateTime());
|
||||||
return userToken;
|
return userToken;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void updateLastLogin(String userName) {
|
||||||
|
UserRepository userRepository = ContextUtils.getBean(UserRepository.class);
|
||||||
|
UserDO userDO = userRepository.getUser(userName);
|
||||||
|
userDO.setLastLogin(new Timestamp(System.currentTimeMillis()));
|
||||||
|
userRepository.updateUser(userDO);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,11 @@ package com.tencent.supersonic.auth.authentication.persistence.dataobject;
|
|||||||
import com.baomidou.mybatisplus.annotation.IdType;
|
import com.baomidou.mybatisplus.annotation.IdType;
|
||||||
import com.baomidou.mybatisplus.annotation.TableId;
|
import com.baomidou.mybatisplus.annotation.TableId;
|
||||||
import com.baomidou.mybatisplus.annotation.TableName;
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.sql.Timestamp;
|
||||||
|
|
||||||
|
@Data
|
||||||
@TableName("s2_user")
|
@TableName("s2_user")
|
||||||
public class UserDO {
|
public class UserDO {
|
||||||
|
|
||||||
@@ -27,71 +31,25 @@ public class UserDO {
|
|||||||
/** */
|
/** */
|
||||||
private Integer isAdmin;
|
private Integer isAdmin;
|
||||||
|
|
||||||
/** @return id */
|
private Timestamp lastLogin;
|
||||||
public Long getId() {
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @param id */
|
|
||||||
public void setId(Long id) {
|
|
||||||
this.id = id;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @return name */
|
|
||||||
public String getName() {
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @param name */
|
/** @param name */
|
||||||
public void setName(String name) {
|
public void setName(String name) {
|
||||||
this.name = name == null ? null : name.trim();
|
this.name = name == null ? null : name.trim();
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @return password */
|
|
||||||
public String getPassword() {
|
|
||||||
return password;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @param password */
|
/** @param password */
|
||||||
public void setPassword(String password) {
|
public void setPassword(String password) {
|
||||||
this.password = password == null ? null : password.trim();
|
this.password = password == null ? null : password.trim();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getSalt() {
|
|
||||||
return salt;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setSalt(String salt) {
|
public void setSalt(String salt) {
|
||||||
this.salt = salt == null ? null : salt.trim();
|
this.salt = salt == null ? null : salt.trim();
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @return display_name */
|
|
||||||
public String getDisplayName() {
|
|
||||||
return displayName;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @param displayName */
|
|
||||||
public void setDisplayName(String displayName) {
|
|
||||||
this.displayName = displayName == null ? null : displayName.trim();
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @return email */
|
|
||||||
public String getEmail() {
|
|
||||||
return email;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @param email */
|
/** @param email */
|
||||||
public void setEmail(String email) {
|
public void setEmail(String email) {
|
||||||
this.email = email == null ? null : email.trim();
|
this.email = email == null ? null : email.trim();
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @return is_admin */
|
|
||||||
public Integer getIsAdmin() {
|
|
||||||
return isAdmin;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @param isAdmin */
|
|
||||||
public void setIsAdmin(Integer isAdmin) {
|
|
||||||
this.isAdmin = isAdmin;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -136,6 +136,9 @@
|
|||||||
<if test="isAdmin != null">
|
<if test="isAdmin != null">
|
||||||
is_admin = #{isAdmin,jdbcType=INTEGER},
|
is_admin = #{isAdmin,jdbcType=INTEGER},
|
||||||
</if>
|
</if>
|
||||||
|
<if test="lastLogin != null">
|
||||||
|
last_login = #{lastLogin,jdbcType=TIMESTAMP},
|
||||||
|
</if>
|
||||||
</set>
|
</set>
|
||||||
where id = #{id,jdbcType=BIGINT}
|
where id = #{id,jdbcType=BIGINT}
|
||||||
</update>
|
</update>
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import lombok.NoArgsConstructor;
|
|||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
import java.sql.Timestamp;
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
@NoArgsConstructor
|
@NoArgsConstructor
|
||||||
@@ -22,26 +23,28 @@ public class User implements Serializable {
|
|||||||
|
|
||||||
private Integer isAdmin;
|
private Integer isAdmin;
|
||||||
|
|
||||||
|
private Timestamp lastLogin;
|
||||||
|
|
||||||
public static User get(Long id, String name, String displayName, String email,
|
public static User get(Long id, String name, String displayName, String email,
|
||||||
Integer isAdmin) {
|
Integer isAdmin) {
|
||||||
return new User(id, name, displayName, email, isAdmin);
|
return new User(id, name, displayName, email, isAdmin, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static User get(Long id, String name) {
|
public static User get(Long id, String name) {
|
||||||
return new User(id, name, name, name, 0);
|
return new User(id, name, name, name, 0, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static User getDefaultUser() {
|
public static User getDefaultUser() {
|
||||||
return new User(1L, "admin", "admin", "admin@email", 1);
|
return new User(1L, "admin", "admin", "admin@email", 1, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static User getVisitUser() {
|
public static User getVisitUser() {
|
||||||
return new User(1L, "visit", "visit", "visit@email", 0);
|
return new User(1L, "visit", "visit", "visit@email", 0, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static User getAppUser(int appId) {
|
public static User getAppUser(int appId) {
|
||||||
String name = String.format("app_%s", appId);
|
String name = String.format("app_%s", appId);
|
||||||
return new User(1L, name, name, "", 1);
|
return new User(1L, name, name, "", 1, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getDisplayName() {
|
public String getDisplayName() {
|
||||||
|
|||||||
@@ -417,4 +417,7 @@ ALTER TABLE s2_model_rela alter column join_condition type text;
|
|||||||
|
|
||||||
--20250310
|
--20250310
|
||||||
ALTER TABLE s2_chat_model add column is_open tinyint DEFAULT NULL COMMENT '是否公开';
|
ALTER TABLE s2_chat_model add column is_open tinyint DEFAULT NULL COMMENT '是否公开';
|
||||||
ALTER TABLE s2_database add column is_open tinyint DEFAULT NULL COMMENT '是否公开';
|
ALTER TABLE s2_database add column is_open tinyint DEFAULT NULL COMMENT '是否公开';
|
||||||
|
|
||||||
|
--20250321
|
||||||
|
ALTER TABLE s2_user add column last_loin datetime DEFAULT NULL;
|
||||||
@@ -129,6 +129,7 @@ create table IF NOT EXISTS s2_user
|
|||||||
salt varchar(256) NULL,
|
salt varchar(256) NULL,
|
||||||
email varchar(100) null,
|
email varchar(100) null,
|
||||||
is_admin INT null,
|
is_admin INT null,
|
||||||
|
last_login TIMESTAMP NULL,
|
||||||
PRIMARY KEY (`id`)
|
PRIMARY KEY (`id`)
|
||||||
);
|
);
|
||||||
COMMENT ON TABLE s2_user IS 'user information table';
|
COMMENT ON TABLE s2_user IS 'user information table';
|
||||||
|
|||||||
@@ -388,6 +388,7 @@ CREATE TABLE IF NOT EXISTS s2_user
|
|||||||
salt varchar(256) DEFAULT NULL COMMENT 'md5密码盐',
|
salt varchar(256) DEFAULT NULL COMMENT 'md5密码盐',
|
||||||
email varchar(100) null,
|
email varchar(100) null,
|
||||||
is_admin tinyint null,
|
is_admin tinyint null,
|
||||||
|
last_login datetime DEFAULT NULL,
|
||||||
UNIQUE (`name`),
|
UNIQUE (`name`),
|
||||||
PRIMARY KEY (`id`)
|
PRIMARY KEY (`id`)
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -498,5 +498,6 @@ CREATE TABLE IF NOT EXISTS s2_user (
|
|||||||
salt varchar(256) DEFAULT NULL,
|
salt varchar(256) DEFAULT NULL,
|
||||||
email varchar(100) NULL,
|
email varchar(100) NULL,
|
||||||
is_admin smallint NULL,
|
is_admin smallint NULL,
|
||||||
|
last_login timestamp NULL,
|
||||||
UNIQUE(name)
|
UNIQUE(name)
|
||||||
);
|
);
|
||||||
Reference in New Issue
Block a user