Making login case-insensitive. Fixes #4272 (#4273)

* Making login case-insensitive. Fixes #4272

* Removing redundant lowercase.
pull/4279/head
Dessalines 2023-12-15 05:34:17 -05:00 committed by GitHub
parent e4b97ad8a9
commit 246e38a45b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 33 additions and 13 deletions

View File

@ -13,12 +13,17 @@ use crate::{
federation_queue_state::FederationQueueState,
instance::{Instance, InstanceForm},
},
utils::{functions::lower, get_conn, naive_now, now, DbPool},
utils::{
functions::{coalesce, lower},
get_conn,
naive_now,
now,
DbPool,
},
};
use diesel::{
dsl::{count_star, insert_into},
result::Error,
sql_types::{Nullable, Timestamptz},
ExpressionMethods,
NullableExpressionMethods,
QueryDsl,
@ -157,5 +162,3 @@ impl Instance {
.await
}
}
sql_function! { fn coalesce(x: Nullable<Timestamptz>, y: Timestamptz) -> Timestamptz; }

View File

@ -1,4 +1,3 @@
use super::instance::coalesce;
use crate::{
newtypes::{CommunityId, DbUrl, PersonId, PostId},
schema::post::dsl::{
@ -30,6 +29,7 @@ use crate::{
},
traits::{Crud, Likeable, Saveable},
utils::{
functions::coalesce,
get_conn,
naive_now,
DbPool,

View File

@ -5,7 +5,14 @@ use diesel_async::RunQueryDsl;
use lemmy_db_schema::{
newtypes::{LocalUserId, PersonId},
schema::{local_user, person, person_aggregates},
utils::{functions::lower, DbConn, DbPool, ListFn, Queries, ReadFn},
utils::{
functions::{coalesce, lower},
DbConn,
DbPool,
ListFn,
Queries,
ReadFn,
},
};
use lemmy_utils::error::{LemmyError, LemmyErrorType};
use std::future::{ready, Ready};
@ -34,7 +41,9 @@ fn queries<'a>(
let mut query = local_user::table.into_boxed();
query = match search {
ReadBy::Id(local_user_id) => query.filter(local_user::id.eq(local_user_id)),
ReadBy::Email(from_email) => query.filter(local_user::email.eq(from_email)),
ReadBy::Email(from_email) => {
query.filter(lower(coalesce(local_user::email, "")).eq(from_email.to_lowercase()))
}
_ => query,
};
let mut query = query.inner_join(person::table);
@ -43,8 +52,8 @@ fn queries<'a>(
ReadBy::Name(name) => query.filter(lower(person::name).eq(name.to_lowercase())),
ReadBy::NameOrEmail(name_or_email) => query.filter(
lower(person::name)
.eq(lower(name_or_email))
.or(local_user::email.eq(name_or_email)),
.eq(lower(name_or_email.to_lowercase()))
.or(lower(coalesce(local_user::email, "")).eq(name_or_email.to_lowercase())),
),
_ => query,
};

View File

@ -4,7 +4,6 @@ use diesel::{
dsl::{exists, not, IntervalDsl},
pg::Pg,
result::Error,
sql_function,
sql_types,
BoolExpressionMethods,
BoxableExpression,
@ -38,14 +37,23 @@ use lemmy_db_schema::{
post_read,
post_saved,
},
utils::{fuzzy_search, get_conn, limit_and_offset, now, DbConn, DbPool, ListFn, Queries, ReadFn},
utils::{
functions::coalesce,
fuzzy_search,
get_conn,
limit_and_offset,
now,
DbConn,
DbPool,
ListFn,
Queries,
ReadFn,
},
ListingType,
SortType,
};
use tracing::debug;
sql_function!(fn coalesce(x: sql_types::Nullable<sql_types::BigInt>, y: sql_types::BigInt) -> sql_types::BigInt);
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
enum Ord {
Desc,