Author: benj
Date: Tue May 10 11:43:18 2016
New Revision: 1671

URL: http://svn.gna.org/viewcvs/gdtc?rev=1671&view=rev
Log:
Add basic mail syntax checks (#20076)

Modified:
    trunk/gdtc/include/person.php

Modified: trunk/gdtc/include/person.php
URL: 
http://svn.gna.org/viewcvs/gdtc/trunk/gdtc/include/person.php?rev=1671&r1=1670&r2=1671&view=diff
==============================================================================
--- trunk/gdtc/include/person.php       (original)
+++ trunk/gdtc/include/person.php       Tue May 10 11:43:18 2016
@@ -2,7 +2,7 @@
 
 /* ************************************************************************** 
*/
 /*                                                                            
*/
-/*     Copyright (C)   2009 Benjamin Drieu ([email protected])                */
+/*     Copyright (C)   2016 Benjamin Drieu ([email protected])                */
 /*                                                                            
*/
 /*  This program is free software; you can redistribute it and/or modify      
*/
 /*  it under the terms of the GNU General Public License as published by      
*/
@@ -163,9 +163,21 @@
     if ( $args [ 'disbar_date' ] ) 
        $args [ 'disbar_date' ]  = arg2sqldate ( $args [ 'disbar_date' ], false 
);
 
+    $additional = Array ();
+    if ( ! $args [ 'email' ] ||
+        ! preg_match ( '/^[^@]+@[a-z0-9\.-]+\.[a-z]+$/i', $args [ 'email' ] ) )
+    {
+       $additional [ 'error' ] = 'Adresse de courriel invalide.';
+       unset ( $args [ 'email' ] );
+    }
+
     /* Update MySQL */
-    $additional = commit ( $actor [ 'actor_type' ], 'actor_id', $actor_id, 
$args ); 
-    $additional = commit ( 'actor', 'actor_id', $actor_id, $args ); 
+    $additional = array_merge ( $additional, commit ( $actor [ 'actor_type' ], 
'actor_id', $actor_id, $args ) ); 
+    $additional = array_merge ( $additional, commit ( 'actor', 'actor_id', 
$actor_id, $args ) );
+    if ( $additional [ 'message' ] [ 'warning' ]  == 'Pas de modification' )
+    {
+       unset ( $additional [ 'message'] [ 'warning' ] );
+    }
 
     // We do this AFTER committing actor to prevent our validation to be
     // shadowed by the actual commit.
@@ -224,8 +236,28 @@
        }
     }
 
-    // TODO: Trouver un moyen de passer un message
-    redirect ( '?action=edit&table=actor&id=' . $actor_id );
+    $url = sprintf ('?action=edit&table=actor&id=%s', $actor_id );
+    if ( $additional [ 'message' ] [ 'notice' ] )
+    {
+       $url .= sprintf ( '&notice=%s', $additional [ 'message' ] [ 'notice' ] 
);
+    }
+    if ( $additional [ 'message' ] [ 'warning' ] )
+    {
+       $url .= sprintf ( '&warning=%s', $additional [ 'message' ] [ 'warning' 
] );
+    }
+    if ( $additional [ 'message' ] [ 'error' ] )
+    {
+       $url .= sprintf ( '&error=%s', $additional [ 'message' ] [ 'error' ] );
+    }
+    if ( $additional [ 'error' ] ) /* This is stupid because I do not
+                                   * handle $xxx['messages']
+                                   * correctly and they are fucked
+                                   * by the array_merge before. */
+    {
+       $url .= sprintf ( '&error=%s', $additional [ 'error' ] );
+    }
+
+    redirect ( $url );
 }
 
 


_______________________________________________
Gdtc-commits mailing list
[email protected]
https://mail.gna.org/listinfo/gdtc-commits

Reply via email to