mirror of
https://github.com/LemmyNet/lemmy.git
synced 2024-11-12 18:56:12 +00:00
* Making login case-insensitive. Fixes #4272 * Removing redundant lowercase.
This commit is contained in:
parent
e4b97ad8a9
commit
246e38a45b
|
@ -13,12 +13,17 @@ use crate::{
|
||||||
federation_queue_state::FederationQueueState,
|
federation_queue_state::FederationQueueState,
|
||||||
instance::{Instance, InstanceForm},
|
instance::{Instance, InstanceForm},
|
||||||
},
|
},
|
||||||
utils::{functions::lower, get_conn, naive_now, now, DbPool},
|
utils::{
|
||||||
|
functions::{coalesce, lower},
|
||||||
|
get_conn,
|
||||||
|
naive_now,
|
||||||
|
now,
|
||||||
|
DbPool,
|
||||||
|
},
|
||||||
};
|
};
|
||||||
use diesel::{
|
use diesel::{
|
||||||
dsl::{count_star, insert_into},
|
dsl::{count_star, insert_into},
|
||||||
result::Error,
|
result::Error,
|
||||||
sql_types::{Nullable, Timestamptz},
|
|
||||||
ExpressionMethods,
|
ExpressionMethods,
|
||||||
NullableExpressionMethods,
|
NullableExpressionMethods,
|
||||||
QueryDsl,
|
QueryDsl,
|
||||||
|
@ -157,5 +162,3 @@ impl Instance {
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sql_function! { fn coalesce(x: Nullable<Timestamptz>, y: Timestamptz) -> Timestamptz; }
|
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
use super::instance::coalesce;
|
|
||||||
use crate::{
|
use crate::{
|
||||||
newtypes::{CommunityId, DbUrl, PersonId, PostId},
|
newtypes::{CommunityId, DbUrl, PersonId, PostId},
|
||||||
schema::post::dsl::{
|
schema::post::dsl::{
|
||||||
|
@ -30,6 +29,7 @@ use crate::{
|
||||||
},
|
},
|
||||||
traits::{Crud, Likeable, Saveable},
|
traits::{Crud, Likeable, Saveable},
|
||||||
utils::{
|
utils::{
|
||||||
|
functions::coalesce,
|
||||||
get_conn,
|
get_conn,
|
||||||
naive_now,
|
naive_now,
|
||||||
DbPool,
|
DbPool,
|
||||||
|
|
|
@ -5,7 +5,14 @@ use diesel_async::RunQueryDsl;
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
newtypes::{LocalUserId, PersonId},
|
newtypes::{LocalUserId, PersonId},
|
||||||
schema::{local_user, person, person_aggregates},
|
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 lemmy_utils::error::{LemmyError, LemmyErrorType};
|
||||||
use std::future::{ready, Ready};
|
use std::future::{ready, Ready};
|
||||||
|
@ -34,7 +41,9 @@ fn queries<'a>(
|
||||||
let mut query = local_user::table.into_boxed();
|
let mut query = local_user::table.into_boxed();
|
||||||
query = match search {
|
query = match search {
|
||||||
ReadBy::Id(local_user_id) => query.filter(local_user::id.eq(local_user_id)),
|
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,
|
_ => query,
|
||||||
};
|
};
|
||||||
let mut query = query.inner_join(person::table);
|
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::Name(name) => query.filter(lower(person::name).eq(name.to_lowercase())),
|
||||||
ReadBy::NameOrEmail(name_or_email) => query.filter(
|
ReadBy::NameOrEmail(name_or_email) => query.filter(
|
||||||
lower(person::name)
|
lower(person::name)
|
||||||
.eq(lower(name_or_email))
|
.eq(lower(name_or_email.to_lowercase()))
|
||||||
.or(local_user::email.eq(name_or_email)),
|
.or(lower(coalesce(local_user::email, "")).eq(name_or_email.to_lowercase())),
|
||||||
),
|
),
|
||||||
_ => query,
|
_ => query,
|
||||||
};
|
};
|
||||||
|
|
|
@ -4,7 +4,6 @@ use diesel::{
|
||||||
dsl::{exists, not, IntervalDsl},
|
dsl::{exists, not, IntervalDsl},
|
||||||
pg::Pg,
|
pg::Pg,
|
||||||
result::Error,
|
result::Error,
|
||||||
sql_function,
|
|
||||||
sql_types,
|
sql_types,
|
||||||
BoolExpressionMethods,
|
BoolExpressionMethods,
|
||||||
BoxableExpression,
|
BoxableExpression,
|
||||||
|
@ -38,14 +37,23 @@ use lemmy_db_schema::{
|
||||||
post_read,
|
post_read,
|
||||||
post_saved,
|
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,
|
ListingType,
|
||||||
SortType,
|
SortType,
|
||||||
};
|
};
|
||||||
use tracing::debug;
|
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)]
|
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||||
enum Ord {
|
enum Ord {
|
||||||
Desc,
|
Desc,
|
||||||
|
|
Loading…
Reference in a new issue