mirror of
https://github.com/Blair-SGA-Dev-Team/blazerapp.git
synced 2024-12-21 22:12:43 -05:00
save
This commit is contained in:
parent
e112f5a33c
commit
c52ff45a82
|
@ -61,7 +61,7 @@ impl<'a, 'r> FromRequest<'a, 'r> for Host {
|
|||
}
|
||||
|
||||
impl<'a, 'r> FromRequest<'a, 'r> for Token {
|
||||
type Error = ();
|
||||
type Error = Redirect;
|
||||
|
||||
fn from_request(request: &'a Request<'r>) -> request::Outcome<Self, Self::Error> {
|
||||
match request.cookies().get("token") {
|
||||
|
@ -75,10 +75,10 @@ impl<'a, 'r> FromRequest<'a, 'r> for Token {
|
|||
.unwrap();
|
||||
|
||||
if resp["error"] != Value::Null {
|
||||
return Outcome::Failure((Status::Forbidden, ()));
|
||||
return Outcome::Forward(());
|
||||
} else {
|
||||
let email = resp["email"].clone();
|
||||
let pg = request.guard::<State<Mutex<PgConnection>>>()?;
|
||||
let pg = request.guard::<State<Mutex<PgConnection>>>().unwrap();
|
||||
let diesel_op = get_auth(&*(pg.lock().unwrap()));
|
||||
let auths: Vec<String> = match diesel_op {
|
||||
Ok(n) => n.into_iter().map(|x| x.email).collect::<Vec<String>>(),
|
||||
|
@ -88,11 +88,11 @@ impl<'a, 'r> FromRequest<'a, 'r> for Token {
|
|||
if auths.into_iter().any(|x| x == email.as_str().unwrap_or("")) {
|
||||
return Outcome::Success(Token(String::from(email.as_str().unwrap_or(""))));
|
||||
} else {
|
||||
return Outcome::Failure((Status::Forbidden, ()));
|
||||
return Outcome::Forward(());
|
||||
}
|
||||
}
|
||||
}
|
||||
None => Outcome::Failure((Status::Unauthorized, ())),
|
||||
None => Outcome::Forward(())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,10 +1,11 @@
|
|||
use cms_macro::api_route;
|
||||
use rocket::{
|
||||
http::{RawStr, Status},
|
||||
request::FromParam,
|
||||
};
|
||||
use std::borrow::Cow;
|
||||
|
||||
use cms_macro::api_route;
|
||||
|
||||
pub struct Lang<'a>(Cow<'a, str>);
|
||||
|
||||
fn valid_lang(lang: &str) -> bool {
|
||||
|
@ -52,6 +53,7 @@ pub mod defs {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
api_route! {
|
||||
|
@ -63,3 +65,14 @@ api_route! {
|
|||
}
|
||||
}
|
||||
|
||||
/*
|
||||
api_route! {
|
||||
teachers {
|
||||
name: (Text, String, String),
|
||||
emails: (Array<Text>, Vec<String>, Vec<String>),
|
||||
}
|
||||
}
|
||||
*/
|
||||
//TODO: fix value parsing to read a TokenStream until the `,` to allow for containerized types in
|
||||
//the macro
|
||||
|
||||
|
|
|
@ -29,14 +29,30 @@ use std::{
|
|||
sync::Mutex,
|
||||
};
|
||||
use utils::{db_conn, exit_with_error};
|
||||
use rocket::response::Redirect;
|
||||
use auth::Token;
|
||||
|
||||
|
||||
|
||||
#[get("/")]
|
||||
fn index() -> Template {
|
||||
let context: HashMap<&str, &str> = [("oauth", "/oauth")].iter().cloned().collect();
|
||||
Template::render("index", &context)
|
||||
fn home(_token: Token) -> Template {
|
||||
let context: HashMap<&str, &str> = HashMap::new();
|
||||
Template::render("home", &context)
|
||||
}
|
||||
|
||||
#[get("/", rank=2)]
|
||||
fn home_not_logged_in() -> Redirect {
|
||||
Redirect::to(uri!(login))
|
||||
}
|
||||
|
||||
#[get("/login")]
|
||||
fn login() -> Template {
|
||||
let context: HashMap<&str, &str> = [("oauth", "/oauth")].iter().cloned().collect();
|
||||
Template::render("login", &context)
|
||||
}
|
||||
|
||||
|
||||
|
||||
#[get("/static/<path..>")]
|
||||
fn static_files(path: PathBuf) -> Option<rocket::response::NamedFile> {
|
||||
rocket::response::NamedFile::open(Path::new("cms/static/").join(path)).ok()
|
||||
|
@ -57,7 +73,7 @@ fn rocket(port: u16, address: String, env: Environment, pg: PgConnection, sa: Se
|
|||
.manage(sa)
|
||||
.mount(
|
||||
"/",
|
||||
routes![index, auth::callback, auth::oauth, static_files],
|
||||
routes![home, home_not_logged_in, login, auth::callback, auth::oauth, static_files],
|
||||
)
|
||||
.mount("/api", routes![data::events::api])
|
||||
.mount(
|
||||
|
|
9
cms/templates/home.html.hbs
Normal file
9
cms/templates/home.html.hbs
Normal file
|
@ -0,0 +1,9 @@
|
|||
{{! vim: set ft=html: }}
|
||||
|
||||
<html>
|
||||
<head>
|
||||
</head>
|
||||
<body>
|
||||
<a href="/ui/events">Events</a>
|
||||
</body>
|
||||
</html>
|
Loading…
Reference in New Issue
Block a user