Fixing problems various in membership application and addition
authorAdam Chlipala <adamc@hcoop.net>
Fri, 22 Feb 2008 00:59:15 +0000 (00:59 +0000)
committerAdam Chlipala <adamc@hcoop.net>
Fri, 22 Feb 2008 00:59:15 +0000 (00:59 +0000)
app.sig
app.sml
app/app.sig
app/app.sml
app/join.mlt
apps.mlt
init.sml
money.mlt
portal.mlt
users.mlt

diff --git a/app.sig b/app.sig
index f31c5be..14fa153 100644 (file)
--- a/app.sig
+++ b/app.sig
@@ -6,6 +6,7 @@ sig
           | ACCEPTED
           | REJECTED
           | ADDED
           | ACCEPTED
           | REJECTED
           | ADDED
+          | BEING_ADDED
 
     val readTosBody : unit -> string
     val readTosAgree : unit -> string
 
     val readTosBody : unit -> string
     val readTosAgree : unit -> string
@@ -20,7 +21,7 @@ sig
                 paypal : string option, checkout : string option }
 
     val lookupApp : int -> app
                 paypal : string option, checkout : string option }
 
     val lookupApp : int -> app
-    val listApps : status -> app list
+    val listApps : status list -> app list
 
     val votes : int -> (int * string) list
     val vote : int * int -> unit
 
     val votes : int -> (int * string) list
     val vote : int * int -> unit
@@ -28,6 +29,7 @@ sig
 
     val deny : int * string -> bool
     val approve : int * string -> bool
 
     val deny : int * string -> bool
     val approve : int * string -> bool
+    val preAdd : int -> unit
     val add : int -> unit
     val abortAdd : int -> unit
     val welcome : int -> unit
     val add : int -> unit
     val abortAdd : int -> unit
     val welcome : int -> unit
diff --git a/app.sml b/app.sml
index 1941e2d..6d603ea 100644 (file)
--- a/app.sml
+++ b/app.sml
@@ -9,6 +9,7 @@ datatype status =
        | ACCEPTED
        | REJECTED
        | ADDED
        | ACCEPTED
        | REJECTED
        | ADDED
+       | BEING_ADDED
 
 val statusFromInt =
     fn 0 => CONFIRMING
 
 val statusFromInt =
     fn 0 => CONFIRMING
@@ -16,6 +17,7 @@ val statusFromInt =
      | 2 => ACCEPTED
      | 3 => REJECTED
      | 4 => ADDED
      | 2 => ACCEPTED
      | 3 => REJECTED
      | 4 => ADDED
+     | 5 => BEING_ADDED
      | _ => raise C.Sql "Bad status"
 
 val statusToInt =
      | _ => raise C.Sql "Bad status"
 
 val statusToInt =
@@ -24,6 +26,7 @@ val statusToInt =
      | ACCEPTED => 2
      | REJECTED => 3
      | ADDED => 4
      | ACCEPTED => 2
      | REJECTED => 3
      | ADDED => 4
+     | BEING_ADDED => 5
 
 fun statusFromSql v = statusFromInt (C.intFromSql v)
 fun statusToSql s = C.intToSql (statusToInt s)
 
 fun statusFromSql v = statusFromInt (C.intFromSql v)
 fun statusToSql s = C.intToSql (statusToInt s)
@@ -58,11 +61,11 @@ fun lookupApp id =
        SOME row => mkAppRow row
       | NONE => raise Fail "Membership application not found"
 
        SOME row => mkAppRow row
       | NONE => raise Fail "Membership application not found"
 
-fun listApps status =
+fun listApps statuses =
     C.map (getDb ()) mkAppRow ($`SELECT id, name, rname, gname, email, forward, uses, other, passwd, status, applied, ipaddr, confirmed, decided,
                                        msg, unix_passwd, paypal, checkout
                                 FROM MemberApp
     C.map (getDb ()) mkAppRow ($`SELECT id, name, rname, gname, email, forward, uses, other, passwd, status, applied, ipaddr, confirmed, decided,
                                        msg, unix_passwd, paypal, checkout
                                 FROM MemberApp
-                                WHERE status = ^(statusToSql status)
+                                WHERE status IN (^(String.concatWith "," (map statusToSql statuses)))
                                   AND NOT (status = 2 AND decided < CURRENT_TIMESTAMP - INTERVAL '1 MONTH')
                                 ORDER BY applied`)
 
                                   AND NOT (status = 2 AND decided < CURRENT_TIMESTAMP - INTERVAL '1 MONTH')
                                 ORDER BY applied`)
 
@@ -116,10 +119,15 @@ fun approve (app, msg) =
        OS.Process.isSuccess (Mail.mclose mail)
     end
 
        OS.Process.isSuccess (Mail.mclose mail)
     end
 
