rave-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mpie...@apache.org
Subject svn commit: r1147332 - in /incubator/rave/trunk/rave-portal/src/main: java/org/apache/rave/portal/service/ java/org/apache/rave/portal/service/impl/ java/org/apache/rave/portal/web/controller/ webapp/ webapp/WEB-INF/views/
Date Fri, 15 Jul 2011 22:03:16 GMT
Author: mpierce
Date: Fri Jul 15 22:03:15 2011
New Revision: 1147332

URL: http://svn.apache.org/viewvc?rev=1147332&view=rev
Log:
(Rave-89) Moving account creation out of the NewAccountController and into a service, NewAccountService.
 Moved newaccount.jsp under WEB-INF/views in anticipation of future, better use of Spring
validation features.  Also added exception catching in case of failed account creation (ie
using an already taken user name).


Added:
    incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/portal/service/NewAccountService.java
    incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/portal/service/impl/DefaultNewAccountService.java
    incubator/rave/trunk/rave-portal/src/main/webapp/WEB-INF/views/newaccount.jsp
Removed:
    incubator/rave/trunk/rave-portal/src/main/webapp/newaccount.jsp
Modified:
    incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/portal/web/controller/NewAccountController.java

Added: incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/portal/service/NewAccountService.java
URL: http://svn.apache.org/viewvc/incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/portal/service/NewAccountService.java?rev=1147332&view=auto
==============================================================================
--- incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/portal/service/NewAccountService.java
(added)
+++ incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/portal/service/NewAccountService.java
Fri Jul 15 22:03:15 2011
@@ -0,0 +1,29 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.rave.portal.service;
+
+public interface NewAccountService {
+
+	 /**
+	  * Creates a new account using several other Rave services.
+	  * @param userName is the user name of the new account.
+	  * @param password is the account's password.
+	  */
+	 public void createNewAccount(String userName, String password) throws Exception;
+}
\ No newline at end of file

Added: incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/portal/service/impl/DefaultNewAccountService.java
URL: http://svn.apache.org/viewvc/incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/portal/service/impl/DefaultNewAccountService.java?rev=1147332&view=auto
==============================================================================
--- incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/portal/service/impl/DefaultNewAccountService.java
(added)
+++ incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/portal/service/impl/DefaultNewAccountService.java
Fri Jul 15 22:03:15 2011
@@ -0,0 +1,94 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.rave.portal.service.impl;
+
+import org.apache.rave.portal.service.UserService;
+import org.apache.rave.portal.service.PageService;
+import org.apache.rave.portal.service.PageLayoutService;
+import org.apache.rave.portal.service.RegionService;
+import org.apache.rave.portal.service.NewAccountService;
+import org.apache.rave.portal.model.User;
+import org.apache.rave.portal.model.Page;
+import org.apache.rave.portal.model.PageLayout;
+import org.apache.rave.portal.model.Region;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.util.List;
+import java.util.ArrayList;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+@Service
+public class DefaultNewAccountService implements NewAccountService {
+
+	 protected final Logger logger=LoggerFactory.getLogger(getClass());
+
+    private final UserService userService;
+	 private final PageService pageService;
+	 private final PageLayoutService pageLayoutService;
+	 private final RegionService regionService;
+
+    @Autowired
+    public DefaultNewAccountService(UserService userService, PageService pageService, PageLayoutService
pageLayoutService, RegionService regionService) {
+        this.userService = userService;
+	 	  this.pageService = pageService;
+	 	  this.pageLayoutService = pageLayoutService;
+	 	  this.regionService = regionService;
+    }
+
+	 @Override
+	 public void createNewAccount(String userName, String password) throws Exception {
+		  User user=new User();
+		  user.setUsername(userName);
+		  user.setPassword(password);
+		  
+		  user.setExpired(false);
+		  user.setLocked(false);
+		  user.setEnabled(true);
+		  userService.registerNewUser(user);
+		  
+		  //Return the newly registered user
+		  User registeredUser=userService.getUserByUsername(user.getUsername());
+		  
+		  //Create a PageLayout object.  We will default to 
+		  //the two-column layout
+		  PageLayout pageLayout=pageLayoutService.getPageLayoutByCode("columns_2");
+		  
+		  //Create regions
+		  List<Region> regions=new ArrayList<Region>();
+		  Region region1=new Region();
+		  Region region2=new Region();
+		  regions.add(region1);
+		  regions.add(region2);
+		  
+		  //Create a Page object and register it.
+		  Page page=new Page();
+		  page.setName("main");
+		  page.setOwner(registeredUser);
+		  page.setPageLayout(pageLayout);
+		  page.setRenderSequence(1L);
+		  page.setRegions(regions);
+		  pageService.registerNewPage(page);
+		  
+	 }
+	 
+}
\ No newline at end of file

