1 53 54 106 107 package com.Yasna.forum.tags; 108 109 import java.util.*; 110 import javax.servlet.*; 111 import javax.servlet.jsp.*; 112 import javax.servlet.jsp.tagext.*; 113 import javax.servlet.http.*; 114 import com.Yasna.forum.*; 115 import com.Yasna.forum.tags.*; 116 117 147 public class LoginTag extends TagSupport 148 { 149 private Authorization auth = null; 150 private YazdState js = null; 151 private YazdRequest jr = null; 152 153 165 public final int doStartTag() throws JspException 166 { 167 js = (YazdState)pageContext.getAttribute("yazdUserState", 169 PageContext.SESSION_SCOPE); 170 if( js == null ) { 171 js = new YazdState(); 172 pageContext.setAttribute("yazdUserState",js,PageContext.SESSION_SCOPE); 173 } 174 175 if( js.getLoggedIn() ) { 176 return EVAL_BODY_INCLUDE; 177 } 178 179 jr = (YazdRequest)pageContext.getAttribute("yazdUserRequest", 181 PageContext.REQUEST_SCOPE); 182 if( jr == null ) { 183 jr = new YazdRequest(); 184 jr.setYazdState(js); 185 pageContext.setAttribute("yazdUserRequest",jr,PageContext.REQUEST_SCOPE); 186 } 187 188 ServletRequest req = pageContext.getRequest(); 190 String tmp = req.getParameter("login"); 191 if( tmp == null || tmp.length() == 0 ) 192 return SKIP_BODY; 193 String u = req.getParameter("username"); 194 String p = req.getParameter("password"); 195 if( p.length() == 0 || u.length() == 0) { 196 jr.addError(TagPropertyManager.getTagProperty("yazd.tag.login.failed")); 197 return SKIP_BODY; 198 } 199 try { 200 auth = AuthorizationFactory.getAuthorization( u, p ); 201 } 202 catch( UnauthorizedException ue ) { 203 jr.addError(TagPropertyManager.getTagProperty("yazd.tag.login.failed")); 204 return SKIP_BODY; 205 } 206 207 ProfileManager pm = jr.getProfileManager(); 209 User user = null; 210 try { 211 user = pm.getUser(auth.getUserID()); 212 } catch( UserNotFoundException ex ) { 213 throw new JspException("Yazd login tag could not find user."); 214 } 215 216 long val; 218 tmp = user.getProperty(YazdState.MESSAGE_DEPTH); 219 if( tmp != null ) { 220 try { 221 val = Long.valueOf(tmp).longValue(); 222 js.setMessageDepth((int)val); 223 } catch(NumberFormatException e) { 224 } 225 } 226 tmp = user.getProperty(YazdState.THREAD_DEPTH); 227 if( tmp != null ) { 228 try { 229 val = Long.valueOf(tmp).longValue(); 230 js.setThreadDepth((int)val); 231 } catch(NumberFormatException e) { 232 } 233 } 234 tmp = user.getProperty(YazdState.ITEMS_PER_PAGE); 235 if( tmp != null ) { 236 try { 237 val = Long.valueOf(tmp).longValue(); 238 js.setItemsPerPage((int)val); 239 } catch(NumberFormatException e) { 240 } 241 } 242 243 tmp = user.getProperty(YazdState.LAST_VISIT); 245 if( tmp != null ) { 246 try { 247 val = Long.valueOf(tmp).longValue(); 248 js.setLastVisit(new Date(val)); 249 } catch(NumberFormatException e) { 250 } 251 } 252 253 js.setAuthorization(auth); 255 256 js.resetLastForumVisitDate(jr); 258 259 js.setLoggedIn(true); 260 return EVAL_BODY_INCLUDE; 261 } 262 263 268 public final int doEndTag() throws JspException 269 { 270 if( js.getLoggedIn() ) 271 return SKIP_PAGE; 272 return EVAL_PAGE; 273 } 274 } 275 | Popular Tags |