feat: finish bilingual session auth learning lab
This commit is contained in:
@@ -1,20 +1,25 @@
|
||||
package com.demo.action;
|
||||
|
||||
import com.opensymphony.xwork2.ActionSupport;
|
||||
import org.apache.struts2.interceptor.SessionAware;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.Map;
|
||||
|
||||
public class LoginAction extends ActionSupport {
|
||||
public class LoginAction extends ActionSupport implements SessionAware {
|
||||
|
||||
public static final String SESSION_USER = "demoUser";
|
||||
public static final String SESSION_ROLE = "demoRole";
|
||||
public static final String SESSION_LOGIN_TIME = "demoLoginTime";
|
||||
|
||||
private static final DateTimeFormatter TIME_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
||||
|
||||
private Map<String, Object> session;
|
||||
private String username;
|
||||
private String password;
|
||||
private String displayName;
|
||||
private String role;
|
||||
private String loginTime;
|
||||
private String recommendation;
|
||||
|
||||
@Override
|
||||
public String execute() {
|
||||
@@ -26,14 +31,15 @@ public class LoginAction extends ActionSupport {
|
||||
}
|
||||
|
||||
if ("admin".equals(username) && "123456".equals(password)) {
|
||||
displayName = "System Demo Admin";
|
||||
role = "Administrator";
|
||||
displayName = "ops-admin";
|
||||
loginTime = LocalDateTime.now().format(TIME_FORMATTER);
|
||||
recommendation = "Continue with the user form, validation sample, or upload flow to explore the rest of the demo.";
|
||||
session.put(SESSION_USER, displayName);
|
||||
session.put(SESSION_ROLE, "admin");
|
||||
session.put(SESSION_LOGIN_TIME, loginTime);
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
addActionError("Invalid demo credentials. Use admin / 123456.");
|
||||
addActionError("演示账号不正确,请使用 admin / 123456。 / Invalid demo credentials. Use admin / 123456.");
|
||||
return INPUT;
|
||||
}
|
||||
|
||||
@@ -43,10 +49,10 @@ public class LoginAction extends ActionSupport {
|
||||
return;
|
||||
}
|
||||
if (username == null || username.length() < 3) {
|
||||
addFieldError("username", "Username must be at least 3 characters.");
|
||||
addFieldError("username", "用户名至少 3 个字符。 / Username must be at least 3 characters.");
|
||||
}
|
||||
if (password == null || password.length() < 6) {
|
||||
addFieldError("password", "Password must be at least 6 characters.");
|
||||
addFieldError("password", "密码至少 6 个字符。 / Password must be at least 6 characters.");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -79,15 +85,12 @@ public class LoginAction extends ActionSupport {
|
||||
return displayName;
|
||||
}
|
||||
|
||||
public String getRole() {
|
||||
return role;
|
||||
}
|
||||
|
||||
public String getLoginTime() {
|
||||
return loginTime;
|
||||
}
|
||||
|
||||
public String getRecommendation() {
|
||||
return recommendation;
|
||||
@Override
|
||||
public void setSession(Map<String, Object> session) {
|
||||
this.session = session;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user