forked from Ruderverein-Donau-Linz/rowt
restructure code
This commit is contained in:
parent
051d20e627
commit
82c4680684
@ -20,46 +20,6 @@ pub struct User {
|
|||||||
is_guest: bool,
|
is_guest: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct AdminUser {
|
|
||||||
user: User,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl TryFrom<User> for AdminUser {
|
|
||||||
type Error = LoginError;
|
|
||||||
|
|
||||||
fn try_from(user: User) -> Result<Self, Self::Error> {
|
|
||||||
if user.is_admin {
|
|
||||||
Ok(AdminUser { user })
|
|
||||||
} else {
|
|
||||||
Err(LoginError::NotAnAdmin)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub struct CoxUser {
|
|
||||||
user: User,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Deref for CoxUser {
|
|
||||||
type Target = User;
|
|
||||||
|
|
||||||
fn deref(&self) -> &Self::Target {
|
|
||||||
&self.user
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl TryFrom<User> for CoxUser {
|
|
||||||
type Error = LoginError;
|
|
||||||
|
|
||||||
fn try_from(user: User) -> Result<Self, Self::Error> {
|
|
||||||
if user.is_cox {
|
|
||||||
Ok(CoxUser { user })
|
|
||||||
} else {
|
|
||||||
Err(LoginError::NotACox)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum LoginError {
|
pub enum LoginError {
|
||||||
SqlxError(sqlx::Error),
|
SqlxError(sqlx::Error),
|
||||||
@ -202,8 +162,32 @@ impl<'r> FromRequest<'r> for User {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub struct CoxUser {
|
||||||
|
user: User,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Deref for CoxUser {
|
||||||
|
type Target = User;
|
||||||
|
|
||||||
|
fn deref(&self) -> &Self::Target {
|
||||||
|
&self.user
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl TryFrom<User> for CoxUser {
|
||||||
|
type Error = LoginError;
|
||||||
|
|
||||||
|
fn try_from(user: User) -> Result<Self, Self::Error> {
|
||||||
|
if user.is_cox {
|
||||||
|
Ok(CoxUser { user })
|
||||||
|
} else {
|
||||||
|
Err(LoginError::NotACox)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
impl<'r> FromRequest<'r> for AdminUser {
|
impl<'r> FromRequest<'r> for CoxUser {
|
||||||
type Error = LoginError;
|
type Error = LoginError;
|
||||||
|
|
||||||
async fn from_request(req: &'r Request<'_>) -> request::Outcome<Self, Self::Error> {
|
async fn from_request(req: &'r Request<'_>) -> request::Outcome<Self, Self::Error> {
|
||||||
@ -220,8 +204,24 @@ impl<'r> FromRequest<'r> for AdminUser {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub struct AdminUser {
|
||||||
|
user: User,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl TryFrom<User> for AdminUser {
|
||||||
|
type Error = LoginError;
|
||||||
|
|
||||||
|
fn try_from(user: User) -> Result<Self, Self::Error> {
|
||||||
|
if user.is_admin {
|
||||||
|
Ok(AdminUser { user })
|
||||||
|
} else {
|
||||||
|
Err(LoginError::NotAnAdmin)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
impl<'r> FromRequest<'r> for CoxUser {
|
impl<'r> FromRequest<'r> for AdminUser {
|
||||||
type Error = LoginError;
|
type Error = LoginError;
|
||||||
|
|
||||||
async fn from_request(req: &'r Request<'_>) -> request::Outcome<Self, Self::Error> {
|
async fn from_request(req: &'r Request<'_>) -> request::Outcome<Self, Self::Error> {
|
||||||
|
@ -65,8 +65,6 @@ async fn join(db: &State<SqlitePool>, trip_details_id: i64, user: User) -> Flash
|
|||||||
|
|
||||||
#[get("/remove/<trip_details_id>")]
|
#[get("/remove/<trip_details_id>")]
|
||||||
async fn remove(db: &State<SqlitePool>, trip_details_id: i64, user: User) -> Flash<Redirect> {
|
async fn remove(db: &State<SqlitePool>, trip_details_id: i64, user: User) -> Flash<Redirect> {
|
||||||
//TODO: Check if > 2 hrs to event
|
|
||||||
|
|
||||||
UserTrip::delete(db, user.id, trip_details_id).await;
|
UserTrip::delete(db, user.id, trip_details_id).await;
|
||||||
|
|
||||||
Flash::success(Redirect::to("/"), "Erfolgreich abgemeldet!")
|
Flash::success(Redirect::to("/"), "Erfolgreich abgemeldet!")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user