aboutsummaryrefslogtreecommitdiff
path: root/src/database.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/database.rs')
-rw-r--r--src/database.rs15
1 files changed, 14 insertions, 1 deletions
diff --git a/src/database.rs b/src/database.rs
index 7905552..89cc213 100644
--- a/src/database.rs
+++ b/src/database.rs
@@ -112,11 +112,16 @@ impl Database {
},
None => return Err("User not found"),
}
-
+
// Truncate whitespace on the ends of the message
let trunc_message = msg.message().trim().to_string();
msg.set_message(trunc_message);
+ // Check if message is empty
+ if msg.message().len() < 1 {
+ return Err("Message cannot be empty")
+ }
+
let query = "INSERT INTO messages (date, sender, message, id, reply_to, deleted) VALUES (:date, :sender, :message, :id, :reply_to, :deleted)";
let statement = self.db.prepare(query).unwrap().into_iter()
.bind::<&[(_, sqlite::Value)]>(&[
@@ -209,6 +214,14 @@ impl Database {
}
pub fn create_user(&mut self, name: String) -> Result<UID, &'static str> {
+ // Truncate whitespace on the ends of the username
+ let name = name.trim().to_string();
+
+ // No empty usernames
+ if name.len() < 1 {
+ return Err("Username cannot be empty")
+ }
+
let id: UID = self.get_user_count().into();
let query = "INSERT INTO users (id, username, deleted) VALUES (:id, :name, false)";