添加了登录状态属性,为在header中添加登录相关按钮做准备
This commit is contained in:
parent
69b48c30ec
commit
a26818f107
@ -24,6 +24,7 @@ public class ProjectBean implements Serializable {
|
||||
private UserInfo userInfo; // User info for the current user
|
||||
private String username;
|
||||
private String password;
|
||||
private boolean isLoggedIn = false;
|
||||
public String projectKeywords = ""; // String to hold project keywords
|
||||
public String newKeyword = "";
|
||||
public String projectCollaborators = ""; // String to hold project collaborators
|
||||
@ -136,12 +137,16 @@ public class ProjectBean implements Serializable {
|
||||
}
|
||||
|
||||
public String register() {
|
||||
isLoggedIn = false;
|
||||
try {
|
||||
databaseService.registerUser(username, password);
|
||||
} catch (SQLException e) {
|
||||
FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, "Registration failed", null));
|
||||
return "register";
|
||||
}
|
||||
FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_INFO, "Registration succeeded", null));
|
||||
FacesContext.getCurrentInstance().getExternalContext().getSessionMap().remove("username");
|
||||
FacesContext.getCurrentInstance().getExternalContext().getSessionMap().remove("password");
|
||||
return "login";
|
||||
}
|
||||
|
||||
@ -151,12 +156,18 @@ public class ProjectBean implements Serializable {
|
||||
FacesContext.getCurrentInstance().getExternalContext().getSessionMap().put("username", username);
|
||||
loadUserInfo();
|
||||
loadProjects();
|
||||
return "project";
|
||||
isLoggedIn = true;
|
||||
return "index";
|
||||
} else {
|
||||
FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, "Login failed", null));
|
||||
FacesContext.getCurrentInstance().getExternalContext().getSessionMap().remove("username");
|
||||
isLoggedIn = false;
|
||||
return "login";
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, "Login failed", null));
|
||||
FacesContext.getCurrentInstance().getExternalContext().getSessionMap().remove("username");
|
||||
isLoggedIn = false;
|
||||
e.printStackTrace();
|
||||
return "login";
|
||||
}
|
||||
@ -164,6 +175,7 @@ public class ProjectBean implements Serializable {
|
||||
|
||||
public String logout() {
|
||||
FacesContext.getCurrentInstance().getExternalContext().invalidateSession();
|
||||
isLoggedIn = false;
|
||||
return "index";
|
||||
}
|
||||
|
||||
@ -239,4 +251,12 @@ public class ProjectBean implements Serializable {
|
||||
public void setNewKeyword(String newKeyword) {
|
||||
this.newKeyword = newKeyword;
|
||||
}
|
||||
|
||||
public boolean isLoggedIn() {
|
||||
return isLoggedIn;
|
||||
}
|
||||
|
||||
public void setLoggedIn(boolean loggedIn) {
|
||||
isLoggedIn = loggedIn;
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user