-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4476661
commit f647d4f
Showing
36 changed files
with
674 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
use diesel::{ | ||
deserialize::{self, FromSql, FromSqlRow}, | ||
expression::AsExpression, | ||
pg::{Pg, PgValue}, | ||
serialize::{self, IsNull, Output, ToSql}, | ||
}; | ||
use serde::{Deserialize, Serialize}; | ||
use std::io::Write; | ||
|
||
use crate::enums::errors::internal::{AuthError, InternalError}; | ||
|
||
#[derive(Debug, AsExpression, FromSqlRow, PartialEq, Eq, Clone, Copy, Serialize, Deserialize)] | ||
#[diesel(sql_type = crate::data::schema::sql_types::OAuthProvider)] | ||
pub enum OAuthProvider { | ||
Github, | ||
Google, | ||
Discord, | ||
} | ||
|
||
impl OAuthProvider { | ||
pub fn from_str(s: &str) -> Result<Self, InternalError> { | ||
match s { | ||
"Github" => Ok(OAuthProvider::Github), | ||
"Google" => Ok(OAuthProvider::Google), | ||
"Discord" => Ok(OAuthProvider::Discord), | ||
_ => Err(InternalError::AuthError(AuthError::UnknownOAuthProvider)), | ||
} | ||
} | ||
} | ||
|
||
impl ToSql<crate::data::schema::sql_types::OAuthProvider, Pg> for OAuthProvider { | ||
fn to_sql<'b>(&'b self, out: &mut Output<'b, '_, Pg>) -> serialize::Result { | ||
match *self { | ||
OAuthProvider::Github => out.write_all(b"Github")?, | ||
OAuthProvider::Google => out.write_all(b"Google")?, | ||
OAuthProvider::Discord => out.write_all(b"Discord")?, | ||
} | ||
Ok(IsNull::No) | ||
} | ||
} | ||
|
||
impl FromSql<crate::data::schema::sql_types::OAuthProvider, Pg> for OAuthProvider { | ||
fn from_sql(bytes: PgValue) -> deserialize::Result<Self> { | ||
match bytes.as_bytes() { | ||
b"Github" => Ok(OAuthProvider::Github), | ||
b"Google" => Ok(OAuthProvider::Google), | ||
b"Discord" => Ok(OAuthProvider::Discord), | ||
_ => Err("Unrecognized enum variant".into()), | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
use crate::data::schema; | ||
use chrono::NaiveDateTime; | ||
use diesel::{Queryable, Selectable}; | ||
use serde::{Deserialize, Serialize}; | ||
use uuid::Uuid; | ||
|
||
#[derive(Queryable, Selectable, Debug, Clone, Serialize, Deserialize)] | ||
#[diesel(table_name = schema::classic_auth)] | ||
#[diesel(check_for_backend(diesel::pg::Pg))] | ||
pub struct ClassicAuth { | ||
pub id: Uuid, | ||
pub user_id: Uuid, | ||
pub password_hash: String, | ||
pub created_at: NaiveDateTime, | ||
pub updated_at: NaiveDateTime, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
use crate::data::{enums::OAuthProvider, schema}; | ||
use chrono::NaiveDateTime; | ||
use diesel::{Queryable, Selectable}; | ||
use serde::{Deserialize, Serialize}; | ||
use uuid::Uuid; | ||
|
||
#[derive(Queryable, Selectable, Debug, Clone, Serialize, Deserialize)] | ||
#[diesel(table_name = schema::oauth)] | ||
#[diesel(check_for_backend(diesel::pg::Pg))] | ||
pub struct OAuth { | ||
pub id: Uuid, | ||
pub user_id: Uuid, | ||
pub provider: OAuthProvider, | ||
pub metadata: serde_json::Value, | ||
pub created_at: NaiveDateTime, | ||
pub updated_at: NaiveDateTime, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
use serde::{Deserialize, Serialize}; | ||
|
||
use crate::data::models::{ClassicAuth, OAuth, User}; | ||
|
||
#[derive(Debug, Serialize, Deserialize, Clone)] | ||
pub struct FullUser { | ||
pub user: User, | ||
pub oauth: Option<Vec<OAuth>>, | ||
pub classic_auth: Option<ClassicAuth>, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
use serde::{Deserialize, Serialize}; | ||
|
||
#[derive(Clone, Serialize, Deserialize)] | ||
pub struct OAuthUser { | ||
pub email: String, | ||
pub metadata: serde_json::Value, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,10 @@ | ||
use crate::{dto::device::internal::DeviceInfo, enums::oauth_providers::OAuthProvider}; | ||
use crate::dto::device::internal::DeviceInfo; | ||
use serde::{Deserialize, Serialize}; | ||
use utoipa::ToSchema; | ||
|
||
#[derive(Debug, Serialize, Deserialize, Clone)] | ||
#[derive(Debug, Serialize, Deserialize, Clone, ToSchema)] | ||
pub struct AuthorizeRequest { | ||
pub code: String, | ||
pub provider: OAuthProvider, | ||
pub provider: String, | ||
pub device: DeviceInfo, | ||
} |
Oops, something went wrong.