mirror of
https://git.ngram.ca/OpenJam/rc-servers
synced 2026-08-23 23:08:52 +00:00
Add real email-based authentication, fix RC account auth to try all 3 login options when it doesn't know #20
This commit is contained in:
@@ -15,13 +15,41 @@ impl Database {
|
||||
})
|
||||
}
|
||||
|
||||
pub async fn user_by_public_id(&self, public_id: String) -> Result<Option<crate::schema::user::Model>, sea_orm::DbErr> {
|
||||
pub async fn user_by_display_name(&self, public_id: String) -> Result<Option<crate::schema::user::Model>, sea_orm::DbErr> {
|
||||
crate::schema::user::Entity::find()
|
||||
.filter(crate::schema::user::Column::PublicId.eq(public_id))
|
||||
.filter(crate::schema::user::Column::DisplayName.eq(public_id))
|
||||
.one(&self.orm)
|
||||
.await
|
||||
}
|
||||
|
||||
pub async fn user_by_steam_id(&self, steam_id: u64) -> Result<Option<crate::schema::user::Model>, sea_orm::DbErr> {
|
||||
crate::schema::user::Entity::find()
|
||||
.filter(crate::schema::user::Column::SteamId.eq(Some(steam_id)))
|
||||
.one(&self.orm)
|
||||
.await
|
||||
}
|
||||
|
||||
pub async fn user_by_email(&self, email: String) -> Result<Option<crate::schema::user::Model>, sea_orm::DbErr> {
|
||||
crate::schema::user::Entity::find()
|
||||
.filter(crate::schema::user::Column::Email.eq(email))
|
||||
.one(&self.orm)
|
||||
.await
|
||||
}
|
||||
|
||||
pub async fn user_by_any_unique_id(&self, id: String) -> Result<Option<crate::schema::user::Model>, sea_orm::DbErr> {
|
||||
if let Ok(steam_id) = id.parse::<u64>() {
|
||||
if let Some(res) = self.user_by_steam_id(steam_id).await? {
|
||||
return Ok(Some(res));
|
||||
}
|
||||
}
|
||||
if id.contains('@') {
|
||||
if let Some(res) = self.user_by_email(id.clone()).await? {
|
||||
return Ok(Some(res));
|
||||
}
|
||||
}
|
||||
self.user_by_display_name(id.clone()).await
|
||||
}
|
||||
|
||||
pub async fn insert_user(&self, entity: crate::schema::user::ActiveModel) -> Result<crate::schema::user::Model, sea_orm::DbErr> {
|
||||
entity.insert(&self.orm).await
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user