diff 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
line wrap: on
line diff
--- a/src/lib/User.luan	Thu Nov 24 22:54:43 2022 -0700
+++ b/src/lib/User.luan	Sun Nov 27 23:46:27 2022 -0700
@@ -66,10 +66,26 @@
 		user.id = doc.id
 	end
 
+	function user.reload()
+		return User.get_by_id(user.id) or error(user.id)
+	end
+
+	function user.login()
+		Http.response.set_persistent_cookie("user",user.name)
+		Http.response.set_persistent_cookie("password",user.password)
+		Http.request.cookies.user = user.name or error()
+		Http.request.cookies.password = user.password or error()
+	end
+
 	set_metatable(user,metatable)
 	return user
 end
 
+function User.get_by_id(id)
+	local doc = Db.get_document("id:"..id)
+	return doc and from_doc(doc)
+end
+
 function User.get_by_email(email)
 	local doc = Db.get_document("user_email:"..lucene_quote(email))
 	return doc and from_doc(doc)