Added input validation in invitation form (issue #1815)
authorChristos Stathis <chstath@ebs.gr>
Mon, 9 Jan 2012 15:47:17 +0000 (17:47 +0200)
committerChristos Stathis <chstath@ebs.gr>
Mon, 9 Jan 2012 15:47:17 +0000 (17:47 +0200)
src/gr/grnet/pithos/web/client/InvitationsDialog.java
src/gr/grnet/pithos/web/public/pithos.css

index d4a5635..3b11130 100644 (file)
@@ -262,28 +262,40 @@ public class InvitationsDialog extends DialogBox {
        }
 
        void sendInvitation(String email, final String realname) {
-               PostRequest sendInvitation = new PostRequest("/im/", "", "invite", "uniq=" + email + "&realname=" + realname) {
-                       
-                       @Override
-                       protected void onUnauthorized(Response response) {
-                               app.sessionExpired();
-                       }
-                       
-                       @Override
-                       public void onSuccess(Resource result) {
-                               HTML msg = new HTML("Invitation to <span class='user'>" + realname + "</span> was sent.");
-                               msg.addStyleName("pithos-invitationResponse");
-                               messagesPanel.add(msg);
+               if (realname == null || realname.length() == 0) {
+                       HTML msg = new HTML("Name cannot be empty");
+                       msg.addStyleName("pithos-invitationResponseError");
+                       messagesPanel.add(msg);
+               }
+               else if (email == null || email.length() == 0 || !email.contains("@") || 
+                               email.substring(email.indexOf("@")).length() < 3 || !email.substring(email.indexOf("@") + 2).contains(".")) {
+                       HTML msg = new HTML("Invalid email");
+                       msg.addStyleName("pithos-invitationResponseError");
+                       messagesPanel.add(msg);
+               }
+               else {
+                       PostRequest sendInvitation = new PostRequest("/im/", "", "invite", "uniq=" + email + "&realname=" + realname) {
                                
-                       }
-                       
-                       @Override
-                       public void onError(Throwable t) {
-                               GWT.log("", t);
-                       }
-               };
-               sendInvitation.setHeader("X-Auth-Token", app.getToken());
-               Scheduler.get().scheduleDeferred(sendInvitation);
+                               @Override
+                               protected void onUnauthorized(Response response) {
+                                       app.sessionExpired();
+                               }
+                               
+                               @Override
+                               public void onSuccess(Resource result) {
+                                       HTML msg = new HTML("Invitation to <span class='user'>" + realname + "</span> was sent.");
+                                       msg.addStyleName("pithos-invitationResponse");
+                                       messagesPanel.add(msg);
+                               }
+                               
+                               @Override
+                               public void onError(Throwable t) {
+                                       GWT.log("", t);
+                               }
+                       };
+                       sendInvitation.setHeader("X-Auth-Token", app.getToken());
+                       Scheduler.get().scheduleDeferred(sendInvitation);
+               }
        }
        
        void fillSentInvitationsTable(Invitations inv) {
index 62a55e6..dd69521 100644 (file)
@@ -555,6 +555,12 @@ a.pithos-tag {
        padding: 5px;
 }
 
+.pithos-invitationResponseError {
+       background-color: #880000;
+       color: #fff;
+       padding: 5px;
+}
+
 .pithos-invitationResponse .user {
        font-weight: bold;
 }