View Javadoc
1   /*
2    * Copyright (c) 2002-2020, City of Paris
3    * All rights reserved.
4    *
5    * Redistribution and use in source and binary forms, with or without
6    * modification, are permitted provided that the following conditions
7    * are met:
8    *
9    *  1. Redistributions of source code must retain the above copyright notice
10   *     and the following disclaimer.
11   *
12   *  2. Redistributions in binary form must reproduce the above copyright notice
13   *     and the following disclaimer in the documentation and/or other materials
14   *     provided with the distribution.
15   *
16   *  3. Neither the name of 'Mairie de Paris' nor 'Lutece' nor the names of its
17   *     contributors may be used to endorse or promote products derived from
18   *     this software without specific prior written permission.
19   *
20   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21   * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23   * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
24   * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25   * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26   * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27   * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28   * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29   * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30   * POSSIBILITY OF SUCH DAMAGE.
31   *
32   * License 1.0
33   */
34  package fr.paris.lutece.plugins.campagnebp.service;
35  
36  import java.io.IOException;
37  import java.sql.Date;
38  import java.text.ParseException;
39  import java.util.Arrays;
40  import java.util.Calendar;
41  import java.util.List;
42  import java.util.Locale;
43  import java.util.regex.Matcher;
44  
45  import javax.servlet.http.HttpServletRequest;
46  
47  import org.apache.commons.lang.StringUtils;
48  import org.joda.time.DateTime;
49  import org.joda.time.LocalDate;
50  import org.joda.time.Years;
51  import org.joda.time.format.DateTimeFormat;
52  import org.joda.time.format.DateTimeFormatter;
53  
54  import fr.paris.lutece.plugins.campagnebp.business.Civility;
55  import fr.paris.lutece.plugins.campagnebp.business.MyInfosForm;
56  import fr.paris.lutece.plugins.campagnebp.utils.Constants;
57  import fr.paris.lutece.plugins.leaflet.business.GeolocItem;
58  import fr.paris.lutece.plugins.openamidentityclient.business.Account;
59  import fr.paris.lutece.plugins.openamidentityclient.service.NotificationService;
60  import fr.paris.lutece.plugins.openamidentityclient.service.OpenamIdentityException;
61  import fr.paris.lutece.plugins.openamidentityclient.service.OpenamIdentityService;
62  import fr.paris.lutece.plugins.openamidentityclient.web.ManageAccountXPage;
63  import fr.paris.lutece.plugins.parisconnect.service.ParisConnectService;
64  import fr.paris.lutece.portal.service.datastore.DatastoreService;
65  import fr.paris.lutece.portal.service.i18n.I18nService;
66  import fr.paris.lutece.portal.service.prefs.IPortalUserPreferencesService;
67  import fr.paris.lutece.portal.service.prefs.UserPreferencesService;
68  import fr.paris.lutece.portal.service.security.LuteceUser;
69  import fr.paris.lutece.portal.service.util.AppLogService;
70  import fr.paris.lutece.portal.service.util.AppPropertiesService;
71  import fr.paris.lutece.util.ReferenceList;
72  
73  /**
74   * MyInfos Service
75   */
76  public final class MyInfosService
77  {
78  
79      private static final java.util.regex.Pattern patternPostalCode = java.util.regex.Pattern.compile( ", (75[0-1][0-2][0-9]) PARIS" );
80      /**
81       * 
82       */
83      public static final String UNDEFINED_POSTALCODE_KEY = "undefined";
84      /**
85       * 
86       */
87      public static final String LUTECE_USER_KEY_VERIFIED = "user.validated";
88      private static final String PREF_KEY_EMAIL = "budgetparticipatif.email";
89      private static final String PREF_KEY_FIRSTNAME = "budgetparticipatif.firstname";
90      private static final String PREF_KEY_CREATIONDATE = "budgetparticipatif.creationdate";
91      private static final String PREF_KEY_CIVILITY = "budgetparticipatif.civility";
92      private static final String PREF_KEY_LASTNAME = "budgetparticipatif.lastname";
93      private static final String PREF_KEY_ADDRESS = "budgetparticipatif.address";
94      private static final String PREF_KEY_GEO_JSON = "budgetparticipatif.geojson";
95      private static final String PREF_KEY_BIRTHDATE = "budgetparticipatif.birthdate";
96      private static final String PREF_KEY_ARRONDISSEMENT_VOTE = "budgetparticipatif.arrondissement";
97      private static final String PREF_KEY_POSTAL_CODE = "budgetparticipatif.postalCode";
98      private static final String PREF_KEY_ILIVEINPARIS = "budgetparticipatif.iliveinparis";
99      private static final String PREF_KEY_STAYCONNECTED = "budgetparticipatif.stayconnected";
100     private static final String PREF_KEY_SEND_ACCOUNT_VALIDATION = "budgetparticipatif.sendaccountvalidation";
101     private static final String PREF_KEY_ACCOUNT_VERIFIED = "budgetparticipatif.accountVerified";
102     private static final String PROPERTY_ARRONDISSEMENT = "budgetparticipatif.arrondissement.";
103     private static final String PROPERTY_SELECT_ARRONDISSEMENT = "campagnebp.mes_infos.arrondissement";
104     private static final String PROPERTY_SELECT_POSTAL_CODE = "campagnebp.mes_infos.postalCode";
105     private static final String PROPERTY_SELECT_POSTAL_CODE_16_KEY = "campagnebp.mes_infos.postalCode16Key";
106     private static final String PROPERTY_SELECT_POSTAL_CODE_16_LABEL = "campagnebp.mes_infos.postalCode16Label";
107     private static final String PREF_VALUE_ON = "on";
108     private static final String PREF_VALUE_OFF = "off";
109     private static final String DEFAULT_CHECKED = "default";
110     private static final String ADDRESS_SEPARATOR = " ";
111 
112     private static final String KEY_PARIS_CONNECT_SUSBCIBE_ID_ALERTE = "budgetparticipatif.site_property.paris_connect.subscribe_id_alerte";
113     private static final String KEY_SEND_ACCOUNT_VALIDATION_BACK_URL = "budgetparticipatif.site_property.send_account_validation_back_url";
114     private static final String KEY_ENABLE_VALIDATION_ACCOUNT = "budgetparticipatif.site_property.enable_validation_account";
115 
116     private static final String TYPE_VALIDATE_ACCOUNT = "validate_account";
117     private static volatile ReferenceList _listArrondissements;
118     private static volatile ReferenceList _listPostalCode;
119     private static List<String> _listAuthorizedCities = Arrays
120             .asList( AppPropertiesService.getProperty( Constants.PROPERTY_AUTHORIZED_CITIES ).split( Constants.AUTHORIZED_CITIES_SEPARATOR ) );
121 
122     /** Private constructor */
123     private MyInfosService( )
124     {
125     }
126 
127     /**
128      * Load informations about the user from ParisConnect and local preferences
129      * 
130      * @param user
131      *            The User
132      * @return User's infos
133      */
134     public static MyInfosForm loadUserInfos( LuteceUser user )
135     {
136         MyInfosFormagnebp/business/MyInfosForm.html#MyInfosForm">MyInfosForm myInfos = new MyInfosForm( );
137 
138         IPortalUserPreferencesService instance = UserPreferencesService.instance( );
139 
140         // Initialized to true, but can be changed in populate methods
141         myInfos.setIsValid( true );
142 
143         // Populate the MyInfosForm object
144         populateMyInfosData( myInfos, instance, user );
145 
146         return myInfos;
147     }
148 
149     /**
150      * Populate the MyInfosForm with the user data
151      * 
152      * @param myInfos
153      *            The instance of MyInfosForm
154      * @param instance
155      *            The IPortalUserPreferencesService instance
156      * @param user
157      *            The user
158      */
159     private static void populateMyInfosData( MyInfosForm myInfos, IPortalUserPreferencesService instance, LuteceUser user )
160     {
161         populateNickname( myInfos, instance, user );
162         populateCivility( myInfos, instance, user );
163         populateFirstName( myInfos, instance, user );
164         populateLastName( myInfos, instance, user );
165         populateBirthDate( myInfos, instance, user );
166         populateAddress( myInfos, instance, user );
167         populatePostalCode( myInfos, instance, user );
168         populateArrondissement( myInfos, instance, user );
169         populateGeoJson( myInfos, instance, user );
170         populateILiveInParisFlag( myInfos, instance, user );
171         populateStayConnectedFlag( myInfos, instance, user );
172         populateSendAccountValidationFlag( myInfos, instance, user );
173         populateAccountVerifiedFlag( myInfos, instance, user );
174 
175     }
176 
177     /**
178      * load UserNickName
179      * 
180      * @param strLuteceUserName
181      *            strLuteceUserName
182      * @return UserNickName
183      */
184     public static String loadUserNickname( String strLuteceUserName )
185     {
186 
187         return UserPreferencesService.instance( ).getNickname( strLuteceUserName );
188 
189     }
190 
191     /**
192      * load UserNickName
193      * 
194      * @param strNickName
195      *            Data
196      * 
197      * @return UserNickName
198      */
199     public static boolean isNicknameAlreadyExist( String strNickName )
200     {
201 
202         return !StringUtils.isEmpty( strNickName ) && UserPreferencesService.instance( ).existsNickname( strNickName.trim( ) );
203 
204     }
205 
206     /**
207      * return true if the user is verified
208      * 
209      * @param user
210      *            The User
211      * @return true if the user is verified
212      */
213     public static boolean isAccountVerified( LuteceUser user )
214     {
215 
216         String bEnableValidationAccount = DatastoreService.getDataValue( KEY_ENABLE_VALIDATION_ACCOUNT, "false" );
217 
218         if ( new Boolean( bEnableValidationAccount ) )
219         {
220 
221             // test if the user have verified his account
222             boolean bpVerified = UserPreferencesService.instance( ).getBoolean( user.getName( ), PREF_KEY_ACCOUNT_VERIFIED, false );
223             boolean openamVerified = user.getUserInfo( LUTECE_USER_KEY_VERIFIED ) != null ? new Boolean( user.getUserInfo( LUTECE_USER_KEY_VERIFIED ) ) : false;
224 
225             return openamVerified || bpVerified;
226         }
227 
228         return true;
229     }
230 
231     /**
232      * Update user preference Stay connected
233      * 
234      * @param strUid
235      *            the user uid
236      * @param stayConnected
237      *            true if the user want stay connected
238      */
239     public static void updatePreferenceStayConnected( String strUid, boolean stayConnected )
240     {
241         IPortalUserPreferencesService instance = UserPreferencesService.instance( );
242         if ( stayConnected )
243 
244         {
245             instance.put( strUid, PREF_KEY_STAYCONNECTED, PREF_VALUE_ON );
246         }
247         else
248         {
249             instance.put( strUid, PREF_KEY_STAYCONNECTED, PREF_VALUE_OFF );
250         }
251 
252     }
253 
254     /**
255      * Save Users info into ParisConnect and local preferences
256      * 
257      * @param strLuteceUserName
258      *            Data
259      * @param strToken
260      *            Data
261      * @param myInfos
262      *            The infos
263      */
264     public static void saveUserInfos( String strLuteceUserName, String strToken, MyInfosForm myInfos )
265     {
266         IPortalUserPreferencesService instance = UserPreferencesService.instance( );
267 
268         boolean bUpdateUserSubscribePreference = false;
269 
270         String strStayConnectedPreference = instance.get( strLuteceUserName, PREF_KEY_STAYCONNECTED, PREF_VALUE_OFF );
271         String strStayConnectedPostForm = StringUtils.isNotEmpty( myInfos.getStayconnected( ) ) ? myInfos.getStayconnected( ) : PREF_VALUE_OFF;
272 
273         bUpdateUserSubscribePreference = !strStayConnectedPostForm.equals( strStayConnectedPreference );
274 
275         // instance.clear( user.getName( ) );
276         String strCreationDate = instance.get( strLuteceUserName, PREF_KEY_CREATIONDATE, StringUtils.EMPTY );
277 
278         if ( strCreationDate == null || strCreationDate.isEmpty( ) )
279         {
280             Date dCreationDate = new Date( Calendar.getInstance( ).getTime( ).getTime( ) );
281             instance.put( strLuteceUserName, PREF_KEY_CREATIONDATE, dCreationDate.toString( ) );
282         }
283 
284         instance.put( strLuteceUserName, PREF_KEY_FIRSTNAME, myInfos.getFirstname( ) );
285         instance.put( strLuteceUserName, PREF_KEY_LASTNAME, myInfos.getLastname( ) );
286         instance.put( strLuteceUserName, PREF_KEY_ADDRESS, myInfos.getAddress( ) );
287         instance.put( strLuteceUserName, PREF_KEY_BIRTHDATE, myInfos.getBirthdate( ) );
288         instance.put( strLuteceUserName, PREF_KEY_ILIVEINPARIS, myInfos.getIliveinparis( ) );
289         instance.put( strLuteceUserName, PREF_KEY_CIVILITY, myInfos.getCivility( ) );
290         instance.put( strLuteceUserName, PREF_KEY_POSTAL_CODE, myInfos.getPostalCode( ) );
291         instance.put( strLuteceUserName, PREF_KEY_ARRONDISSEMENT_VOTE, myInfos.getArrondissement( ) );
292 
293         instance.put( strLuteceUserName, PREF_KEY_STAYCONNECTED,
294                 StringUtils.isNotEmpty( myInfos.getStayconnected( ) ) ? myInfos.getStayconnected( ) : PREF_VALUE_OFF );
295         instance.put( strLuteceUserName, PREF_KEY_SEND_ACCOUNT_VALIDATION, myInfos.getSendaccountvalidation( ) );
296 
297         instance.put( strLuteceUserName, PREF_KEY_GEO_JSON, myInfos.getGeojson( ) );
298 
299         // subscribe alert
300         if ( bUpdateUserSubscribePreference )
301         {
302             subscribeAltertParisConnect( strLuteceUserName, myInfos );
303         }
304         myInfos.setIsValid( isUserValid( myInfos ) );
305 
306         if ( !StringUtils.isEmpty( myInfos.getNickname( ) ) && !StringUtils.isEmpty( instance.getNickname( strLuteceUserName ) )
307                 && !myInfos.getNickname( ).equals( instance.getNickname( strLuteceUserName ) ) )
308         {
309             instance.setNickname( strLuteceUserName, myInfos.getNickname( ) );
310             MyInfosListenerService.updateNickName( strLuteceUserName, myInfos.getNickname( ) );
311 
312         }
313         else
314             if ( StringUtils.isEmpty( instance.getNickname( strLuteceUserName ) ) )
315             {
316 
317                 MyInfosListenerService.createNickName( strLuteceUserName, myInfos.getNickname( ) );
318             }
319         instance.setNickname( strLuteceUserName, myInfos.getNickname( ) );
320 
321     }
322 
323     /**
324      * Save Users email into localPreferences
325      * 
326      * @param strLuteceUserName
327      *            The User name
328      * @param strEmail
329      *            The email
330      */
331     public static void saveUserEmail( String strLuteceUserName, String strEmail )
332     {
333         IPortalUserPreferencesService instance = UserPreferencesService.instance( );
334         instance.put( strLuteceUserName, PREF_KEY_EMAIL, strEmail );
335     }
336 
337     /**
338      * Gives the user email
339      * 
340      * @param strLuteceUserName
341      *            The User name
342      * @return the user email
343      */
344     public static String getUserEmail( String strLuteceUserName )
345     {
346         return UserPreferencesService.instance( ).get( strLuteceUserName, PREF_KEY_EMAIL, StringUtils.EMPTY );
347     }
348 
349     /**
350      * check if a validation mail must be send to the user
351      * 
352      * @param strLuteceUserName
353      *            The User name
354      * @param myInfos
355      *            the user information
356      * @return True if account validation is required
357      */
358     public static boolean mustSendAccountValidationMail( String strLuteceUserName, MyInfosForm myInfos )
359     {
360 
361         String bEnableValidationAccount = DatastoreService.getDataValue( KEY_ENABLE_VALIDATION_ACCOUNT, "false" );
362 
363         return new Boolean( bEnableValidationAccount ) && StringUtils.isNotEmpty( myInfos.getSendaccountvalidation( ) );
364     }
365 
366     /**
367      * Send account validation mail if the user never have validation mail
368      * 
369      * @param request
370      *            The request
371      * @param locale
372      *            The locale
373      * @param strUid
374      *            The account UID
375      * @return True if process is ok, then false.
376      * 
377      */
378     public static boolean sendAccountValidationMail( HttpServletRequest request, Locale locale, String strUid )
379     {
380 
381         String strBackUrl = DatastoreService.getDataValue( KEY_SEND_ACCOUNT_VALIDATION_BACK_URL, "https://budgetparticipatif.paris.fr/bp/je-vote.html" );
382         // return
383         // ParisConnectService.getInstance().verification(user.getEmail(),
384         // strReturnUrl);
385         try
386         {
387             Account account = OpenamIdentityService.getService( ).getAccount( strUid );
388             NotificationService.getService( ).doNotifyUser( request, locale, account, TYPE_VALIDATE_ACCOUNT, TYPE_VALIDATE_ACCOUNT,
389                     ManageAccountXPage.getActivateAccountUrl( request ), strBackUrl );
390 
391         }
392         catch( OpenamIdentityException e )
393         {
394             AppLogService.error( e );
395             return false;
396         }
397 
398         return true;
399     }
400 
401     /**
402      * Provides the list of arrondissements
403      * 
404      * @return The list
405      */
406     public static ReferenceList getArrondissements( )
407     {
408         if ( _listArrondissements == null )
409         {
410             synchronized( MyInfosService.class )
411             {
412                 if ( _listArrondissements == null )
413                 {
414                     _listArrondissements = new ReferenceList( );
415                     _listArrondissements.addItem( UNDEFINED_POSTALCODE_KEY, I18nService.getLocalizedString( PROPERTY_SELECT_ARRONDISSEMENT, Locale.FRENCH ) );
416 
417                     for ( int i = 0; i < 20; i++ )
418                     {
419                         String strCode = "" + ( 75001 + i );
420                         _listArrondissements.addItem( strCode, I18nService.getLocalizedString( PROPERTY_ARRONDISSEMENT + strCode, Locale.FRENCH ) );
421                     }
422                 }
423             }
424         }
425 
426         return _listArrondissements;
427     }
428 
429     /**
430      * Provides the list of arrondissements
431      * 
432      * @return The list
433      */
434     public static ReferenceList getPostalCodes( )
435     {
436         if ( _listPostalCode == null )
437         {
438             synchronized( MyInfosService.class )
439             {
440                 if ( _listPostalCode == null )
441                 {
442                     _listPostalCode = new ReferenceList( );
443                     _listPostalCode.addItem( UNDEFINED_POSTALCODE_KEY, I18nService.getLocalizedString( PROPERTY_SELECT_POSTAL_CODE, Locale.FRENCH ) );
444 
445                     for ( int i = 0; i < 20; i++ )
446                     {
447                         String strCode = "" + ( 75001 + i );
448                         _listPostalCode.addItem( strCode, strCode );
449                         if ( i == 15 )
450                         {
451                             _listPostalCode.addItem( I18nService.getLocalizedString( PROPERTY_SELECT_POSTAL_CODE_16_KEY, Locale.FRENCH ),
452                                     I18nService.getLocalizedString( PROPERTY_SELECT_POSTAL_CODE_16_LABEL, Locale.FRENCH ) );
453                         }
454                     }
455                 }
456             }
457         }
458 
459         return _listPostalCode;
460     }
461 
462     /**
463      * Calculate age
464      * 
465      * @param strBirthDate
466      *            The birth date as a String
467      * @return The age
468      * @throws ParseException
469      *             if parsing failed
470      */
471     public static int getAge( String strBirthDate ) throws ParseException
472     {
473         DateTimeFormatter formatter = DateTimeFormat.forPattern( "dd/MM/yyyy" );
474         DateTime dateBirthdate = formatter.parseDateTime( strBirthDate );
475         Years years = Years.yearsBetween( new LocalDate( dateBirthdate ), new LocalDate( ) );
476 
477         return years.getYears( );
478     }
479 
480     /**
481      * @param myInfos
482      *            My info form
483      * @return True if the address is valid
484      */
485     public static boolean setAdressValid( MyInfosForm myInfos )
486     {
487 
488         GeolocItem geolocItem = null;
489         try
490         {
491             geolocItem = GeolocItem.fromJSON( myInfos.getGeojson( ) );
492 
493             Matcher m = patternPostalCode.matcher( geolocItem.getAddress( ) );
494             m.find( );
495 
496             String strPostalCode = m.group( 1 );
497 
498             if ( !StringUtils.isEmpty( strPostalCode ) )
499             {
500                 myInfos.setLatitude( geolocItem.getLat( ) );
501                 myInfos.setLongitude( geolocItem.getLon( ) );
502                 myInfos.setAddress( geolocItem.getAddress( ) );
503                 myInfos.setPostalCode( strPostalCode );
504                 return true;
505             }
506 
507         }
508         catch( IOException e )
509         {
510 
511             AppLogService.error( "MyInfosApp: malformed data from client: address = " + myInfos.getGeojson( ) + "; exeception " + e );
512         }
513 
514         return false;
515 
516     }
517 
518     /**
519      * Check if a user is valid or not
520      * 
521      * @param myInfos
522      *            True if the user is valid, valse otherwise
523      * @return
524      */
525     private static boolean isUserValid( MyInfosForm myInfos )
526     {
527         return StringUtils.isNotBlank( myInfos.getCivility( ) )
528                 // && StringUtils.isNotBlank(myInfos.getNickname())
529                 && StringUtils.isNotBlank( myInfos.getAddress( ) ) && StringUtils.isNotBlank( myInfos.getPostalCode( ) )
530                 && StringUtils.isNotBlank( myInfos.getArrondissement( ) ) && !UNDEFINED_POSTALCODE_KEY.equals( myInfos.getArrondissement( ) )
531                 && StringUtils.isNotBlank( myInfos.getBirthdate( ) )
532                 && ( StringUtils.isNotBlank( myInfos.getIliveinparis( ) ) && myInfos.getIliveinparis( ).equals( PREF_VALUE_ON ) );
533     }
534 
535     /**
536      * Update Paris Connect Information
537      * 
538      * @param user
539      * @param myInfos
540      */
541     private static void subscribeAltertParisConnect( String strToken, MyInfosForm myInfos )
542     {
543         String strSubscribeIdAlerte = DatastoreService.getDataValue( KEY_PARIS_CONNECT_SUSBCIBE_ID_ALERTE, "91" );
544         if ( StringUtils.isNotEmpty( myInfos.getStayconnected( ) ) && myInfos.getStayconnected( ).equals( PREF_VALUE_ON ) )
545         {
546             ParisConnectService.getInstance( ).subscribeAlert( strToken, strSubscribeIdAlerte );
547         }
548         else
549         {
550             ParisConnectService.getInstance( ).unSubscribeAlert( strToken, strSubscribeIdAlerte );
551         }
552 
553     }
554 
555     /**
556      * Populates the nickname into the specified information form.
557      * 
558      * @param myInfos
559      *            the information form
560      * @param userPreferenceService
561      *            the service containing the user preferences
562      * @param user
563      *            the connected user
564      */
565     private static void populateNickname( MyInfosForm myInfos, IPortalUserPreferencesService userPreferenceService, LuteceUser user )
566     {
567         String strNickname = userPreferenceService.getNickname( user );
568 
569         if ( !CampagnesService.getInstance( ).isDuring( Constants.VOTE ) && StringUtils.isBlank( strNickname ) )
570         {
571             myInfos.setIsValid( false );
572         }
573 
574         myInfos.setNickname( strNickname );
575     }
576 
577     /**
578      * Populates the civility into the specified information form.
579      * 
580      * @param myInfos
581      *            the information form
582      * @param userPreferenceService
583      *            the service containing the user preferences
584      * @param user
585      *            the connected user
586      */
587     private static void populateCivility( MyInfosForm myInfos, IPortalUserPreferencesService userPreferenceService, LuteceUser user )
588     {
589         String strCivility = userPreferenceService.get( user.getName( ), PREF_KEY_CIVILITY, null );
590 
591         if ( strCivility == null )
592         {
593             myInfos.setIsValid( false );
594 
595             strCivility = Civility.fromNumericCode( user.getUserInfo( LuteceUser.GENDER ) ).getLabelCode( );
596         }
597 
598         myInfos.setCivility( strCivility );
599     }
600 
601     /**
602      * Populates the first name into the specified information form.
603      * 
604      * @param myInfos
605      *            the information form
606      * @param userPreferenceService
607      *            the service containing the user preferences
608      * @param user
609      *            the connected user
610      */
611     private static void populateFirstName( MyInfosForm myInfos, IPortalUserPreferencesService userPreferenceService, LuteceUser user )
612     {
613         String strFirstName = userPreferenceService.get( user.getName( ), PREF_KEY_FIRSTNAME, null );
614 
615         myInfos.setFirstname( strFirstName != null ? strFirstName : user.getUserInfo( LuteceUser.NAME_GIVEN ) );
616     }
617 
618     /**
619      * Populates the last name into the specified information form.
620      * 
621      * @param myInfos
622      *            the information form
623      * @param userPreferenceService
624      *            the service containing the user preferences
625      * @param user
626      *            the connected user
627      */
628     private static void populateLastName( MyInfosForm myInfos, IPortalUserPreferencesService userPreferenceService, LuteceUser user )
629     {
630         String strLastName = userPreferenceService.get( user.getName( ), PREF_KEY_LASTNAME, null );
631 
632         if ( strLastName == null )
633         {
634             strLastName = user.getUserInfo( LuteceUser.NAME_FAMILY );
635 
636             if ( StringUtils.isEmpty( strLastName ) )
637             {
638                 strLastName = user.getUserInfo( LuteceUser.NAME_CIVILITY );
639             }
640         }
641 
642         myInfos.setLastname( strLastName );
643     }
644 
645     /**
646      * Populates the birth date into the specified information form.
647      * 
648      * @param myInfos
649      *            the information form
650      * @param userPreferenceService
651      *            the service containing the user preferences
652      * @param user
653      *            the connected user
654      */
655     private static void populateBirthDate( MyInfosForm myInfos, IPortalUserPreferencesService userPreferenceService, LuteceUser user )
656     {
657         String strBirthDate = userPreferenceService.get( user.getName( ), PREF_KEY_BIRTHDATE, null );
658 
659         if ( strBirthDate == null )
660         {
661             myInfos.setIsValid( false );
662 
663             strBirthDate = user.getUserInfo( LuteceUser.BDATE );
664         }
665 
666         myInfos.setBirthdate( strBirthDate );
667     }
668 
669     /**
670      * Populates the address into the specified information form.
671      * 
672      * @param myInfos
673      *            the information form
674      * @param userPreferenceService
675      *            the service containing the user preferences
676      * @param user
677      *            the connected user
678      */
679     private static void populateAddress( MyInfosForm myInfos, IPortalUserPreferencesService userPreferenceService, LuteceUser user )
680     {
681         String strAddress = userPreferenceService.get( user.getName( ), PREF_KEY_ADDRESS, null );
682 
683         if ( strAddress == null )
684         {
685             myInfos.setIsValid( false );
686 
687             String strCity = user.getUserInfo( LuteceUser.HOME_INFO_POSTAL_CITY );
688 
689             if ( _listAuthorizedCities.contains( strCity.trim( ).toLowerCase( ) ) )
690             {
691                 strAddress = user.getUserInfo( LuteceUser.HOME_INFO_POSTAL_STREET ) + ADDRESS_SEPARATOR
692                         + user.getUserInfo( LuteceUser.HOME_INFO_POSTAL_POSTALCODE ) + ADDRESS_SEPARATOR + strCity;
693             }
694         }
695 
696         myInfos.setAddress( strAddress );
697     }
698 
699     /**
700      * Populates the postal code into the specified information form.
701      * 
702      * @param myInfos
703      *            the information form
704      * @param userPreferenceService
705      *            the service containing the user preferences
706      * @param user
707      *            the connected user
708      */
709     private static void populatePostalCode( MyInfosForm myInfos, IPortalUserPreferencesService userPreferenceService, LuteceUser user )
710     {
711         String strPostalCode = userPreferenceService.get( user.getName( ), PREF_KEY_POSTAL_CODE, StringUtils.EMPTY );
712 
713         if ( StringUtils.isBlank( strPostalCode ) )
714         {
715             myInfos.setIsValid( false );
716         }
717 
718         myInfos.setPostalCode( strPostalCode );
719     }
720 
721     /**
722      * Populates the arrondissement into the specified information form.
723      * 
724      * @param myInfos
725      *            the information form
726      * @param userPreferenceService
727      *            the service containing the user preferences
728      * @param user
729      *            the connected user
730      */
731     private static void populateArrondissement( MyInfosForm myInfos, IPortalUserPreferencesService userPreferenceService, LuteceUser user )
732     {
733         String strArrondissement = userPreferenceService.get( user.getName( ), PREF_KEY_ARRONDISSEMENT_VOTE, StringUtils.EMPTY );
734 
735         if ( CampagnesService.getInstance( ).isAfterBeginning( Constants.SUBMIT ) && CampagnesService.getInstance( ).isBeforeEnd( Constants.VOTE )
736                 && ( StringUtils.isBlank( strArrondissement ) || UNDEFINED_POSTALCODE_KEY.equals( strArrondissement ) ) )
737         {
738             myInfos.setIsValid( false );
739         }
740 
741         myInfos.setArrondissement( strArrondissement );
742     }
743 
744     /**
745      * Populates the geo json into the specified information form.
746      * 
747      * @param myInfos
748      *            the information form
749      * @param userPreferenceService
750      *            the service containing the user preferences
751      * @param user
752      *            the connected user
753      */
754     private static void populateGeoJson( MyInfosForm myInfos, IPortalUserPreferencesService userPreferenceService, LuteceUser user )
755     {
756         String strGeoJson = userPreferenceService.get( user.getName( ), PREF_KEY_GEO_JSON, StringUtils.EMPTY );
757 
758         if ( StringUtils.isBlank( strGeoJson ) )
759         {
760             myInfos.setIsValid( false );
761         }
762 
763         myInfos.setGeojson( strGeoJson );
764     }
765 
766     /**
767      * Populates the flag ILiveInParis into the specified information form.
768      * 
769      * @param myInfos
770      *            the information form
771      * @param userPreferenceService
772      *            the service containing the user preferences
773      * @param user
774      *            the connected user
775      */
776     private static void populateILiveInParisFlag( MyInfosForm myInfos, IPortalUserPreferencesService userPreferenceService, LuteceUser user )
777     {
778         if ( userPreferenceService.existsKey( user.getName( ), PREF_KEY_ILIVEINPARIS ) )
779         {
780             String strILiveInParis = userPreferenceService.get( user.getName( ), PREF_KEY_ILIVEINPARIS, PREF_VALUE_OFF );
781 
782             if ( PREF_VALUE_OFF.equals( strILiveInParis ) )
783             {
784                 myInfos.setIsValid( false );
785             }
786 
787             myInfos.setIliveinparis( strILiveInParis );
788         }
789         else
790         {
791             myInfos.setIsValid( false );
792 
793             myInfos.setIliveinparis( DEFAULT_CHECKED );
794         }
795     }
796 
797     /**
798      * Populates the stay connected flag into the specified information form.
799      * 
800      * @param myInfos
801      *            the information form
802      * @param userPreferenceService
803      *            the service containing the user preferences
804      * @param user
805      *            the connected user
806      */
807     private static void populateStayConnectedFlag( MyInfosForm myInfos, IPortalUserPreferencesService userPreferenceService, LuteceUser user )
808     {
809         if ( userPreferenceService.existsKey( user.getName( ), PREF_KEY_STAYCONNECTED ) )
810         {
811             myInfos.setStayconnected( userPreferenceService.get( user.getName( ), PREF_KEY_STAYCONNECTED, PREF_VALUE_OFF ) );
812         }
813         else
814         {
815             myInfos.setStayconnected( DEFAULT_CHECKED );
816         }
817     }
818 
819     /**
820      * Populates the send account validation flag into the specified information form.
821      * 
822      * @param myInfos
823      *            the information form
824      * @param userPreferenceService
825      *            the service containing the user preferences
826      * @param user
827      *            the connected user
828      */
829     private static void populateSendAccountValidationFlag( MyInfosForm myInfos, IPortalUserPreferencesService userPreferenceService, LuteceUser user )
830     {
831         if ( userPreferenceService.existsKey( user.getName( ), PREF_KEY_SEND_ACCOUNT_VALIDATION ) )
832         {
833             myInfos.setSendaccountvalidation( userPreferenceService.get( user.getName( ), PREF_KEY_SEND_ACCOUNT_VALIDATION, PREF_VALUE_OFF ) );
834         }
835         else
836         {
837             myInfos.setSendaccountvalidation( DEFAULT_CHECKED );
838         }
839     }
840 
841     /**
842      * Populates the account verified validation flag into the specified information form.
843      * 
844      * @param myInfos
845      *            the information form
846      * @param userPreferenceService
847      *            the service containing the user preferences
848      * @param user
849      *            the connected user
850      */
851     private static void populateAccountVerifiedFlag( MyInfosForm myInfos, IPortalUserPreferencesService userPreferenceService, LuteceUser user )
852     {
853         myInfos.setAccountVerified( userPreferenceService.getBoolean( user.getName( ), PREF_KEY_ACCOUNT_VERIFIED, false ) );
854     }
855 
856 }