1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34 package fr.paris.lutece.plugins.mydashboard.modules.identity.web;
35
36 import fr.paris.lutece.plugins.mydashboard.modules.identity.util.Constants;
37 import fr.paris.lutece.plugins.mydashboard.modules.identity.util.DashboardIdentityUtils;
38 import fr.paris.lutece.plugins.avatar.service.AvatarService;
39 import fr.paris.lutece.plugins.identitystore.web.exception.IdentityNotFoundException;
40 import fr.paris.lutece.plugins.identitystore.web.rs.dto.AttributeDto;
41 import fr.paris.lutece.plugins.identitystore.web.rs.dto.AuthorDto;
42 import fr.paris.lutece.plugins.identitystore.web.rs.dto.IdentityChangeDto;
43 import fr.paris.lutece.plugins.identitystore.web.rs.dto.IdentityDto;
44 import fr.paris.lutece.plugins.identitystore.web.service.AuthorType;
45 import fr.paris.lutece.plugins.identitystore.web.service.IdentityService;
46 import fr.paris.lutece.plugins.mydashboard.modules.identity.business.DashboardAttribute;
47 import fr.paris.lutece.plugins.mydashboard.modules.identity.business.DashboardIdentity;
48 import fr.paris.lutece.portal.service.datastore.DatastoreService;
49 import fr.paris.lutece.portal.service.i18n.I18nService;
50 import fr.paris.lutece.portal.service.security.LuteceUser;
51 import fr.paris.lutece.portal.service.security.SecurityService;
52 import fr.paris.lutece.portal.service.security.UserNotSignedException;
53 import fr.paris.lutece.portal.service.site.properties.SitePropertiesGroup;
54 import fr.paris.lutece.portal.service.spring.SpringContextService;
55 import fr.paris.lutece.portal.service.util.AppPropertiesService;
56 import fr.paris.lutece.portal.util.mvc.commons.annotations.Action;
57 import fr.paris.lutece.portal.util.mvc.commons.annotations.View;
58 import fr.paris.lutece.portal.util.mvc.xpage.MVCApplication;
59 import fr.paris.lutece.portal.util.mvc.xpage.annotations.Controller;
60 import fr.paris.lutece.portal.web.xpages.XPage;
61 import fr.paris.lutece.util.ReferenceItem;
62 import fr.paris.lutece.util.ReferenceList;
63
64 import org.apache.commons.lang.StringUtils;
65
66 import org.apache.commons.validator.routines.EmailValidator;
67
68 import java.util.HashMap;
69 import java.util.Map;
70
71 import javax.servlet.http.HttpServletRequest;
72
73
74
75
76 @Controller( xpageName = "mydashboardIdentity", pageTitleI18nKey = "module.mydashboard.identity.xpage.getIdentity.pageTitle", pagePathI18nKey = "module.mydashboard.identity.xpage.getIdentity.pagePath" )
77 public class IdentityXPage extends MVCApplication
78 {
79 private static final long serialVersionUID = 1L;
80 private static final String VIEW_GET_VIEW_IDENTITY = "getViewIdentity";
81 private static final String VIEW_GET_MODIFY_IDENTITY = "getModifyIdentity";
82 private static final String ACTION_DO_MODIFY_IDENTITY = "doModifyIdentity";
83 private static final String PARAMETER_BACK = "back";
84 private static final String MARK_IDENTITY = "identity";
85 private static final String MARK_VIEW_MODE = "viewMode";
86 private static final String MARK_AVATAR_URL = "avatar_url";
87 private static final String MARK_AVATARSERVER_POST_URL = "avatarserver_post_url";
88 private static final String MARK_MYDASHBOARD_SITE_PROPERTIES ="mydashboard_site_properties";
89 private static final String BEAN_MYDASHBOARD_IDENTITY_SITE_PROPERTIES = "mydashboard-identity.sitePropertiesGroup";
90
91 private static final String TEMPLATE_GET_VIEW_MODIFY_IDENTITY = "skin/plugins/mydashboard/modules/identity/edit_identity.html";
92 private static final String DASHBOARD_APP_CODE = AppPropertiesService.getProperty( Constants.PROPERTY_APPLICATION_CODE );
93 private static final String MARK_GENDER_LIST = "genderlist";
94 private static final String MARK_CONTACT_MODE_LIST = "contact_modeList";
95 private static final String BEAN_IDENTITYSTORE_SERVICE = "mydashboard-identity.identitystore.service";
96 private static final String SPLIT_PATTERN = ";";
97 private static final String PROPERTY_AVATERSERVER_POST_URL = "mydashboard.identity.avatarserver.post.url";
98 private static final String AVATARSERVER_POST_URL = AppPropertiesService.getProperty( PROPERTY_AVATERSERVER_POST_URL );
99
100
101 private static final String VIEW_VALIDATE_LAST_NAME = "validate_lastName";
102 private static final String VIEW_VALIDATE_PREFERRED_USERNAME = "validate_preferredUsername";
103 private static final String VIEW_VALIDATE_FISRTNAME = "validate_firstname";
104 private static final String VIEW_VALIDATE_BIRTHDATE = "validate_birthdate";
105 private static final String VIEW_VALIDATE_BIRTHPLACE = "validate_birthplace";
106 private static final String VIEW_VALIDATE_BIRTHCOUNTRY = "validate_birthcountry";
107 private static final String VIEW_VALIDATE_ADDRESS = "validate_address";
108 private static final String VIEW_VALIDATE_ADDRESS_DETAIL = "validate_addressdetail";
109 private static final String VIEW_VALIDATE_ADDRESS_POSTALCODE = "validate_addressPostalcode";
110 private static final String VIEW_VALIDATE_ADDRESS_CITY = "validate_addressCity";
111 private static final String VIEW_VALIDATE_EMAIL = "validate_email";
112 private static final String VIEW_VALIDATE_PHONE = "validate_phone";
113 private static final String VIEW_VALIDATE_MOBILEPHONE = "validate_mobilephone";
114 private static final String VIEW_UPDATE_ACCEPT_NEWS = "update_acceptNews";
115 private static final String VIEW_UPDATE_ACCEPT_SURVEY = "update_acceptSurvey";
116 private ReferenceList _lstContactModeList;
117 private ReferenceList _lstGenderList;
118
119
120 private DashboardIdentity _dashboardIdentity;
121 private IdentityService _identityService;
122
123
124
125
126 public IdentityXPage( )
127 {
128 super( );
129 _identityService = SpringContextService.getBean( BEAN_IDENTITYSTORE_SERVICE );
130
131 _lstGenderList = new ReferenceList( );
132
133 int i = 0;
134
135 for ( String sItem : Constants.PROPERTY_KEY_GENDER_LIST.split( SPLIT_PATTERN ) )
136 {
137 ReferenceItem refItm = new ReferenceItem( );
138 refItm.setName( sItem );
139 refItm.setCode( String.valueOf( i ) );
140 _lstGenderList.add( refItm );
141 i++;
142 }
143
144 _lstContactModeList = new ReferenceList( );
145
146 for ( String sItem : Constants.PROPERTY_KEY_CONTACT_MODE_LIST.split( SPLIT_PATTERN ) )
147 {
148 ReferenceItem refItm = new ReferenceItem( );
149 refItm.setName( sItem );
150 refItm.setCode( sItem );
151 _lstContactModeList.add( refItm );
152 }
153 }
154
155
156
157
158
159
160
161
162
163
164 @View( value = VIEW_GET_VIEW_IDENTITY, defaultView = true )
165 public XPage getViewIdentity( HttpServletRequest request ) throws UserNotSignedException
166 {
167 LuteceUser luteceUser = getConnectedUser( request );
168
169 SitePropertiesGroup dashboardPropertiesGroup = (SitePropertiesGroup)SpringContextService.getBean( BEAN_MYDASHBOARD_IDENTITY_SITE_PROPERTIES );
170 String strMyDashboardPropertiesPrefix = dashboardPropertiesGroup.getDatastoreKeysPrefix( );
171
172 Map<String, Object> model = getModel( );
173 IdentityDto identityDto = getIdentityDto( luteceUser.getName( ) );
174 _dashboardIdentity = DashboardIdentityUtils.getInstance( ).convertToDashboardIdentity( identityDto );
175
176 model.put( MARK_MYDASHBOARD_SITE_PROPERTIES, DatastoreService.getDataByPrefix( strMyDashboardPropertiesPrefix ).toMap( ) );
177 model.put( MARK_IDENTITY, _dashboardIdentity );
178 model.put( MARK_VIEW_MODE, Boolean.TRUE );
179 model.put( MARK_CONTACT_MODE_LIST, _lstContactModeList );
180 model.put( MARK_GENDER_LIST, _lstGenderList );
181 model.put( MARK_AVATAR_URL, getAvatarUrl( request ) );
182
183 return getXPage( TEMPLATE_GET_VIEW_MODIFY_IDENTITY, request.getLocale( ), model );
184 }
185
186
187
188
189
190
191
192
193
194
195 @View( VIEW_GET_MODIFY_IDENTITY )
196 public XPage getModifyIdentity( HttpServletRequest request ) throws UserNotSignedException
197 {
198 LuteceUser luteceUser = getConnectedUser( request );
199
200 if ( ( _dashboardIdentity == null ) || ( _dashboardIdentity.getConnectionId( ) == null )
201 || !_dashboardIdentity.getConnectionId( ).equals( luteceUser.getName( ) ) )
202 {
203 IdentityDto identityDto = getIdentityDto( luteceUser.getName( ) );
204 _dashboardIdentity = DashboardIdentityUtils.getInstance( ).convertToDashboardIdentity( identityDto );
205 }
206
207 SitePropertiesGroup dashboardPropertiesGroup = (SitePropertiesGroup)SpringContextService.getBean( BEAN_MYDASHBOARD_IDENTITY_SITE_PROPERTIES );
208 String strMyDashboardPropertiesPrefix = dashboardPropertiesGroup.getDatastoreKeysPrefix( );
209
210 Map<String, Object> model = getModel( );
211
212 model.put( MARK_MYDASHBOARD_SITE_PROPERTIES, DatastoreService.getDataByPrefix( strMyDashboardPropertiesPrefix ).toMap( ) );
213 model.put( MARK_IDENTITY, _dashboardIdentity );
214 model.put( MARK_VIEW_MODE, Boolean.FALSE );
215 model.put( MARK_CONTACT_MODE_LIST, _lstContactModeList );
216 model.put( MARK_GENDER_LIST, _lstGenderList );
217 model.put( MARK_AVATAR_URL, getAvatarUrl( request ) );
218 model.put( MARK_AVATARSERVER_POST_URL, AVATARSERVER_POST_URL );
219
220 return getXPage( TEMPLATE_GET_VIEW_MODIFY_IDENTITY, request.getLocale( ), model );
221 }
222
223
224
225
226
227
228
229
230
231
232 @Action( ACTION_DO_MODIFY_IDENTITY )
233 public XPage doModifyIdentity( HttpServletRequest request ) throws UserNotSignedException
234 {
235 checkUserAuthentication( request );
236
237 if ( request.getParameter( PARAMETER_BACK ) != null )
238 {
239 return redirectView( request, VIEW_GET_VIEW_IDENTITY );
240 }
241
242
243 DashboardIdentityUtils.getInstance( ).populateDashboardIdentity( _dashboardIdentity, request );
244
245 if ( !checkDashboardIdentityFields( _dashboardIdentity, request ) )
246 {
247 return redirectView( request, VIEW_GET_MODIFY_IDENTITY );
248 }
249
250 IdentityDto identityDto = DashboardIdentityUtils.getInstance( ).convertToIdentityDto( _dashboardIdentity );
251
252 try
253 {
254 updateIdentity( identityDto );
255 }
256 catch( Exception appEx )
257 {
258 addError( Constants.MESSAGE_ERROR_UPDATE_IDENTITY, request.getLocale( ) );
259
260 return redirectView( request, VIEW_GET_MODIFY_IDENTITY );
261 }
262
263 addInfo( Constants.MESSAGE_INFO_IDENTITY_UPDATED, request.getLocale( ) );
264
265 return redirectView( request, VIEW_GET_VIEW_IDENTITY );
266 }
267
268
269
270
271
272
273
274
275
276
277 private LuteceUser getConnectedUser( HttpServletRequest request ) throws UserNotSignedException
278 {
279 LuteceUser luteceUser = SecurityService.isAuthenticationEnable( ) ? SecurityService.getInstance( ).getRegisteredUser( request ) : null;
280
281 if ( luteceUser == null )
282 {
283 throw new UserNotSignedException( );
284 }
285
286 return luteceUser;
287 }
288
289
290
291
292
293
294
295
296
297 private IdentityDto getIdentityDto( String strConnectionId )
298 {
299 IdentityDto identityDto = null;
300
301 try
302 {
303 identityDto = _identityService.getIdentityByConnectionId( strConnectionId, DASHBOARD_APP_CODE );
304 }
305 catch( IdentityNotFoundException infe )
306 {
307 identityDto = new IdentityDto( );
308 identityDto.setConnectionId( strConnectionId );
309 }
310
311 return identityDto;
312 }
313
314
315
316
317
318
319
320
321 private void updateIdentity( IdentityDto identityDto )
322 {
323 IdentityChangeDto identityChangeDto = buildIdentityChangeDto( identityDto );
324
325 _identityService.updateIdentity( identityChangeDto, null );
326
327 }
328
329
330
331
332
333
334
335
336
337 private void checkUserAuthentication( HttpServletRequest request ) throws UserNotSignedException
338 {
339 getConnectedUser( request );
340 }
341
342
343
344
345
346
347
348
349 private IdentityChangeDto buildIdentityChangeDto( IdentityDto identity )
350 {
351 IdentityChangeDto identityChange = new IdentityChangeDto( );
352 AuthorDto author = new AuthorDto( );
353 author.setApplicationCode( DASHBOARD_APP_CODE );
354 author.setType( AuthorType.TYPE_USER_OWNER.getTypeValue( ) );
355
356 identityChange.setIdentity( identity );
357 identityChange.setAuthor( author );
358
359 return identityChange;
360 }
361
362
363
364
365
366
367
368
369
370
371 private boolean checkDashboardIdentityFields( DashboardIdentity dashboardIdentity, HttpServletRequest request )
372 {
373 boolean bStatus = true;
374
375 String strValidateLastName = validateLastName( request ).getContent( );
376
377 if ( !strValidateLastName.isEmpty( ) )
378 {
379 addError( strValidateLastName );
380 bStatus = false;
381 }
382
383 String strValidatePreferredUsername = validatePreferredUserName( request ).getContent( );
384
385 if ( !strValidatePreferredUsername.isEmpty( ) )
386 {
387 addError( strValidatePreferredUsername );
388 bStatus = false;
389 }
390
391 String strValidateFirstname = validateFirstName( request ).getContent( );
392
393 if ( !strValidateFirstname.isEmpty( ) )
394 {
395 addError( strValidateFirstname );
396 bStatus = false;
397 }
398
399 String strValidateBirthplace = validateBirthPlace( request ).getContent( );
400
401 if ( !strValidateBirthplace.isEmpty( ) )
402 {
403 addError( strValidateBirthplace );
404 bStatus = false;
405 }
406
407 String strValidateBirthDate = validateBirthDate( request ).getContent( );
408
409 if ( !strValidateBirthDate.isEmpty( ) )
410 {
411 addError( strValidateBirthDate );
412 bStatus = false;
413 }
414
415 String strValidateBirthCountry = validateBirthCountry( request ).getContent( );
416
417 if ( !strValidateBirthCountry.isEmpty( ) )
418 {
419 addError( strValidateBirthCountry );
420 bStatus = false;
421 }
422
423 String strValidateEmail = validateEmail( request ).getContent( );
424
425 if ( !strValidateEmail.isEmpty( ) )
426 {
427 addError( strValidateEmail );
428 bStatus = false;
429 }
430
431 String strValidatePhone = validatePhone( request ).getContent( );
432
433 if ( !strValidatePhone.isEmpty( ) )
434 {
435 addError( strValidatePhone );
436 bStatus = false;
437 }
438
439 String strValidateMobilePhone = validateMobilePhone( request ).getContent( );
440
441 if ( !strValidateMobilePhone.isEmpty( ) )
442 {
443 addError( strValidateMobilePhone );
444 bStatus = false;
445 }
446
447 String strValidateAdresse = validateAddress( request ).getContent( );
448
449 if ( !strValidateAdresse.isEmpty( ) )
450 {
451 addError( strValidateAdresse );
452 bStatus = false;
453 }
454
455 String strValidateAdresseDetail = validateAddressDetail( request ).getContent( );
456
457 if ( !strValidateAdresseDetail.isEmpty( ) )
458 {
459 addError( strValidateAdresseDetail );
460 bStatus = false;
461 }
462
463 String strValidateAdressePostalcode = validateAddressPostalCode( request ).getContent( );
464
465 if ( !strValidateAdressePostalcode.isEmpty( ) )
466 {
467 addError( strValidateAdressePostalcode );
468 bStatus = false;
469 }
470
471 String strValidateCity = validateAddressCity( request ).getContent( );
472
473 if ( !strValidateCity.isEmpty( ) )
474 {
475 addError( strValidateCity );
476 bStatus = false;
477 }
478
479 String strPreferredContactMode = dashboardIdentity.getPreferredContactMode( ).getValue( );
480
481
482 if ( strPreferredContactMode.compareTo( _lstContactModeList.get( 0 ).getName( ) ) == 0 )
483 {
484 if ( dashboardIdentity.getEmail( ).getValue( ).isEmpty( ) )
485 {
486 addError( I18nService.getLocalizedString( Constants.MESSAGE_ERROR_EMAIL_EMPTY, request.getLocale( ) ) );
487 bStatus = false;
488 }
489 }
490
491
492 if ( strPreferredContactMode.compareTo( _lstContactModeList.get( 1 ).getName( ) ) == 0 )
493 {
494 if ( ( dashboardIdentity.getPhone( ).getValue( ).isEmpty( ) ) && ( dashboardIdentity.getMobilePhone( ).getValue( ).isEmpty( ) ) )
495 {
496 addError( I18nService.getLocalizedString( Constants.MESSAGE_ERROR_TELEPHONE_EMPTY, request.getLocale( ) ) );
497 bStatus = false;
498 }
499 }
500
501
502 String strGender = dashboardIdentity.getGender( ).getValue( );
503
504 for ( ReferenceItem rItem : _lstGenderList )
505 {
506 if ( strGender.compareTo( rItem.getName( ) ) == 0 )
507 {
508 dashboardIdentity.setGender( new DashboardAttribute(
509 Constants.ATTRIBUTE_DB_IDENTITY_GENDER,
510 rItem.getCode( ) ) );
511 }
512 }
513
514 return bStatus;
515 }
516
517
518
519
520
521
522 @View( VIEW_VALIDATE_LAST_NAME )
523 public XPage validateLastName( HttpServletRequest request )
524 {
525 String errorValidationMessage = StringUtils.EMPTY;
526
527 if ( !request.getParameter( Constants.ATTRIBUTE_DB_IDENTITY_LAST_NAME ).matches( Constants.PROPERTY_KEY_VALIDATION_REGEXP_LAST_NAME ) )
528 {
529 errorValidationMessage = I18nService.getLocalizedString( Constants.MESSAGE_ERROR_VALIDATION_LASTNAME, request.getLocale( ) );
530 }
531
532 XPage xpContent = getXPage( );
533 xpContent.setContent( errorValidationMessage );
534 xpContent.setStandalone( true );
535
536 return xpContent;
537 }
538
539
540
541
542
543
544 @View( VIEW_VALIDATE_PREFERRED_USERNAME )
545 public XPage validatePreferredUserName( HttpServletRequest request )
546 {
547 String errorValidationMessage = StringUtils.EMPTY;
548
549 if ( !request.getParameter( "preferredUsername" ).matches( Constants.PROPERTY_KEY_VALIDATION_REGEXP_PREFERREDUSERNAME ) )
550 {
551 errorValidationMessage = I18nService.getLocalizedString( Constants.MESSAGE_ERROR_VALIDATION_PREFFEREDUSERNAME, request.getLocale( ) );
552 }
553
554 XPage xpContent = getXPage( );
555 xpContent.setContent( errorValidationMessage );
556 xpContent.setStandalone( true );
557
558 return xpContent;
559 }
560
561
562
563
564
565
566 @View( VIEW_VALIDATE_FISRTNAME )
567 public XPage validateFirstName( HttpServletRequest request )
568 {
569 String errorValidationMessage = StringUtils.EMPTY;
570
571 if ( !request.getParameter( "firstname" ).matches( Constants.PROPERTY_KEY_VALIDATION_REGEXP_FIRSTNAME ) )
572 {
573 errorValidationMessage = I18nService.getLocalizedString( Constants.MESSAGE_ERROR_VALIDATION_FIRSTNAME, request.getLocale( ) );
574 }
575
576 XPage xpContent = getXPage( );
577 xpContent.setContent( errorValidationMessage );
578 xpContent.setStandalone( true );
579
580 return xpContent;
581 }
582
583
584
585
586
587
588 @View( VIEW_VALIDATE_BIRTHDATE )
589 public XPage validateBirthDate( HttpServletRequest request )
590 {
591 String errorValidationMessage = StringUtils.EMPTY;
592
593 if ( !request.getParameter( "birthdate" ).matches( Constants.PROPERTY_KEY_VALIDATION_REGEXP_BIRTHDATE ) )
594 {
595 errorValidationMessage = I18nService.getLocalizedString( Constants.MESSAGE_ERROR_VALIDATION_BIRTHDATE, request.getLocale( ) );
596 }
597
598 XPage xpContent = getXPage( );
599 xpContent.setContent( errorValidationMessage );
600 xpContent.setStandalone( true );
601
602 return xpContent;
603 }
604
605
606
607
608
609
610 @View( VIEW_VALIDATE_BIRTHPLACE )
611 public XPage validateBirthPlace( HttpServletRequest request )
612 {
613 String errorValidationMessage = StringUtils.EMPTY;
614
615 if ( !request.getParameter( "birthplace" ).matches( Constants.PROPERTY_KEY_VALIDATION_REGEXP_BIRTHPLACE ) )
616 {
617 errorValidationMessage = I18nService.getLocalizedString( Constants.MESSAGE_ERROR_VALIDATION_BIRTHPLACE, request.getLocale( ) );
618 }
619
620 XPage xpContent = getXPage( );
621 xpContent.setContent( errorValidationMessage );
622 xpContent.setStandalone( true );
623
624 return xpContent;
625 }
626
627
628
629
630
631
632 @View( VIEW_VALIDATE_BIRTHCOUNTRY )
633 public XPage validateBirthCountry( HttpServletRequest request )
634 {
635 String errorValidationMessage = StringUtils.EMPTY;
636
637 if ( !request.getParameter( Constants.ATTRIBUTE_DB_IDENTITY_BIRTHCOUNTRY ).matches( Constants.PROPERTY_KEY_VALIDATION_REGEXP_BIRTHCOUNTRY ) )
638 {
639 errorValidationMessage = I18nService.getLocalizedString( Constants.MESSAGE_ERROR_VALIDATION_BIRTHCOUNTRY, request.getLocale( ) );
640 }
641
642 XPage xpContent = getXPage( );
643 xpContent.setContent( errorValidationMessage );
644 xpContent.setStandalone( true );
645
646 return xpContent;
647 }
648
649
650
651
652
653
654 @View( VIEW_VALIDATE_ADDRESS )
655 public XPage validateAddress( HttpServletRequest request )
656 {
657 String errorValidationMessage = StringUtils.EMPTY;
658
659 if ( !request.getParameter( Constants.ATTRIBUTE_DB_IDENTITY_ADDRESS ).matches( Constants.PROPERTY_KEY_VALIDATION_REGEXP_ADDRESS ) )
660 {
661 errorValidationMessage = I18nService.getLocalizedString( Constants.MESSAGE_ERROR_VALIDATION_ADDRESS, request.getLocale( ) );
662 }
663
664 XPage xpContent = getXPage( );
665 xpContent.setContent( errorValidationMessage );
666 xpContent.setStandalone( true );
667
668 return xpContent;
669 }
670
671
672
673
674
675
676 @View( VIEW_VALIDATE_ADDRESS_DETAIL )
677 public XPage validateAddressDetail( HttpServletRequest request )
678 {
679 String errorValidationMessage = StringUtils.EMPTY;
680
681 if ( !request.getParameter( Constants.ATTRIBUTE_DB_IDENTITY_ADDRESS_DETAIL ).matches( Constants.PROPERTY_KEY_VALIDATION_REGEXP_ADDRESS_DETAIL ) )
682 {
683 errorValidationMessage = I18nService.getLocalizedString( Constants.MESSAGE_ERROR_VALIDATION_ADDRESS_DETAIL, request.getLocale( ) );
684 }
685
686 XPage xpContent = getXPage( );
687 xpContent.setContent( errorValidationMessage );
688 xpContent.setStandalone( true );
689
690 return xpContent;
691 }
692
693
694
695
696
697
698 @View( VIEW_VALIDATE_ADDRESS_POSTALCODE )
699 public XPage validateAddressPostalCode( HttpServletRequest request )
700 {
701 String errorValidationMessage = StringUtils.EMPTY;
702
703 if ( !request.getParameter( Constants.ATTRIBUTE_DB_IDENTITY_ADDRESS_POSTAL_CODE ).matches( Constants.PROPERTY_KEY_VALIDATION_REGEXP_ADDRESS_POSTALCODE ) )
704 {
705 errorValidationMessage = I18nService.getLocalizedString( Constants.MESSAGE_ERROR_VALIDATION_ADDRESS_POSTALCODE, request.getLocale( ) );
706 }
707
708 XPage xpContent = getXPage( );
709 xpContent.setContent( errorValidationMessage );
710 xpContent.setStandalone( true );
711
712 return xpContent;
713 }
714
715
716
717
718
719
720 @View( VIEW_VALIDATE_ADDRESS_CITY )
721 public XPage validateAddressCity( HttpServletRequest request )
722 {
723 String errorValidationMessage = StringUtils.EMPTY;
724
725 if ( !request.getParameter( Constants.ATTRIBUTE_DB_IDENTITY_ADDRESS_CITY ).matches( Constants.PROPERTY_KEY_VALIDATION_REGEXP_ADDRESS_CITY ) )
726 {
727 errorValidationMessage = I18nService.getLocalizedString( Constants.MESSAGE_ERROR_VALIDATION_ADDRESS_CITY, request.getLocale( ) );
728 }
729
730 XPage xpContent = getXPage( );
731 xpContent.setContent( errorValidationMessage );
732 xpContent.setStandalone( true );
733
734 return xpContent;
735 }
736
737
738
739
740
741
742 @View( VIEW_VALIDATE_EMAIL )
743 public XPage validateEmail( HttpServletRequest request )
744 {
745 String errorValidationMessage = StringUtils.EMPTY;
746
747 if ( !EmailValidator.getInstance( ).isValid( request.getParameter( Constants.ATTRIBUTE_DB_IDENTITY_EMAIL ) ) )
748 {
749 errorValidationMessage = I18nService.getLocalizedString( Constants.MESSAGE_ERROR_VALIDATION_EMAIL, request.getLocale( ) );
750 }
751
752 XPage xpContent = getXPage( );
753 xpContent.setContent( errorValidationMessage );
754 xpContent.setStandalone( true );
755
756 return xpContent;
757 }
758
759
760
761
762
763
764 @View( VIEW_VALIDATE_PHONE )
765 public XPage validatePhone( HttpServletRequest request )
766 {
767 String errorValidationMessage = StringUtils.EMPTY;
768
769 if ( !request.getParameter( Constants.ATTRIBUTE_DB_IDENTITY_PHONE ).matches( Constants.PROPERTY_KEY_VALIDATION_REGEXP_PHONE ) )
770 {
771 errorValidationMessage = I18nService.getLocalizedString( Constants.MESSAGE_ERROR_VALIDATION_PHONE, request.getLocale( ) );
772 }
773
774 XPage xpContent = getXPage( );
775 xpContent.setContent( errorValidationMessage );
776 xpContent.setStandalone( true );
777
778 return xpContent;
779 }
780
781
782
783
784
785
786 @View( VIEW_VALIDATE_MOBILEPHONE )
787 public XPage validateMobilePhone( HttpServletRequest request )
788 {
789 String errorValidationMessage = StringUtils.EMPTY;
790
791 if ( !request.getParameter( Constants.ATTRIBUTE_DB_IDENTITY_MOBILE_PHONE ).matches( Constants.PROPERTY_KEY_VALIDATION_REGEXP_MOBILEPHONE ) )
792 {
793 errorValidationMessage = I18nService.getLocalizedString( Constants.MESSAGE_ERROR_VALIDATION_MOBILEPHONE, request.getLocale( ) );
794 }
795
796 XPage xpContent = getXPage( );
797 xpContent.setContent( errorValidationMessage );
798 xpContent.setStandalone( true );
799
800 return xpContent;
801 }
802
803
804
805
806
807
808
809
810 private String getAvatarUrl( HttpServletRequest request )
811 {
812 LuteceUser user = SecurityService.getInstance( ).getRegisteredUser( request );
813
814 return AvatarService.getAvatarUrl( user.getEmail( ) );
815 }
816
817
818
819
820
821
822
823 @View( VIEW_UPDATE_ACCEPT_NEWS )
824 public void updateAcceptNews( HttpServletRequest request )
825 {
826 if ( !request.getParameter( "bAccept" ).isEmpty( ) )
827 {
828 updateIdentityAttribute( Constants.PROPERTY_KEY_ACCEPT_NEWS, request.getParameter( "bAccept" ) );
829 String strAcceptNews = (Boolean.parseBoolean( request.getParameter( "bAccept" ) ) == true ) ?
830 Constants.TRUE : Constants.FALSE;
831
832 _dashboardIdentity.setAcceptNews( new DashboardAttribute (
833 Constants.ATTRIBUTE_DB_IDENTITY_ACCEPT_NEWS,
834 strAcceptNews
835 ) );
836 }
837 }
838
839
840
841
842
843
844
845 @View( VIEW_UPDATE_ACCEPT_SURVEY )
846 public void updateAcceptSurvey( HttpServletRequest request )
847 {
848 if ( !request.getParameter( "bAccept" ).isEmpty( ) )
849 {
850 updateIdentityAttribute( Constants.PROPERTY_KEY_ACCEPT_SURVEY, request.getParameter( "bAccept" ) );
851 String strAcceptSurveys = (Boolean.parseBoolean( request.getParameter( "bAccept" ) ) == true ) ?
852 Constants.TRUE : Constants.FALSE;
853 _dashboardIdentity.setAcceptSurvey( new DashboardAttribute (
854 Constants.ATTRIBUTE_DB_IDENTITY_ACCEPT_SURVEY,
855 strAcceptSurveys
856 ) );
857
858 }
859 }
860
861
862
863
864
865
866
867
868
869 private void updateIdentityAttribute( String propertyKeyToUpdate, String value )
870 {
871 IdentityDto identityDto = new IdentityDto( );
872 identityDto.setConnectionId( _dashboardIdentity.getConnectionId( ).getValue( ) );
873 identityDto.setCustomerId( _dashboardIdentity.getCustomerId( ).getValue( ) );
874
875 Map<String, AttributeDto> mapAttributes = new HashMap<String, AttributeDto>( );
876 AttributeDto attribute = new AttributeDto( );
877 attribute.setKey( propertyKeyToUpdate );
878 attribute.setValue( value );
879 mapAttributes.put( attribute.getKey( ), attribute );
880 identityDto.setAttributes( mapAttributes );
881
882 updateIdentity( identityDto );
883 }
884 }