summaryrefslogtreecommitdiffstats
path: root/server/src/api/user.rs
diff options
context:
space:
mode:
Diffstat (limited to 'server/src/api/user.rs')
-rw-r--r--server/src/api/user.rs34
1 files changed, 17 insertions, 17 deletions
diff --git a/server/src/api/user.rs b/server/src/api/user.rs
index d6d5962e..5d5f1a6b 100644
--- a/server/src/api/user.rs
+++ b/server/src/api/user.rs
@@ -102,13 +102,13 @@ impl Perform<LoginResponse> for Oper<Login> {
// Fetch that username / email
let user: User_ = match User_::find_by_email_or_username(&conn, &data.username_or_email) {
Ok(user) => user,
- Err(_e) => return Err(APIError::err(&self.op, "Couldn't find that username or email"))?
+ Err(_e) => return Err(APIError::err(&self.op, "couldnt_find_that_username_or_email"))?
};
// Verify the password
let valid: bool = verify(&data.password, &user.password_encrypted).unwrap_or(false);
if !valid {
- return Err(APIError::err(&self.op, "Password incorrect"))?
+ return Err(APIError::err(&self.op, "password_incorrect"))?
}
// Return the jwt
@@ -129,16 +129,16 @@ impl Perform<LoginResponse> for Oper<Register> {
// Make sure passwords match
if &data.password != &data.password_verify {
- return Err(APIError::err(&self.op, "Passwords do not match."))?
+ return Err(APIError::err(&self.op, "passwords_dont_match"))?
}
if has_slurs(&data.username) {
- return Err(APIError::err(&self.op, "No slurs"))?
+ return Err(APIError::err(&self.op, "no_slurs"))?
}
// Make sure there are no admins
if data.admin && UserView::admins(&conn)?.len() > 0 {
- return Err(APIError::err(&self.op, "Sorry, there's already an admin."))?
+ return Err(APIError::err(&self.op, "admin_already_created"))?
}
// Register the new user
@@ -157,7 +157,7 @@ impl Perform<LoginResponse> for Oper<Register> {
let inserted_user = match User_::register(&conn, &user_form) {
Ok(user) => user,
Err(_e) => {
- return Err(APIError::err(&self.op, "User already exists."))?
+ return Err(APIError::err(&self.op, "user_already_exists"))?
}
};
@@ -188,7 +188,7 @@ impl Perform<LoginResponse> for Oper<Register> {
let _inserted_community_follower = match CommunityFollower::follow(&conn, &community_follower_form) {
Ok(user) => user,
Err(_e) => {
- return Err(APIError::err(&self.op, "Community follower already exists."))?
+ return Err(APIError::err(&self.op, "community_follower_already_exists"))?
}
};
@@ -202,7 +202,7 @@ impl Perform<LoginResponse> for Oper<Register> {
let _inserted_community_moderator = match CommunityModerator::join(&conn, &community_moderator_form) {
Ok(user) => user,
Err(_e) => {
- return Err(APIError::err(&self.op, "Community moderator already exists."))?
+ return Err(APIError::err(&self.op, "community_moderator_already_exists"))?
}
};
@@ -321,7 +321,7 @@ impl Perform<AddAdminResponse> for Oper<AddAdmin> {
let claims = match Claims::decode(&data.auth) {
Ok(claims) => claims.claims,
Err(_e) => {
- return Err(APIError::err(&self.op, "Not logged in."))?
+ return Err(APIError::err(&self.op, "not_logged_in"))?
}
};
@@ -329,7 +329,7 @@ impl Perform<AddAdminResponse> for Oper<AddAdmin> {
// Make sure user is an admin
if UserView::read(&conn, user_id)?.admin == false {
- return Err(APIError::err(&self.op, "Not an admin."))?
+ return Err(APIError::err(&self.op, "not_an_admin"))?
}
let read_user = User_::read(&conn, data.user_id)?;
@@ -348,7 +348,7 @@ impl Perform<AddAdminResponse> for Oper<AddAdmin> {
match User_::update(&conn, data.user_id, &user_form) {
Ok(user) => user,
Err(_e) => {
- return Err(APIError::err(&self.op, "Couldn't update user"))?
+ return Err(APIError::err(&self.op, "couldnt_update_user"))?
}
};
@@ -380,7 +380,7 @@ impl Perform<BanUserResponse> for Oper<BanUser> {
let claims = match Claims::decode(&data.auth) {
Ok(claims) => claims.claims,
Err(_e) => {
- return Err(APIError::err(&self.op, "Not logged in."))?
+ return Err(APIError::err(&self.op, "not_logged_in"))?
}
};
@@ -388,7 +388,7 @@ impl Perform<BanUserResponse> for Oper<BanUser> {
// Make sure user is an admin
if UserView::read(&conn, user_id)?.admin == false {
- return Err(APIError::err(&self.op, "Not an admin."))?
+ return Err(APIError::err(&self.op, "not_an_admin"))?
}
let read_user = User_::read(&conn, data.user_id)?;
@@ -407,7 +407,7 @@ impl Perform<BanUserResponse> for Oper<BanUser> {
match User_::update(&conn, data.user_id, &user_form) {
Ok(user) => user,
Err(_e) => {
- return Err(APIError::err(&self.op, "Couldn't update user"))?
+ return Err(APIError::err(&self.op, "couldnt_update_user"))?
}
};
@@ -448,7 +448,7 @@ impl Perform<GetRepliesResponse> for Oper<GetReplies> {
let claims = match Claims::decode(&data.auth) {
Ok(claims) => claims.claims,
Err(_e) => {
- return Err(APIError::err(&self.op, "Not logged in."))?
+ return Err(APIError::err(&self.op, "not_logged_in"))?
}
};
@@ -476,7 +476,7 @@ impl Perform<GetRepliesResponse> for Oper<MarkAllAsRead> {
let claims = match Claims::decode(&data.auth) {
Ok(claims) => claims.claims,
Err(_e) => {
- return Err(APIError::err(&self.op, "Not logged in."))?
+ return Err(APIError::err(&self.op, "not_logged_in"))?
}
};
@@ -499,7 +499,7 @@ impl Perform<GetRepliesResponse> for Oper<MarkAllAsRead> {
let _updated_comment = match Comment::update(&conn, reply.id, &comment_form) {
Ok(comment) => comment,
Err(_e) => {
- return Err(APIError::err(&self.op, "Couldn't update Comment"))?
+ return Err(APIError::err(&self.op, "couldnt_update_comment"))?
}
};
}