packages feed

hesql-0.5: example/Account.hesql

module Account.DB where 

-- see README for the table definitions

verifyLogin login password =
  maybe select Accountid, Login, RealName, Email from Account
     where (Password is null or Password  = md5(password)) and Lower(Login) = Lower(login)
           and not Locked;


login accountid =
    update Account set LoggedIn = true, 
           LastRequest = Now(), 
           Validated = true where AccountID = accountid;

logout accountid =
   update Account 
     set LoggedIn = false, 
         LastLogout = Now()
      where AccountID = accountid;
 
createAccount login password email realname =
    insert into Account (Login, Password, Email, RealName, LastRequest) 
    values (login,md5(password),email,realname, now());


activeUsers = 
    select Login from Account  where LoggedIn and  now() - LastRequest < '00:05:00';

listAccounts =
   select AccountId, Login, Notes, LastRequest from Account   order by LastRequest desc;