View Javadoc
1   /******************************************************************************
2    * HelloPageController.java - The Spring controller for the hello page (anonymous home page)
3    * 
4    * BSAccountMan - BuckoSoft Web Account Manager Manager 
5    * Copyright(c) 2013 - Dick Balaska and BuckoSoft, Corp.
6    * 
7    */
8   package com.buckosoft.BSAccountMan.web;
9   
10  import javax.servlet.http.HttpServletRequest;
11  
12  import org.apache.commons.logging.Log;
13  import org.apache.commons.logging.LogFactory;
14  import org.springframework.beans.factory.annotation.Autowired;
15  import org.springframework.stereotype.Controller;
16  import org.springframework.ui.Model;
17  import org.springframework.web.bind.annotation.RequestMapping;
18  import org.springframework.web.bind.annotation.RequestParam;
19  
20  import com.buckosoft.BSAccount.BSAccountMan;
21  import com.buckosoft.BSAccount.domain.BSAccount;
22  import com.buckosoft.BSAccount.domain.BSAccountUser;
23  import com.buckosoft.BSAccount.domain.BSAccountUserWebSession;
24  import com.buckosoft.BSAccountMan.util.ConfigManager;
25  import com.buckosoft.BSWebLinks.BSWebLinksMan;
26  
27  /** Control the hello.do page, determine whether to redirect to home.do
28   * 
29   * @author dick
30   *
31   */
32  @Controller
33  public class HelloPageController {
34  	private final Log log = LogFactory.getLog(getClass());
35  
36  	// for the compass
37  	final private static String myWebUri = "/BSAccountMan/"; 
38  
39  	@Autowired
40  	private BSWebLinksMan	bsWebLinksMan;
41  
42  	@Autowired
43  	private	BSAccountMan	bsAccountMan;
44  
45  //	private BSAccountManMan	bsAccountManMan;
46  
47  	private	boolean	compressJS;
48  	private	boolean debugJS;
49  	
50  	public HelloPageController() {
51  		compressJS = ConfigManager.getBoolean("BSAccountMan.compressJS", true);
52  		debugJS = ConfigManager.getBoolean("BSAccountMan.debugJS", false);
53  		
54  	}
55  
56  	/**
57  	 * @param webLinksMan the bSWebLinksMan to set
58  	 */
59  	public void setBsWebLinksMan(BSWebLinksMan webLinksMan) {
60  		bsWebLinksMan = webLinksMan;
61  		bsWebLinksMan.setCompassTextDiv("compassTextDiv");
62  	}
63  
64  	/**
65  	 * @param bsAccountMan the bsAccountMan to set
66  	 */
67  	public void setBsAccountMan(BSAccountMan bsAccountMan) {
68  		this.bsAccountMan = bsAccountMan;
69  	}
70  
71  	@RequestMapping("/")
72  	public String handleRequest(HttpServletRequest request, Model model) {
73  
74  		BSAccountUserWebSession userWebSession = this.bsAccountMan.getUserWebSession(request);
75  		log.debug("userWebSession = " + userWebSession);
76  		model.addAttribute("userWebSession", userWebSession);
77  		model.addAttribute("compressJS", compressJS);
78  		model.addAttribute("debugJS", debugJS);
79  		model.addAttribute("appName", this.bsAccountMan.getAppName());
80  
81  		bsWebLinksMan.setCompassTextDiv("compassTextDiv");
82  		String s = bsWebLinksMan.getWebPageHead(request, myWebUri);
83  		model.addAttribute("compassHead", s);
84  		if (debugJS) {
85  			log.debug("************************  HEAD ********************");
86  			log.debug(s);
87  		}
88  		s = bsWebLinksMan.getWebPageBody(request, myWebUri);
89  		//		if (debugJS) {
90  		//			log.debug("************************  BODY ********************");
91  		//			log.debug(s);
92  		//		}
93  		model.addAttribute("compassBody", s);
94  
95  		return("hello");
96  
97  	}
98  	
99  	@RequestMapping("/forgotPassword")
100 	public String forgotPassword(HttpServletRequest request, Model model,
101 			@RequestParam("app") String appName) {
102 	
103       	BSAccountUserWebSession userWebSession = this.bsAccountMan.getUserWebSession(request);
104        	log.debug("userWebSession = " + userWebSession);
105      	model.addAttribute("userWebSession", userWebSession);
106 		model.addAttribute("compressJS", compressJS);
107 		model.addAttribute("debugJS", debugJS);
108 		model.addAttribute("appName", appName);
109 		return("forgotPassword");
110 	}
111 	
112 	@RequestMapping("/newUser")
113 	public String newUser(HttpServletRequest request, Model model,
114 			@RequestParam("app") String appName) {
115 	
116       	BSAccountUserWebSession userWebSession = this.bsAccountMan.getUserWebSession(request);
117        	log.debug("userWebSession = " + userWebSession);
118      	model.addAttribute("userWebSession", userWebSession);
119 		model.addAttribute("compressJS", compressJS);
120 		model.addAttribute("debugJS", debugJS);
121 		model.addAttribute("appName", appName);
122 		if (userWebSession.isLoggedIn())
123 			return("newUserBad");
124 		return("newUser");
125 	}
126 
127 	@RequestMapping("/editUser")
128 	public String editUser(HttpServletRequest request, Model model,
129 			@RequestParam("app") String appName) {
130 
131 		BSAccountUserWebSession userWebSession = this.bsAccountMan.getUserWebSession(request);
132 		BSAccountUser user = userWebSession.getUser();
133 		BSAccount account = user.accessAccount();
134 		
135 		log.debug("userWebSession = " + userWebSession);
136 		model.addAttribute("userWebSession", userWebSession);
137 		model.addAttribute("compressJS", compressJS);
138 		model.addAttribute("debugJS", debugJS);
139 		if (request.getParameter("app") != null)
140 			model.addAttribute("appName", request.getParameter("app"));
141 		else
142 			model.addAttribute("appName", this.bsAccountMan.getAppName());
143 		model.addAttribute("account", account);
144 
145 		String s = bsWebLinksMan.getWebPageHead(request, myWebUri);
146 		model.addAttribute("compassHead", s);
147 		if (debugJS) {
148 			log.debug("************************  HEAD ********************");
149 			log.debug(s);
150 		}
151 		//		if (debugJS) {
152 		//			log.debug("************************  BODY ********************");
153 		//			log.debug(s);
154 		//		}
155 
156 		return("editUser");
157 
158 	}
159 }