comparison src/lib/User.luan @ 40:7ea33179592a

email notification
author Franklin Schmidt <fschmidt@gmail.com>
date Thu, 27 Feb 2025 16:44:20 -0700
parents e2b7f6393dab
children 818697418dbe
comparison
equal deleted inserted replaced
39:471b13e6ce2c 40:7ea33179592a
31 doc.type == "user" or error "wrong type" 31 doc.type == "user" or error "wrong type"
32 return User.new { 32 return User.new {
33 id = doc.id 33 id = doc.id
34 email = doc.user_email 34 email = doc.user_email
35 password = doc.password 35 password = doc.password
36 was_notified = doc.was_notified=="true"
37 notify_email = doc.notify_email
38 multi_notify = doc.multi_notify=="true"
36 } 39 }
37 end 40 end
38 41
39 local function to_doc(user) 42 local function to_doc(user)
40 return { 43 return {
41 type = "user" 44 type = "user"
42 id = user.id 45 id = user.id
43 user_email = user.email 46 user_email = user.email
44 password = user.password 47 password = user.password
48 was_notified = user.was_notified and "true" or nil
49 notify_email = user.notify_email
50 multi_notify = user.multi_notify and "true" or nil
45 } 51 }
46 end 52 end
47 53
48 function User.new(user) 54 function User.new(user)
49 55
50 function user.save() 56 function user.save()
51 local doc = to_doc(user) 57 local doc = to_doc(user)
52 Db.save(doc) 58 Db.save(doc)
53 user.id = doc.id 59 user.id = doc.id
60 end
61
62 function user.reload()
63 return User.get_by_id(user.id) or error(user.id)
54 end 64 end
55 65
56 function user.delete() 66 function user.delete()
57 run_in_transaction( function() 67 run_in_transaction( function()
58 local id = user.id 68 local id = user.id
133 local user = get_by_email(email) 143 local user = get_by_email(email)
134 if user == nil then 144 if user == nil then
135 user = User.new{ 145 user = User.new{
136 email = email 146 email = email
137 password = new_password() 147 password = new_password()
148 notify_email = email
138 } 149 }
139 user.save() 150 user.save()
140 end 151 end
141 return user 152 return user
142 end ) 153 end )