Modified: incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/portal/web/controller/NewAccountController.java
URL: http://svn.apache.org/viewvc/incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/portal/web/controller/NewAccountController.java?rev=1147332&r1=1147331&r2=1147332&view=diff
==============================================================================
--- incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/portal/web/controller/NewAccountController.java
(original)
+++ incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/portal/web/controller/NewAccountController.java
Fri Jul 15 22:03:15 2011
@@ -19,80 +19,62 @@
 
 package org.apache.rave.portal.web.controller;
 
-import org.apache.rave.portal.service.UserService;
-import org.apache.rave.portal.service.PageService;
-import org.apache.rave.portal.service.PageLayoutService;
-import org.apache.rave.portal.service.RegionService;
+import org.apache.rave.portal.service.NewAccountService;
 import org.apache.rave.portal.web.util.ModelKeys;
 import org.apache.rave.portal.web.util.ViewNames;
-import org.apache.rave.portal.model.User;
-import org.apache.rave.portal.model.Page;
-import org.apache.rave.portal.model.PageLayout;
-import org.apache.rave.portal.model.Region;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Controller;
 import org.springframework.ui.Model;
+import org.springframework.ui.ModelMap;
 import org.springframework.web.bind.annotation.PathVariable;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestMethod;
 import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.ModelAttribute;
+
 import java.util.List;
 import java.util.ArrayList;
 
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
 @Controller
