Mercurial Hosting > freedit
comparison src/lib/User.luan @ 8:be36282b556a
add new_thread
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Wed, 29 Jun 2022 00:04:09 -0600 |
parents | fc3ee39d7764 |
children | de0cbf515ef5 |
comparison
equal
deleted
inserted
replaced
7:0472897e790d | 8:be36282b556a |
---|---|
62 | 62 |
63 set_metatable(user,metatable) | 63 set_metatable(user,metatable) |
64 return user | 64 return user |
65 end | 65 end |
66 | 66 |
67 function User.get_by_id(id) | |
68 local doc = Db.get_document("id:"..id) | |
69 return doc and User.from_doc(doc) | |
70 end | |
71 | |
67 function User.get_by_email(email) | 72 function User.get_by_email(email) |
68 local doc = Db.get_document("user_email:"..lucene_quote(email)) | 73 local doc = Db.get_document("user_email:"..lucene_quote(email)) |
69 return doc and from_doc(doc) | 74 return doc and from_doc(doc) |
70 end | 75 end |
71 | 76 |
83 end | 88 end |
84 local user = get_by_name(name) | 89 local user = get_by_name(name) |
85 if user == nil or user.password ~= password then | 90 if user == nil or user.password ~= password then |
86 return nil | 91 return nil |
87 end | 92 end |
93 return user | |
94 end | |
95 | |
96 function User.current_required() | |
97 local user = User.current() | |
98 user or Http.response.send_redirect "/login.html" | |
88 return user | 99 return user |
89 end | 100 end |
90 | 101 |
91 local password_chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" | 102 local password_chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" |
92 do | 103 do |