+fun preAdd app =
+    ignore (C.dml (getDb ()) ($`UPDATE MemberApp
+                               SET status = 5
+                               WHERE id = ^(C.intToSql app)`))
+
 fun add app =
     let
        val _ = C.dml (getDb ()) ($`UPDATE MemberApp
 fun add app =
     let
        val _ = C.dml (getDb ()) ($`UPDATE MemberApp
-                                   SET status = 3
+                                   SET status = 4
                                    WHERE id = ^(C.intToSql app)`)
 
        val app = lookupApp app
                                    WHERE id = ^(C.intToSql app)`)
 
        val app = lookupApp app
index 8df47d8..2b7de99 100644 (file)
@@ -16,7 +16,7 @@ sig
     val apply : application -> string option
 
     val validEmail : string -> bool
     val apply : application -> string option
 
     val validEmail : string -> bool
-    val validUser : string -> bool
+    val validUsername : string -> bool
     val userExists : string -> bool
 
     val confirm : int * string -> bool
     val userExists : string -> bool
 
     val confirm : int * string -> bool
index db3fe9d..bbc12fa 100644 (file)
@@ -159,10 +159,11 @@ fun validHost s =
 fun validDomain s =
     size s > 0 andalso size s < 100 andalso List.all validHost (String.fields (fn ch => ch = #".") s)
 
 fun validDomain s =
     size s > 0 andalso size s < 100 andalso List.all validHost (String.fields (fn ch => ch = #".") s)
 
-fun validUser s =
-    size s > 0 andalso size s < 50 andalso List.all
-                                              (fn ch => isIdent ch orelse ch = #"." orelse ch = #"_" orelse ch = #"-" orelse ch = #"+")
-                                              (String.explode s)
+fun validUsername name =
+    size name <= 12
+    andalso size name > 0
+    andalso Char.isLower (String.sub (name, 0))
+    andalso CharVector.all Char.isAlphaNum name
 
 fun validEmailUser s =
     size s > 0 andalso size s < 50 andalso List.all
 
 fun validEmailUser s =
     size s > 0 andalso size s < 50 andalso List.all
index 1b39eac..ebb28d2 100644 (file)
@@ -22,7 +22,7 @@
                %><h3>Please enter your contact e-mail address</h3><%
        elseif uses = "" then
                %><h3>Please enter your proposed uses</h3><%
                %><h3>Please enter your contact e-mail address</h3><%
        elseif uses = "" then
                %><h3>Please enter your proposed uses</h3><%
-       elseif not (App.validUser name) then
+       elseif not (App.validUsername name) then
                %><h3>Invalid requested username</h3><%
        elseif App.userExists name then
                %><h3>That username is already in use.</b><h3><%
                %><h3>Invalid requested username</h3><%
        elseif App.userExists name then
                %><h3>That username is already in use.</b><h3><%
index 5fe3f2a..33fb346 100644 (file)
--- a/apps.mlt
+++ b/apps.mlt
@@ -83,7 +83,7 @@ elseif $"cmd" = "approved" then
 
        %><h3>Pending applications</h3><%
 
 
        %><h3>Pending applications</h3><%
 
-       foreach appl in App.listApps App.ACCEPTED do %>
+       foreach appl in App.listApps [App.ACCEPTED, App.BEING_ADDED] do %>
                <br><hr><br>
                <table class="blanks">
                <tr> <td>Received:</td> <td><% #applied appl %> (<% Util.diffFromNow (#applied appl) %> ago)</td> </tr>
                <br><hr><br>
                <table class="blanks">
                <tr> <td>Received:</td> <td><% #applied appl %> (<% Util.diffFromNow (#applied appl) %> ago)</td> </tr>
@@ -110,6 +110,7 @@ elseif $"cmd" = "approved" then
        <tr> <td>Forward e-mail?</td> <td><% if #forward appl then %>yes<% else %>no<% end %></td> </tr>
        <tr> <td>Proposed uses:</td> <td><% Web.htmlNl (#uses appl) %></td> </tr>
        <tr> <td>Other information:</td> <td><% Web.htmlNl (#other appl) %></td> </tr>
        <tr> <td>Forward e-mail?</td> <td><% if #forward appl then %>yes<% else %>no<% end %></td> </tr>
        <tr> <td>Proposed uses:</td> <td><% Web.htmlNl (#uses appl) %></td> </tr>
        <tr> <td>Other information:</td> <td><% Web.htmlNl (#other appl) %></td> </tr>
+       <% if #status appl = App.BEING_ADDED then %><tr> <td colspan="2" align="left"><font color="red"><b>WARNING: Someone already followed the add link for this application.  Maybe he forgot to finish.</b></font></td></tr><% end %>
        </table>
 
        <% if root then %>
        </table>
 
        <% if root then %>
@@ -121,7 +122,7 @@ elseif $"add" <> "" then
        showNormal := false;
        val id = Web.stoi ($"add");
        val appl = App.lookupApp id;
        showNormal := false;
        val id = Web.stoi ($"add");
        val appl = App.lookupApp id;
-       App.add id %>
+       App.preAdd id %>
 
 First, run this on deleuze:
 <blockquote><tt>new-user <% #name appl %> "<% #rname appl %>"<% if #forward appl then %> "<% #email appl %>"<% end %></tt></blockquote>
 
 First, run this on deleuze:
 <blockquote><tt>new-user <% #name appl %> "<% #rname appl %>"<% if #forward appl then %> "<% #email appl %>"<% end %></tt></blockquote>
@@ -160,7 +161,7 @@ end %>
 <% if showNormal then %>
 <h3>Pending applications</h3>
 
 <% if showNormal then %>
 <h3>Pending applications</h3>
 
-<% foreach appl in App.listApps App.PENDING do %>
+<% foreach appl in App.listApps [App.PENDING] do %>
        <br><hr><br>
        <table class="blanks">
        <tr> <td>Received:</td> <td><% #applied appl %> (<% Util.diffFromNow (#applied appl) %> ago)</td></tr>
        <br><hr><br>
        <table class="blanks">
        <tr> <td>Received:</td> <td><% #applied appl %> (<% Util.diffFromNow (#applied appl) %> ago)</td></tr>
index b4d537b..ba3b2bf 100644 (file)
--- a/init.sml
+++ b/init.sml
@@ -159,7 +159,7 @@ fun deleteUser id =
     C.dml (getDb ()) ($`DELETE FROM WebUser WHERE id = ^(C.intToSql id)`)
 
 fun validUsername name =
     C.dml (getDb ()) ($`DELETE FROM WebUser WHERE id = ^(C.intToSql id)`)
 
 fun validUsername name =
-    size name <= 10
+    size name <= 12
     andalso size name > 0
     andalso Char.isLower (String.sub (name, 0))
     andalso CharVector.all Char.isAlphaNum name
     andalso size name > 0
     andalso Char.isLower (String.sub (name, 0))
     andalso CharVector.all Char.isAlphaNum name
index e7413e5..2af1635 100644 (file)
--- a/money.mlt
+++ b/money.mlt
@@ -466,8 +466,11 @@ end %>
    val bal = Balance.lookupBalance (#bal you);
    val deposit = Balance.depositAmount (#id bal) %>
 
    val bal = Balance.lookupBalance (#bal you);
    val deposit = Balance.depositAmount (#id bal) %>
 
-<h3>Your balance: $<% Util.sub (#amount bal, deposit) %><br>
-Deposit: $<% deposit %></b> (3 months of dues at your current <a href="pledge">pledge level</a>)</h3>
+<!--h3>Your balance: $<% Util.sub (#amount bal, deposit) %><br>
+Deposit: $<% deposit %></b> (3 months of dues at your current <a href="pledge">pledge level</a>)</h3-->
+
+<h3>Your balance: $<% #amount bal %></h3>
+
 <% if (iff Group.inGroupName "money" then $"lookback" = "" else $"audit" <> "") then %><h3>Sum of all active balances: $<% Balance.sumOwnedBalances () %></h3><% end %>
 
 <a href="money?cmd=list">List all transactions</a><br>
 <% if (iff Group.inGroupName "money" then $"lookback" = "" else $"audit" <> "") then %><h3>Sum of all active balances: $<% Balance.sumOwnedBalances () %></h3><% end %>
 
 <a href="money?cmd=list">List all transactions</a><br>
index 03d8dbd..2875bc2 100644 (file)
@@ -13,8 +13,10 @@ val deposit = Balance.depositAmount (#id bal);
 <tr> <td><% #d trn %></td> <td><a href="money?trn=<% #id trn %>"><% Web.html (#descr trn) %></a></td> <td><% amount %>/<% #amount trn %></td> </tr>
 <% end %>
 </table>
 <tr> <td><% #d trn %></td> <td><a href="money?trn=<% #id trn %>"><% Web.html (#descr trn) %></a></td> <td><% amount %>/<% #amount trn %></td> </tr>
 <% end %>
 </table>
-<b>Balance: $<% Util.sub (#amount bal, deposit) %></b><br>
-<b>Deposit: $<% deposit %></b> (3 months of dues at your current <a href="pledge">pledge level</a>)
+<!--b>Balance: $<% Util.sub (#amount bal, deposit) %></b><br>
+<b>Deposit: $<% deposit %></b> (3 months of dues at your current <a href="pledge">pledge level</a>)-->
+
+<b>Balance: $<% #amount bal %></b>
 
 <% val polls = Poll.listCurrentPolls ();
 switch polls of
 
 <% val polls = Poll.listCurrentPolls ();
 switch polls of
index 6a6dfc8..2135308 100644 (file)
--- a/users.mlt
+++ b/users.mlt
@@ -27,6 +27,8 @@ if $"cmd" = "Create" then
                                Money.applyCharges trn
                        end;
 
                                Money.applyCharges trn
                        end;
 
+                       App.add ap;
+
                        if $"subscribe" = "on" then
                                if not (Pref.subscribe ("hcoop-announce", $"name" ^ Init.emailSuffix)) then
                                        %><h3>Error subscribing to hcoop-announce</h3><%
                        if $"subscribe" = "on" then
                                if not (Pref.subscribe ("hcoop-announce", $"name" ^ Init.emailSuffix)) then
                                        %><h3>Error subscribing to hcoop-announce</h3><%