Author: amarkhel
Date: 2009-05-07 08:02:11 -0400 (Thu, 07 May 2009)
New Revision: 14058
Modified:
trunk/examples/photoalbum/source/web/src/main/java/org/richfaces/photoalbum/manager/Authenticator.java
trunk/examples/photoalbum/source/web/src/main/webapp/WEB-INF/pages.xml
trunk/examples/photoalbum/source/web/src/main/webapp/includes/index/header.xhtml
trunk/examples/photoalbum/source/web/src/main/webapp/includes/index/login.xhtml
trunk/examples/photoalbum/source/web/src/main/webapp/includes/index/menu.xhtml
trunk/examples/photoalbum/source/web/src/main/webapp/includes/index/tree.xhtml
trunk/examples/photoalbum/source/web/src/main/webapp/includes/search/searchWidget.xhtml
trunk/examples/photoalbum/source/web/src/main/webapp/includes/shelfUnvisited.xhtml
trunk/examples/photoalbum/source/web/src/main/webapp/includes/userPrefs/userPrefsEdit.xhtml
trunk/examples/photoalbum/source/web/src/main/webapp/index.html
Log:
Modified:
trunk/examples/photoalbum/source/web/src/main/java/org/richfaces/photoalbum/manager/Authenticator.java
===================================================================
---
trunk/examples/photoalbum/source/web/src/main/java/org/richfaces/photoalbum/manager/Authenticator.java 2009-05-07
12:01:57 UTC (rev 14057)
+++
trunk/examples/photoalbum/source/web/src/main/java/org/richfaces/photoalbum/manager/Authenticator.java 2009-05-07
12:02:11 UTC (rev 14058)
@@ -31,6 +31,7 @@
import org.jboss.seam.ScopeType;
import org.jboss.seam.annotations.In;
import org.jboss.seam.annotations.Name;
+import org.jboss.seam.annotations.Out;
import org.jboss.seam.annotations.Scope;
import org.jboss.seam.annotations.web.RequestParameter;
import org.jboss.seam.contexts.Contexts;
@@ -45,160 +46,160 @@
@Name("authenticator")
@Scope(ScopeType.CONVERSATION)
-public class Authenticator implements Serializable{
+public class Authenticator implements Serializable {
private static final long serialVersionUID = -4585673256547342140L;
- @RequestParameter protected Long startConversation;
-
- @In Identity identity;
-
- @In Credentials credentials;
-
- @In FacesMessages facesMessages;
-
- @In IUserAction userAction;
-
+ @RequestParameter
+ protected Long startConversation;
+
+ @In
+ @Out
+ User user;
+
+ @In
+ Identity identity;
+
+ @In
+ Credentials credentials;
+
+ @In
+ FacesMessages facesMessages;
+
+ @In
+ IUserAction userAction;
+
private boolean loginFailed = false;
-
- public void login(){
- if(identity.hasRole(Constants.ADMIN_ROLE)){
- return;
+
+ private boolean conversationStarted = false;
+
+ public boolean needStartConversation() {
+ if (identity.isLoggedIn()) {
+ setConversationStarted(true);
}
- String password = credentials.getPassword();
- String username = credentials.getUsername();
- identity.unAuthenticate();
- credentials.setPassword(password);
- credentials.setUsername(username);
+ return user.getId() == null && !isConversationStarted();
+ }
+
+ public boolean authenticate() {
try {
- identity.authenticate();
- } catch (LoginException e) {
+ user = userAction.login(credentials.getUsername(), HashUtils
+ .hash(credentials.getPassword()));
+ if (user != null) {
+ identity.addRole(Constants.ADMIN_ROLE);
+ Events.instance().raiseEvent(Constants.AUTHENTICATED_EVENT,
+ user);
+ setLoginFailed(false);
+ return true;
+ }
+ } catch (Exception nre) {
setLoginFailed(true);
- credentials.clear();
- loginAnonymous();
facesMessages.clear();
facesMessages.add(Constants.INVALID_LOGIN_OR_PASSWORD);
FacesContext.getCurrentInstance().renderResponse();
+ return false;
}
+ return false;
}
- public void register(User user){
- if(checkPassword(user) || checkUserExist(user)){
- return;
- }
- user.setPasswordHash(HashUtils.hash(user.getPassword()));
- user.setPreDefined(false);
- File avatarData =
(File)Contexts.getConversationContext().get(Constants.AVATAR_DATA_COMPONENT);
- if(avatarData != null){
- user.setHasAvatar(true);
- FileManager fileManager =
(FileManager)Contexts.getApplicationContext().get(Constants.FILE_MANAGER_COMPONENT);
- if(fileManager == null || !fileManager.saveAvatar(avatarData, user)){
- Events.instance().raiseEvent(Constants.ADD_ERROR_EVENT,
Constants.AVATAR_SAVING_ERROR);
- return;
- }
- }
- try{
- userAction.register(user);
- }
- catch(Exception e){
- return;
- }
- credentials.setPassword(user.getPassword());
- credentials.setUsername(user.getLogin());
- login();
+ public String logout() {
+ identity.logout();
+ setConversationStarted(false);
+ return Constants.LOGOUT_OUTCOME;
+ }
- }
-
- public void goToRegister(){
+ public void register(User user) {
+ if (checkPassword(user) || checkUserExist(user)
+ || checkEmailExist(user.getEmail())) {
+ return;
+ }
+ user.setPasswordHash(HashUtils.hash(user.getPassword()));
+ user.setPreDefined(false);
+ File avatarData = (File) Contexts.getConversationContext().get(
+ Constants.AVATAR_DATA_COMPONENT);
+ if (avatarData != null) {
+ user.setHasAvatar(true);
+ FileManager fileManager = (FileManager) Contexts
+ .getApplicationContext().get(
+ Constants.FILE_MANAGER_COMPONENT);
+ if (fileManager == null
+ || !fileManager.saveAvatar(avatarData, user)) {
+ Events.instance().raiseEvent(Constants.ADD_ERROR_EVENT,
+ Constants.AVATAR_SAVING_ERROR);
+ return;
+ }
+ }
+ try {
+ userAction.register(user);
+ } catch (Exception e) {
+ Events.instance().raiseEvent(Constants.ADD_ERROR_EVENT,
+ Constants.REGISTRATION_ERROR);
+ return;
+ }
+ credentials.setPassword(user.getPassword());
+ credentials.setUsername(user.getLogin());
+ try {
+ identity.authenticate();
+ } catch (LoginException e) {
+ Events.instance().raiseEvent(Constants.ADD_ERROR_EVENT,
+ Constants.LOGIN_ERROR);
+ }
+
+ }
+
+ public void goToRegister() {
Contexts.getSessionContext().set("user", new User());
- Contexts.getConversationContext().set(Constants.AVATAR_DATA_COMPONENT, null);
- setLoginFailed(false);
- Events.instance().raiseEvent(Constants.START_REGISTER_EVENT);
- }
-
+ Contexts.getConversationContext().set(Constants.AVATAR_DATA_COMPONENT,
+ null);
+ setLoginFailed(false);
+ Events.instance().raiseEvent(Constants.START_REGISTER_EVENT);
+ }
+
private boolean checkUserExist(User user) {
- if(userAction.isUserExist(user.getLogin())){
- addFacesMessage(Constants.REGISTER_LOGIN_NAME_ID,
Constants.USER_WITH_THIS_LOGIN_ALREADY_EXIST);
- return true;
- }
+ if (userAction.isUserExist(user.getLogin())) {
+ addFacesMessage(Constants.REGISTER_LOGIN_NAME_ID,
+ Constants.USER_WITH_THIS_LOGIN_ALREADY_EXIST);
+ return true;
+ }
return false;
}
- private void addFacesMessage(String componentId, String message ) {
+ private boolean checkEmailExist(String email) {
+ if (userAction.isEmailExist(email)) {
+ addFacesMessage(Constants.REGISTER_EMAIL_ID,
+ Constants.USER_WITH_THIS_EMAIL_ALREADY_EXIST);
+ return true;
+ }
+ return false;
+ }
+
+ private void addFacesMessage(String componentId, String message) {
UIComponent root = FacesContext.getCurrentInstance().getViewRoot();
UIComponent component = root.findComponent(componentId);
- FacesContext.getCurrentInstance().addMessage(component.getClientId(FacesContext.getCurrentInstance()),
new FacesMessage(
- FacesMessage.SEVERITY_ERROR, message , message));
+ FacesContext
+ .getCurrentInstance()
+ .addMessage(
+ component
+ .getClientId(FacesContext.getCurrentInstance()),
+ new FacesMessage(FacesMessage.SEVERITY_ERROR, message,
+ message));
}
private boolean checkPassword(User user) {
- if(!user.getPassword().equals(user.getConfirmPassword())){
- addFacesMessage(Constants.REGISTER_CONFIRM_PASSWORD_ID,
Constants.CONFIRM_PASSWORD_NOT_EQUALS_PASSWORD);
+ if (!user.getPassword().equals(user.getConfirmPassword())) {
+ addFacesMessage(Constants.REGISTER_CONFIRM_PASSWORD_ID,
+ Constants.CONFIRM_PASSWORD_NOT_EQUALS_PASSWORD);
return true;
- }
+ }
return false;
}
-
- public boolean authenticate()
- {
- if (wantLoginAnonymous()) {
- return loginAnonymous();
- }
- try {
- User user = userAction.login(credentials.getUsername(),
HashUtils.hash(credentials.getPassword()));
- if (user != null) {
- identity.addRole(Constants.ADMIN_ROLE);
- Events.instance().raiseEvent(Constants.AUTHENTICATED_EVENT, user);
- setLoginFailed(false);
- Contexts.getSessionContext().set(Constants.USER_VARIABLE, user);
- return true;
- }
- } catch (Exception nre) {
- return false;
- }
- return false;
- }
- private boolean loginAnonymous() {
- identity.addRole(Constants.GUEST_ROLE);
- Events.instance().raiseEvent(Constants.UPDATE_MAIN_AREA_EVENT, NavigationEnum.ANONYM);
- return true;
- }
-
- public String logout(){
- identity.logout();
- return Constants.LOGOUT_OUTCOME;
- }
-
- public String startConversation(){
- if(!identity.isLoggedIn()){
- credentials.clear();
- try {
- identity.authenticate();
- } catch (LoginException e) {
- //No cases for that
- }
- }
- return "";
- }
-
- public String destroyConversation(){
- if(identity.isLoggedIn()){
- identity.logout();
- }else{
- identity.unAuthenticate();
- }
+ public String startConversation() {
+ Events.instance().raiseEvent(Constants.UPDATE_MAIN_AREA_EVENT,
+ NavigationEnum.ANONYM);
+ setConversationStarted(true);
return "";
- }
-
- private boolean wantLoginAnonymous() {
- return null == credentials.getUsername() ||
credentials.getUsername().equals("");
}
- public Long getStartConversation() {
- return startConversation;
- }
-
public boolean isLoginFailed() {
return loginFailed;
}
@@ -206,4 +207,12 @@
public void setLoginFailed(boolean loginFailed) {
this.loginFailed = loginFailed;
}
+
+ public boolean isConversationStarted() {
+ return conversationStarted;
+ }
+
+ public void setConversationStarted(boolean conversationStarted) {
+ this.conversationStarted = conversationStarted;
+ }
}
\ No newline at end of file
Modified: trunk/examples/photoalbum/source/web/src/main/webapp/WEB-INF/pages.xml
===================================================================
--- trunk/examples/photoalbum/source/web/src/main/webapp/WEB-INF/pages.xml 2009-05-07
12:01:57 UTC (rev 14057)
+++ trunk/examples/photoalbum/source/web/src/main/webapp/WEB-INF/pages.xml 2009-05-07
12:02:11 UTC (rev 14058)
@@ -4,9 +4,8 @@
xsi:schemaLocation="http://jboss.com/products/seam/pages
http://jboss.com/products/seam/pages-2.1.xsd">
<page view-id="/index.xhtml">
- <begin-conversation if="#{!identity.isLoggedIn()}"/>
- <action if="#{authenticator.startConversation!=null}"
execute="#{authenticator.destroyConversation}"/>
- <action if="#{!identity.isLoggedIn()}"
execute="#{authenticator.startConversation}"/>
+ <begin-conversation if="#{!conversation.longRunning and
authenticator.needStartConversation()}"/>
+ <action if="#{user.id == null and !authenticator.conversationStarted}"
execute="#{authenticator.startConversation}"/>
<navigation from-action="#{authenticator.logout}">
<rule if-outcome="logout">
<end-conversation />
Modified:
trunk/examples/photoalbum/source/web/src/main/webapp/includes/index/header.xhtml
===================================================================
(Binary files differ)
Modified: trunk/examples/photoalbum/source/web/src/main/webapp/includes/index/login.xhtml
===================================================================
(Binary files differ)
Modified: trunk/examples/photoalbum/source/web/src/main/webapp/includes/index/menu.xhtml
===================================================================
(Binary files differ)
Modified: trunk/examples/photoalbum/source/web/src/main/webapp/includes/index/tree.xhtml
===================================================================
(Binary files differ)
Modified:
trunk/examples/photoalbum/source/web/src/main/webapp/includes/search/searchWidget.xhtml
===================================================================
(Binary files differ)
Modified:
trunk/examples/photoalbum/source/web/src/main/webapp/includes/shelfUnvisited.xhtml
===================================================================
(Binary files differ)
Modified:
trunk/examples/photoalbum/source/web/src/main/webapp/includes/userPrefs/userPrefsEdit.xhtml
===================================================================
(Binary files differ)
Modified: trunk/examples/photoalbum/source/web/src/main/webapp/index.html
===================================================================
--- trunk/examples/photoalbum/source/web/src/main/webapp/index.html 2009-05-07 12:01:57
UTC (rev 14057)
+++ trunk/examples/photoalbum/source/web/src/main/webapp/index.html 2009-05-07 12:02:11
UTC (rev 14058)
@@ -1,5 +1,5 @@
<html>
<head>
- <meta http-equiv="Refresh" content="0;
URL=index.seam?startConversation=1">
+ <meta http-equiv="Refresh" content="0; URL=index.seam">
</head>
</html>
\ No newline at end of file