From: Adam Chlipala Date: Fri, 22 Feb 2008 00:59:15 +0000 (+0000) Subject: Fixing problems various in membership application and addition X-Git-Url: http://git.hcoop.net/bpt/portal.git/commitdiff_plain/96bd398ee746f9f2975bc06b24fcbe7e430164fb Fixing problems various in membership application and addition --- diff --git a/app.sig b/app.sig index f31c5be..14fa153 100644 --- a/app.sig +++ b/app.sig @@ -6,6 +6,7 @@ sig | ACCEPTED | REJECTED | ADDED + | BEING_ADDED val readTosBody : unit -> string val readTosAgree : unit -> string @@ -20,7 +21,7 @@ sig 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 @@ -28,6 +29,7 @@ sig 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 diff --git a/app.sml b/app.sml index 1941e2d..6d603ea 100644 --- a/app.sml +++ b/app.sml @@ -9,6 +9,7 @@ datatype status = | ACCEPTED | REJECTED | ADDED + | BEING_ADDED val statusFromInt = fn 0 => CONFIRMING @@ -16,6 +17,7 @@ val statusFromInt = | 2 => ACCEPTED | 3 => REJECTED | 4 => ADDED + | 5 => BEING_ADDED | _ => raise C.Sql "Bad status" val statusToInt = @@ -24,6 +26,7 @@ val statusToInt = | ACCEPTED => 2 | REJECTED => 3 | ADDED => 4 + | BEING_ADDED => 5 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" -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 - 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`) @@ -116,10 +119,15 @@ fun approve (app, msg) = 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 - SET status = 3 + SET status = 4 WHERE id = ^(C.intToSql app)`) val app = lookupApp app diff --git a/app/app.sig b/app/app.sig index 8df47d8..2b7de99 100644 --- a/app/app.sig +++ b/app/app.sig @@ -16,7 +16,7 @@ sig 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 diff --git a/app/app.sml b/app/app.sml index db3fe9d..bbc12fa 100644 --- a/app/app.sml +++ b/app/app.sml @@ -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 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 diff --git a/app/join.mlt b/app/join.mlt index 1b39eac..ebb28d2 100644 --- a/app/join.mlt +++ b/app/join.mlt @@ -22,7 +22,7 @@ %>

Please enter your contact e-mail address

<% elseif uses = "" then %>

Please enter your proposed uses

<% - elseif not (App.validUser name) then + elseif not (App.validUsername name) then %>

Invalid requested username

<% elseif App.userExists name then %>

That username is already in use.

<% diff --git a/apps.mlt b/apps.mlt index 5fe3f2a..33fb346 100644 --- a/apps.mlt +++ b/apps.mlt @@ -83,7 +83,7 @@ elseif $"cmd" = "approved" then %>

Pending applications

<% - foreach appl in App.listApps App.ACCEPTED do %> + foreach appl in App.listApps [App.ACCEPTED, App.BEING_ADDED] do %>


@@ -110,6 +110,7 @@ elseif $"cmd" = "approved" then + <% if #status appl = App.BEING_ADDED then %><% end %>
Received: <% #applied appl %> (<% Util.diffFromNow (#applied appl) %> ago)
Forward e-mail? <% if #forward appl then %>yes<% else %>no<% end %>
Proposed uses: <% Web.htmlNl (#uses appl) %>
Other information: <% Web.htmlNl (#other appl) %>
WARNING: Someone already followed the add link for this application. Maybe he forgot to finish.
<% if root then %> @@ -121,7 +122,7 @@ elseif $"add" <> "" then showNormal := false; val id = Web.stoi ($"add"); val appl = App.lookupApp id; - App.add id %> + App.preAdd id %> First, run this on deleuze:
new-user <% #name appl %> "<% #rname appl %>"<% if #forward appl then %> "<% #email appl %>"<% end %>
@@ -160,7 +161,7 @@ end %> <% if showNormal then %>

Pending applications

-<% foreach appl in App.listApps App.PENDING do %> +<% foreach appl in App.listApps [App.PENDING] do %>


diff --git a/init.sml b/init.sml index b4d537b..ba3b2bf 100644 --- 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 = - size name <= 10 + size name <= 12 andalso size name > 0 andalso Char.isLower (String.sub (name, 0)) andalso CharVector.all Char.isAlphaNum name diff --git a/money.mlt b/money.mlt index e7413e5..2af1635 100644 --- a/money.mlt +++ b/money.mlt @@ -466,8 +466,11 @@ end %> val bal = Balance.lookupBalance (#bal you); val deposit = Balance.depositAmount (#id bal) %> -

Your balance: $<% Util.sub (#amount bal, deposit) %>
-Deposit: $<% deposit %> (3 months of dues at your current pledge level)

+ + +

Your balance: $<% #amount bal %>

+ <% if (iff Group.inGroupName "money" then $"lookback" = "" else $"audit" <> "") then %>

Sum of all active balances: $<% Balance.sumOwnedBalances () %>

<% end %> List all transactions
diff --git a/portal.mlt b/portal.mlt index 03d8dbd..2875bc2 100644 --- a/portal.mlt +++ b/portal.mlt @@ -13,8 +13,10 @@ val deposit = Balance.depositAmount (#id bal); <% end %>
Received: <% #applied appl %> (<% Util.diffFromNow (#applied appl) %> ago)
<% #d trn %> <% Web.html (#descr trn) %> <% amount %>/<% #amount trn %>
-Balance: $<% Util.sub (#amount bal, deposit) %>
-Deposit: $<% deposit %> (3 months of dues at your current pledge level) + + +Balance: $<% #amount bal %> <% val polls = Poll.listCurrentPolls (); switch polls of diff --git a/users.mlt b/users.mlt index 6a6dfc8..2135308 100644 --- a/users.mlt +++ b/users.mlt @@ -27,6 +27,8 @@ if $"cmd" = "Create" then Money.applyCharges trn end; + App.add ap; + if $"subscribe" = "on" then if not (Pref.subscribe ("hcoop-announce", $"name" ^ Init.emailSuffix)) then %>

Error subscribing to hcoop-announce

<%