Mercurial Hosting > freedit
comparison src/lib/User.luan @ 54:260abd8f8565
login and register
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Sun, 27 Nov 2022 23:46:27 -0700 |
parents | 298c71e0c854 |
children | c57b84f461ae |
comparison
equal
deleted
inserted
replaced
53:cac477dd1f82 | 54:260abd8f8565 |
---|---|
64 local doc = to_doc(user) | 64 local doc = to_doc(user) |
65 Db.save(doc) | 65 Db.save(doc) |
66 user.id = doc.id | 66 user.id = doc.id |
67 end | 67 end |
68 | 68 |
69 function user.reload() | |
70 return User.get_by_id(user.id) or error(user.id) | |
71 end | |
72 | |
73 function user.login() | |
74 Http.response.set_persistent_cookie("user",user.name) | |
75 Http.response.set_persistent_cookie("password",user.password) | |
76 Http.request.cookies.user = user.name or error() | |
77 Http.request.cookies.password = user.password or error() | |
78 end | |
79 | |
69 set_metatable(user,metatable) | 80 set_metatable(user,metatable) |
70 return user | 81 return user |
82 end | |
83 | |
84 function User.get_by_id(id) | |
85 local doc = Db.get_document("id:"..id) | |
86 return doc and from_doc(doc) | |
71 end | 87 end |
72 | 88 |
73 function User.get_by_email(email) | 89 function User.get_by_email(email) |
74 local doc = Db.get_document("user_email:"..lucene_quote(email)) | 90 local doc = Db.get_document("user_email:"..lucene_quote(email)) |
75 return doc and from_doc(doc) | 91 return doc and from_doc(doc) |