94 lines
2.4 KiB
Java
94 lines
2.4 KiB
Java
package com.demo.action;
|
|
|
|
import com.opensymphony.xwork2.ActionSupport;
|
|
|
|
import java.time.LocalDateTime;
|
|
import java.time.format.DateTimeFormatter;
|
|
|
|
public class LoginAction extends ActionSupport {
|
|
|
|
private static final DateTimeFormatter TIME_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
|
|
|
private String username;
|
|
private String password;
|
|
private String displayName;
|
|
private String role;
|
|
private String loginTime;
|
|
private String recommendation;
|
|
|
|
@Override
|
|
public String execute() {
|
|
username = normalize(username);
|
|
password = normalize(password);
|
|
|
|
if (!hasSubmitted()) {
|
|
return INPUT;
|
|
}
|
|
|
|
if ("admin".equals(username) && "123456".equals(password)) {
|
|
displayName = "System Demo Admin";
|
|
role = "Administrator";
|
|
loginTime = LocalDateTime.now().format(TIME_FORMATTER);
|
|
recommendation = "Continue with the user form, validation sample, or upload flow to explore the rest of the demo.";
|
|
return SUCCESS;
|
|
}
|
|
|
|
addActionError("Invalid demo credentials. Use admin / 123456.");
|
|
return INPUT;
|
|
}
|
|
|
|
@Override
|
|
public void validate() {
|
|
if (!hasSubmitted()) {
|
|
return;
|
|
}
|
|
if (username == null || username.length() < 3) {
|
|
addFieldError("username", "Username must be at least 3 characters.");
|
|
}
|
|
if (password == null || password.length() < 6) {
|
|
addFieldError("password", "Password must be at least 6 characters.");
|
|
}
|
|
}
|
|
|
|
private boolean hasSubmitted() {
|
|
return (username != null && !username.trim().isEmpty())
|
|
|| (password != null && !password.trim().isEmpty());
|
|
}
|
|
|
|
private String normalize(String value) {
|
|
return value == null ? null : value.trim();
|
|
}
|
|
|
|
public String getUsername() {
|
|
return username;
|
|
}
|
|
|
|
public void setUsername(String username) {
|
|
this.username = username;
|
|
}
|
|
|
|
public String getPassword() {
|
|
return password;
|
|
}
|
|
|
|
public void setPassword(String password) {
|
|
this.password = password;
|
|
}
|
|
|
|
public String getDisplayName() {
|
|
return displayName;
|
|
}
|
|
|
|
public String getRole() {
|
|
return role;
|
|
}
|
|
|
|
public String getLoginTime() {
|
|
return loginTime;
|
|
}
|
|
|
|
public String getRecommendation() {
|
|
return recommendation;
|
|
}
|
|
}
|