Advertisement
Guest User

Untitled

a guest
Oct 21st, 2012
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
OCaml 1.83 KB | None | 0 0
  1. cookie userSession : { Email : string, Password : string }
  2.  
  3. table user : {
  4. Id : int,
  5. Email : string,
  6. Password : string,
  7. FirstName : string,
  8. LastName : string
  9. }
  10. PRIMARY KEY Id
  11.  
  12. table addresstype : {
  13. Id : int,
  14. DisplayName : string,
  15. Value : string
  16. }
  17. PRIMARY KEY Id
  18.  
  19. table address : {
  20. Id : int,
  21. UserId : int,
  22. AddressTypeId : int,
  23. Address1 : string,
  24. Address2 : string,
  25. City : string,
  26. State : string,
  27. Zip : string,
  28. Country : string
  29. }
  30. PRIMARY KEY Id
  31. CONSTRAINT FK_User FOREIGN KEY (UserId) REFERENCES user(Id) ON DELETE CASCADE,
  32. CONSTRAINT FK_AddressType FOREIGN KEY (AddressTypeId) REFERENCES addresstype(Id) ON DELETE CASCADE
  33.  
  34. sequence userSeq
  35. sequence addressSeq
  36.  
  37. fun create (email, password, firstname, lastname)  =
  38. let
  39.     val cryptPass = Sha.hash password
  40. in
  41.     id <- nextval userSeq;
  42.     dml (INSERT INTO user (Id, Email,Password, FirstName, LastName)
  43.      VALUES ({[id]},{[email]},{[cryptPass]},{[firstname]},{[lastname]})
  44.     )
  45. end
  46.  
  47. fun checkPassword (r:{Email:string, Password: string}) =
  48. let
  49.    val cryptPass = {Email=r.Email, Password=Sha.hash r.Password}
  50. in
  51.    re' <- oneOrNoRows1(SELECT user.Id
  52.                         FROM user
  53.                        WHERE user.Email = {[cryptPass.Email]}
  54.                          AND user.Password = {[cryptPass.Password]});
  55.    case re' of
  56.       None => return False
  57.     | Some re => setCookie userSession { Value = cryptPass, Expires=None,Secure=False };
  58.       return True
  59. end    
  60.  
  61. fun addAddress (userid, addresstypeid, address1, address2, city, state, zip, country) =
  62.     id <- nextval addressSeq;
  63.     dml (INSERT INTO address (Id, UserId, AddressTypeId, Address1, Address2, City, State, Zip, Country)
  64.      VALUES ({[id]},{[userid]},{[addresstypeid]},{[address1]},{[address2]},{[city]}, {[state]}, {[zip]}, {[country]})
  65.     )
  66.  
  67. fun main () = return <xml>Test</xml>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement