From b70d79bd90f604815dd00101946ff6fd81156950 Mon Sep 17 00:00:00 2001 From: "Captain.B" Date: Thu, 13 Feb 2020 11:57:26 +0800 Subject: [PATCH] login demo --- .../controller/LoginController.java | 3 ++- .../java/io/metersphere/user/SessionUser.java | 24 +++++++------------ 2 files changed, 10 insertions(+), 17 deletions(-) diff --git a/backend/src/main/java/io/metersphere/controller/LoginController.java b/backend/src/main/java/io/metersphere/controller/LoginController.java index 4cb84d1e4e..5099706ff5 100644 --- a/backend/src/main/java/io/metersphere/controller/LoginController.java +++ b/backend/src/main/java/io/metersphere/controller/LoginController.java @@ -35,7 +35,8 @@ public class LoginController { try { subject.login(token); if (subject.isAuthenticated()) { - return ResultHolder.success(""); + // 返回 userDTO + return ResultHolder.success(subject.getSession().getAttribute("user")); } else { return ResultHolder.error("login fail"); } diff --git a/backend/src/main/java/io/metersphere/user/SessionUser.java b/backend/src/main/java/io/metersphere/user/SessionUser.java index 0a36e97649..187a39621f 100644 --- a/backend/src/main/java/io/metersphere/user/SessionUser.java +++ b/backend/src/main/java/io/metersphere/user/SessionUser.java @@ -1,26 +1,18 @@ package io.metersphere.user; +import io.metersphere.dto.UserDTO; +import org.springframework.beans.BeanUtils; + import java.io.Serializable; -public class SessionUser implements Serializable { +public class SessionUser extends UserDTO implements Serializable { private static final long serialVersionUID = -7149638440406959033L; - private String id; - private String name; - public String getId() { - return id; + public static SessionUser fromUser(UserDTO user) { + SessionUser sessionUser = new SessionUser(); + BeanUtils.copyProperties(user, sessionUser); + return sessionUser; } - public void setId(String id) { - this.id = id; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } }