login demo

This commit is contained in:
Captain.B 2020-02-13 11:57:26 +08:00
parent 53979cc3b7
commit b70d79bd90
2 changed files with 10 additions and 17 deletions

View File

@ -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");
}

View File

@ -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;
}
}