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 185 186 public class AccountTag extends TagSupport implements YazdProperty 187 { 188 private YazdState js = null; 189 private YazdRequest jr = null; 190 private User user = null; 191 private String username = null; 193 private String email = null; 195 private String nameVisible = null; 197 private String emailVisible = null; 198 private String receiveMail = null; 199 private String password = null; 200 private String confirm = null; 201 private String name = null; 202 private Map properties = new HashMap(); 204 private Map required = new HashMap(); 206 private boolean confirm_password = false; 209 210 218 219 public final int doStartTag() throws JspException 220 { 221 boolean extended_required = true; 222 223 js = (YazdState)pageContext.getAttribute("yazdUserState", 225 PageContext.SESSION_SCOPE); 226 if( js == null ) { 227 throw new JspException("Yazd account tag could not get yazd state."); 228 } 229 230 jr = (YazdRequest)pageContext.getAttribute("yazdUserRequest", 232 PageContext.REQUEST_SCOPE); 233 if( jr == null ) { 234 throw new JspException("Yazd account tag could not get yazd request."); 235 } 236 237 try { 239 AdminUserTag at = (AdminUserTag)this.findAncestorWithClass(this, 240 Class.forName("com.Yasna.forum.tags.AdminUserTag")); 241 user = at.getUser(); 242 } catch(Exception e) { 243 } 244 245 if( user == null ) { 246 ProfileManager pm = jr.getProfileManager(); 248 try { 249 user = pm.getUser(js.getAuthorization().getUserID()); 250 } catch( UserNotFoundException ex ) { 251 throw new JspException("Yazd account tag could not find user."); 252 } 253 } 254 255 if( user.isAnonymous() ) { 257 throw new JspException("Yazd account tag can not be used by an anonymous user."); 258 } 259 260 if( user.getUsername() == null ) 262 throw new JspException("Yazd account tag, user with id " + 263 user.getID() + " has no name."); 264 username = user.getUsername(); 265 266 pageContext.setAttribute(id,this,PageContext.PAGE_SCOPE); 268 269 Enumeration enume = TagPropertyManager.getUserPropertyNames(); 271 String tmp; 272 String prop; 273 ServletRequest req = pageContext.getRequest(); 274 if( user.getEmail() != null ) 275 email = user.getEmail(); 276 if( user.getName() != null ) 277 name = user.getName(); 278 if( user.isEmailVisible() ) 279 emailVisible = "checked"; 280 if( user.isNameVisible() ) 281 nameVisible = "checked"; 282 while( enume.hasMoreElements() ) { 285 prop = (String )enume.nextElement(); 286 if( prop.startsWith( "required." ) ) { 287 prop = prop.substring(9); 288 if( (tmp = user.getProperty(prop)) != null ) { 289 required.put(prop,tmp); 290 } else { 291 required.put(prop,""); 292 } 293 } else { 294 if( (tmp = user.getProperty(prop)) != null ) { 295 properties.put(prop,tmp); 296 } else { 297 properties.put(prop,""); 298 } 299 } 300 } 301 302 if( (tmp = req.getParameter("modify")) == null ) { 303 return EVAL_BODY_INCLUDE; 305 } 306 307 309 email = req.getParameter("email"); 311 password = req.getParameter("password"); 312 confirm = req.getParameter("confirm"); 313 name = req.getParameter("name"); 314 nameVisible = req.getParameter("nameVisible"); 315 emailVisible = req.getParameter("emailVisible"); 316 receiveMail = req.getParameter("receiveMail"); 317 318 for( Iterator it=required.keySet().iterator(); it.hasNext(); ) { 320 prop = (String )it.next(); 321 if( (tmp = req.getParameter(prop)) != null && tmp.length() > 0 ) { 322 required.put(prop,tmp); 323 } else { 324 required.put(prop,""); 325 extended_required = false; 326 } 327 } 328 329 for( Iterator it=properties.keySet().iterator(); it.hasNext(); ) { 331 prop = (String )it.next(); 332 if( (tmp = req.getParameter(prop)) != null ) { 333 properties.put(prop,tmp); 334 } 335 } 336 337 if( email == null || email.length() == 0 || !extended_required ) { 339 jr.addError(TagPropertyManager.getTagProperty("yazd.tag.account.required")); 340 return EVAL_BODY_INCLUDE; 341 } 342 343 if( password != null && password.length() > 0 ) { 346 if( confirm_password && (confirm == null || !password.equals(confirm)) ) { 347 password = null; 348 confirm = null; 349 jr.addError(TagPropertyManager.getTagProperty("yazd.tag.account.confirm_password")); 350 return EVAL_BODY_INCLUDE; 351 } 352 } 353 354 try { 355 if( password != null && password.length() > 0 ) { 357 user.setPassword(password); 358 if( properties.get("password") != null ) { 359 ForumPermissions perms = 360 jr.getForumFactory().getPermissions(js.getAuthorization()); 361 if( !perms.get(ForumPermissions.SYSTEM_ADMIN) && 362 !perms.get(ForumPermissions.FORUM_ADMIN) && 363 !perms.get(ForumPermissions.GROUP_ADMIN) && 364 !perms.get(ForumPermissions.USER_ADMIN) ) { 365 user.setProperty( "password", (String )properties.get("password")); 366 } 367 } 368 } 369 if( name != null && name.length() > 0 ) { 370 user.setName( name ); 371 } 372 if( nameVisible != null && nameVisible.length() > 0) { 373 user.setNameVisible( true ); 374 } else { 375 user.setNameVisible( false ); 376 } 377 if( receiveMail != null) { 378 user.setThreadSubscribe( true ); 379 } else { 380 user.setThreadSubscribe( false ); 381 } 382 if( email != null && email.length() > 0 ) { 383 user.setEmail( email ); 384 } 385 if( emailVisible != null && emailVisible.length() > 0 ) { 386 user.setEmailVisible( true ); 387 } else { 388 user.setEmailVisible( false ); 389 } 390 391 for( Iterator it=properties.keySet().iterator(); it.hasNext(); ) { 395 tmp = (String )it.next(); 396 if( !tmp.equals("password") ) 397 user.setProperty( tmp, (String )properties.get(tmp)); 398 if( tmp.equals(YazdState.MESSAGE_DEPTH) ) 399 js.setMessageDepth(Integer.valueOf((String )properties.get(tmp)).intValue()); 400 if( tmp.equals(YazdState.THREAD_DEPTH) ) 401 js.setThreadDepth(Integer.valueOf((String )properties.get(tmp)).intValue()); 402 if( tmp.equals(YazdState.ITEMS_PER_PAGE) ) 403 js.setItemsPerPage(Integer.valueOf((String )properties.get(tmp)).intValue()); 404 } 405 406 for( Iterator it=required.keySet().iterator(); it.hasNext(); ) { 410 tmp = (String )it.next(); 411 if( !tmp.equals("password") ) 412 user.setProperty( tmp, (String )required.get(tmp)); 413 if( tmp.equals(YazdState.MESSAGE_DEPTH) ) 414 js.setMessageDepth(Integer.valueOf((String )required.get(tmp)).intValue()); 415 if( tmp.equals(YazdState.THREAD_DEPTH) ) 416 js.setThreadDepth(Integer.valueOf((String )required.get(tmp)).intValue()); 417 if( tmp.equals(YazdState.ITEMS_PER_PAGE) ) 418 js.setItemsPerPage(Integer.valueOf((String )required.get(tmp)).intValue()); 419 } 420 421 } catch(UnauthorizedException e) { 422 throw new JspException("Yazd account tag, user with id " + 423 user.getID() + " is not authorized to set user values."); 424 } 425 426 return EVAL_BODY_INCLUDE; 429 } 430 431 435 public final void setConfirm(String name) 436 { 437 if( name.equals("true") ) 438 confirm_password = true; 439 } 440 441 444 450 public final String getEmail() 451 { 452 if( email == null ) 453 return ""; 454 return email; 455 } 456 457 463 public final String getUsername() 464 { 465 if( username == null ) 466 return ""; 467 return username; 468 } 469 470 477 public final String getPassword() 478 { 479 if( password == null ) 480 return ""; 481 return password; 482 } 483 484 491 public final String getConfirm() 492 { 493 if( confirm == null ) 494 return ""; 495 return confirm; 496 } 497 498 504 public final String getName() 505 { 506 if( name == null ) 507 return ""; 508 return name; 509 } 510 511 517 public final String getNameVisible() 518 { 519 if( nameVisible != null ) 520 return "checked"; 521 return ""; 522 } 523 524 530 public final String getEmailVisible() 531 { 532 if( emailVisible != null ) 533 return "checked"; 534 return ""; 535 } 536 537 public final String getEmailReply() 538 { 539 if( receiveMail != null ) 540 return "checked"; 541 return ""; 542 } 543 544 550 public final String getProperty(String name) 551 { 552 String tmp = (String )properties.get(name); 553 if( tmp != null ) 554 return tmp; 555 tmp = (String )required.get(name); 556 if( tmp != null ) 557 return tmp; 558 return ""; 559 } 560 561 565 public final void setProperty(String name, String value) 566 { 567 user.setProperty(name,value); 568 if( properties.containsKey(name) ) 569 properties.put(name,value); 570 else if( required.containsKey(name) ) 571 properties.put(name,value); 572 } 573 574 579 public final boolean isMember(String name) throws JspException 580 { 581 ProfileManager pm = jr.getProfileManager(); 583 try { 584 Group group = pm.getGroup(name); 585 return group.isMember(user); 586 } catch( GroupNotFoundException ex ) { 587 } 588 return false; 589 } 590 591 } 592 | Popular Tags |