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