[Ur] EUnurlify in code to be compiled to JavaScript[2]?
Marko Schütz Schmuck
markoschuetz at googlemail.com
Wed Apr 19 15:58:27 EDT 2017
Dear All,
I'm getting this error. I don't see why this happens. Please enlighten
me.
Thanks and best regards,
Marko
-------------- next part --------------
structure Theme = Ui.Make(Default)
type user = string
val expireSeconds = 3600 * 4
sequence sessionIds
table session : {Id : int, Key : int, Identifier : string, Expires : time}
PRIMARY KEY Id
task periodic 60 = fn () => dml (DELETE FROM session
WHERE Expires < CURRENT_TIMESTAMP)
type authMode
= {User : user, Session : int, Key : int}
cookie auth : authMode
fun newSession email =
ses <- nextval sessionIds;
now <- now;
key <- rand;
dml (INSERT INTO session (Id, Key, Identifier, Expires)
VALUES ({[ses]}, {[key]}, {[email]}, {[addSeconds now expireSeconds]}));
return {Session = ses, Key = key}
fun startSession (email : string) : transaction unit
= ses <- newSession email;
setCookie auth {Value = ({User = email} ++ ses),
Expires = None,
Secure = False}
fun serverLogin (r : {User : string, Pass : string}) : transaction unit
= u <- Password.authenticate r;
case u of
None => return ()
| Some user => startSession user
con toBool = fn (t :: Type) => bool
fun toBool_option [t ::: Type] (a : option t) : toBool (option t)
= case a of
None => False
| Some _ => True
fun some [t ::: Type] (op : option t) : t
= case op of
None => error <xml>Cannot get data from option None.</xml>
| Some d => d
fun main () : transaction page
= loggedIn <- source (None : option string);
scUser <- source "";
scPass <- source "";
c <- getCookie auth;
Theme.simple
"Main"
(Ui.moded (toBool_option c)
(Ui.const <xml>
<ctextbox source={scUser}/> <cpassword source={scPass}/>
<button value="Login" onclick={fn _ =>
vu <- get scUser;
vp <- get scPass;
rpc (serverLogin {User = vu, Pass = vp});
c <- getCookie auth;
case c of
None => set loggedIn None
| Some _ => set loggedIn (Some vu)}/>
</xml>)
(Ui.const <xml>Logged in as
<dyn signal={s <- signal loggedIn; return <xml>{[some s]}</xml>}/>
</xml>)
)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 181 bytes
Desc: OpenPGP Digital Signature
URL: <http://www.impredicative.com/pipermail/ur/attachments/20170419/847136b1/attachment.sig>
More information about the Ur
mailing list