-@RequestMapping(value = { "/newaccount/*", "/newaccount" })
+//@RequestMapping(value = { "/newaccount/*", "/newaccount" })
 public class NewAccountController {
 
-    private final UserService userService;
-	 private final PageService pageService;
-	 private final PageLayoutService pageLayoutService;
-	 private final RegionService regionService;
-	 
-    @Autowired
-    public NewAccountController(UserService userService, PageService pageService, PageLayoutService
pageLayoutService, RegionService regionService) {
-        this.userService = userService;
-		  this.pageService = pageService;
-		  this.pageLayoutService = pageLayoutService;
-		  this.regionService = regionService;
-    }
+	 protected final Logger logger=LoggerFactory.getLogger(getClass());
 
-    @RequestMapping(method = RequestMethod.POST)
-	 //Needs to be specified by action.
-	 //TODO: have a more elegant way of adding a user
-	 public String create(Model model, @RequestParam String userName, @RequestParam String password)
{	  
-	 //Create a new user object and register it.
-		  User user=new User();
-		  user.setUsername(userName);
-		  user.setPassword(password);
-		  user.setExpired(false);
-		  user.setLocked(false);
-		  user.setEnabled(true);
-		  userService.registerNewUser(user);
-		  
-		  //Return the newly registered user
-		  User registeredUser=userService.getUserByUsername(userName);
-		  
-		  //Create a PageLayout object.  We will default to 
-		  //the two-column layout
-		  PageLayout pageLayout=pageLayoutService.getPageLayoutByCode("columns_2");
-
-		  //Create regions
-		  List<Region> regions=new ArrayList<Region>();
-		  Region region1=new Region();
-		  Region region2=new Region();
-		  regions.add(region1);
-		  regions.add(region2);
-
-		  //Create a Page object and register it.
-		  Page page=new Page();
-		  page.setName("main");
-		  page.setOwner(registeredUser);
-		  page.setPageLayout(pageLayout);
-		  page.setRenderSequence(1L);
-								 page.setRegions(regions);
-		  pageService.registerNewPage(page);
+	 private final NewAccountService newAccountService;
 
-        return "redirect:/";
+    @Autowired
+    public NewAccountController(NewAccountService newAccountService) {
+		  this.newAccountService=newAccountService;
     }
 
+    @RequestMapping(value ="/newaccount.jsp", method = RequestMethod.GET)
+	 public String setUpForm(ModelMap model) {
+		  logger.debug("Initializing form");
+		  //TODO this should use view keys like other pages.
+		  return "newaccount";
+	 }
+
+    @RequestMapping(value = { "/newaccount/*","/newaccount"}, method = RequestMethod.POST)
+	 public String create(Model model,@RequestParam String userName, @RequestParam String password,
@RequestParam String passwordConfirm) {	  
+			logger.debug("Creating a new user account");
+
+			 try {
+			    //TODO need to validate input, Spring-style
+				 newAccountService.createNewAccount(userName,password);
+				 return "redirect:/";
+			 }
+											 
+			  //TODO need to handle more specific exceptions
+			  catch (Exception ex) {
+				  logger.error("Account creation failed: "+ex.getMessage());
+				  //TODO: change this to a viewname
+				  return "newaccount";
+			  }
+	 
+		 }
 }
\ No newline at end of file

Added: incubator/rave/trunk/rave-portal/src/main/webapp/WEB-INF/views/newaccount.jsp
URL: http://svn.apache.org/viewvc/incubator/rave/trunk/rave-portal/src/main/webapp/WEB-INF/views/newaccount.jsp?rev=1147332&view=auto
==============================================================================
--- incubator/rave/trunk/rave-portal/src/main/webapp/WEB-INF/views/newaccount.jsp (added)
+++ incubator/rave/trunk/rave-portal/src/main/webapp/WEB-INF/views/newaccount.jsp Fri Jul
15 22:03:15 2011
@@ -0,0 +1,55 @@
+<%--
+  Licensed to the Apache Software Foundation (ASF) under one
+  or more contributor license agreements.  See the NOTICE file
+  distributed with this work for additional information
+  regarding copyright ownership.  The ASF licenses this file
+  to you under the Apache License, Version 2.0 (the
+  "License"); you may not use this file except in compliance
+  with the License.  You may obtain a copy of the License at
+
+      http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing,
+  software distributed under the License is distributed on an
+  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+  KIND, either express or implied.  See the License for the
+  specific language governing permissions and limitations
+  under the License.
+  --%>
+<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
+<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>
+<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
+<%@ taglib tagdir="/WEB-INF/tags" prefix="rave"%>
+  
+<rave:rave_generic_page pageTitle="New Account Application - Rave">
+<div id="content">
+    <h1>Rave Account Application</h1>
+    <form id="newAccountForm" name="newAccountForm" action="newaccount" method="POST">
+        <fieldset>
+            <p>All fields are required</p>
+            <p>
+                <label for="userNameField">Username:</label>
+                <input id="userNameField" type="text" name="userName" required="required"
autofocus="autofocus"/>
+            </p>
+            <p>
+                <label for="passwordField">Password:</label>
+                <input id="passwordField" type="password" name="password" required="required"/>
+            </p>
+            <p>
+                <label for="passwordConfirmField">Confirm Password:</label>
+                <input id="passwordConfirmField" type="password" name="passwordConfirm"
required="required"/>
+            </p>
+        </fieldset>
+        <fieldset>
+             <input type="submit" value="Create Account" />
+        </fieldset>
+    </form>
+</div>
+<script src="//ajax.aspnetcdn.com/ajax/jQuery/jquery-1.6.1.min.js"></script>
+<script src="//ajax.aspnetcdn.com/ajax/jquery.validate/1.8.1/jquery.validate.min.js"></script>
+<script src="<spring:url value="/script/rave.js"/>"></script>
+<script src="<spring:url value="/script/rave_forms.js"/>"></script>
+
+<script>$(document).ready(rave.forms.validateNewAccountForm());</script>
+</rave:rave_generic_page>
+  
\ No newline at end of file



Mime
View raw message