[seam-commits] Seam SVN: r7700 - in trunk/examples/seamspace: view and 1 other directory.
seam-commits at lists.jboss.org
seam-commits at lists.jboss.org
Wed Mar 26 02:50:58 EDT 2008
Author: shane.bryzak at jboss.com
Date: 2008-03-26 02:50:58 -0400 (Wed, 26 Mar 2008)
New Revision: 7700
Removed:
trunk/examples/seamspace/src/org/jboss/seam/example/seamspace/UserAction.java
Modified:
trunk/examples/seamspace/view/userdetail.xhtml
Log:
UserAction now part of identity management, added first and last name to user creation
Deleted: trunk/examples/seamspace/src/org/jboss/seam/example/seamspace/UserAction.java
===================================================================
--- trunk/examples/seamspace/src/org/jboss/seam/example/seamspace/UserAction.java 2008-03-26 06:50:01 UTC (rev 7699)
+++ trunk/examples/seamspace/src/org/jboss/seam/example/seamspace/UserAction.java 2008-03-26 06:50:58 UTC (rev 7700)
@@ -1,178 +0,0 @@
-package org.jboss.seam.example.seamspace;
-
-import static org.jboss.seam.ScopeType.CONVERSATION;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.jboss.seam.annotations.Begin;
-import org.jboss.seam.annotations.In;
-import org.jboss.seam.annotations.Name;
-import org.jboss.seam.annotations.Scope;
-import org.jboss.seam.core.Conversation;
-import org.jboss.seam.faces.FacesMessages;
-import org.jboss.seam.security.management.IdentityManager;
-
- at Name("userAction")
- at Scope(CONVERSATION)
-public class UserAction
-{
- private String username;
- private String password;
- private String confirm;
- private List<String> roles;
- private boolean enabled;
-
- @In IdentityManager identityManager;
-
- @Begin
- public void createUser()
- {
- roles = new ArrayList<String>();
- }
-
- @Begin
- public void editUser(String username)
- {
- this.username = username;
- roles = identityManager.getGrantedRoles(username);
- enabled = identityManager.isUserEnabled(username);
- }
-
- public String save()
- {
- if (identityManager.userExists(username))
- {
- return saveExistingUser();
- }
- else
- {
- return saveNewUser();
- }
- }
-
- private String saveNewUser()
- {
- if (!password.equals(confirm))
- {
- FacesMessages.instance().addToControl("password", "Passwords do not match");
- return "failure";
- }
-
- boolean success = identityManager.createUser(username, password);
-
- if (success)
- {
- for (String role : roles)
- {
- identityManager.grantRole(username, role);
- }
-
- if (!enabled)
- {
- identityManager.disableUser(username);
- }
-
- Conversation.instance().end();
- }
-
- return "success";
- }
-
- private String saveExistingUser()
- {
- // Check if a new password has been entered
- if (password != null && !"".equals(password))
- {
- if (!password.equals(confirm))
- {
- FacesMessages.instance().addToControl("password", "Passwords do not match");
- return "failure";
- }
- else
- {
- identityManager.changePassword(username, password);
- }
- }
-
- List<String> grantedRoles = identityManager.getGrantedRoles(username);
-
- if (grantedRoles != null)
- {
- for (String role : grantedRoles)
- {
- if (!roles.contains(role)) identityManager.revokeRole(username, role);
- }
- }
-
- for (String role : roles)
- {
- if (grantedRoles == null || !grantedRoles.contains(role))
- {
- identityManager.grantRole(username, role);
- }
- }
-
- if (enabled)
- {
- identityManager.enableUser(username);
- }
- else
- {
- identityManager.disableUser(username);
- }
-
- Conversation.instance().end();
- return "success";
- }
-
- 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 getConfirm()
- {
- return confirm;
- }
-
- public void setConfirm(String confirm)
- {
- this.confirm = confirm;
- }
-
- public List<String> getRoles()
- {
- return roles;
- }
-
- public void setRoles(List<String> roles)
- {
- this.roles = roles;
- }
-
- public boolean isEnabled()
- {
- return enabled;
- }
-
- public void setEnabled(boolean enabled)
- {
- this.enabled = enabled;
- }
-}
Modified: trunk/examples/seamspace/view/userdetail.xhtml
===================================================================
--- trunk/examples/seamspace/view/userdetail.xhtml 2008-03-26 06:50:01 UTC (rev 7699)
+++ trunk/examples/seamspace/view/userdetail.xhtml 2008-03-26 06:50:58 UTC (rev 7700)
@@ -17,6 +17,18 @@
<h:messages globalOnly="true"/>
<h:form>
+
+ <div class="formRow">
+ <h:outputLabel for="firstname" value="First name" styleClass="formLabel"/>
+ <h:inputText id="firstname" value="#{userAction.firstname}" readonly="#{identityManager.userExists(userAction.username)}"/>
+ <div class="validationError"><h:message for="firstname"/></div>
+ </div>
+
+ <div class="formRow">
+ <h:outputLabel for="lastname" value="Last name" styleClass="formLabel"/>
+ <h:inputText id="lastname" value="#{userAction.lastname}" readonly="#{identityManager.userExists(userAction.username)}"/>
+ <div class="validationError"><h:message for="lastname"/></div>
+ </div>
<div class="formRow">
<h:outputLabel for="username" value="Username" styleClass="formLabel"/>
More information about the seam-commits
mailing list