Dear All,

I'm getting this error. I don't see why this happens. Please enlighten
me.

Thanks and best regards,

Marko
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>)
        )

Attachment: pgpOSLAse5k4C.pgp
Description: OpenPGP Digital Signature

_______________________________________________
Ur mailing list
[email protected]
http://www.impredicative.com/cgi-bin/mailman/listinfo/ur

Reply via email to