a mini social media app for small communities
1module entity 2 3import time 4 5pub struct User { 6pub mut: 7 id int @[primary; sql: serial] 8 username string @[unique] 9 nickname ?string 10 11 password string 12 password_salt string 13 14 muted bool 15 admin bool 16 17 theme string 18 19 bio string 20 pronouns string 21 22 created_at time.Time = time.now() 23} 24 25// get_name returns the user's nickname if it is not none, if so then their 26// username is returned. 27@[inline] 28pub fn (user User) get_name() string { 29 return user.nickname or { user.username } 30} 31 32// to_str_without_sensitive_data returns the stringified data for the user with 33// their password and salt censored. 34@[inline] 35pub fn (user User) to_str_without_sensitive_data() string { 36 return user.str() 37 .replace(user.password, '*'.repeat(16)) 38 .replace(user.password_salt, '*'.repeat(16)) 39}