Verified Commit 61e17d11 authored by Rien's avatar Rien

Rustc crash :(

parent a284f45b
......@@ -1314,6 +1314,7 @@ dependencies = [
"regex 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
"rocket 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)",
"rocket_contrib 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)",
"rocket_http_authentication 0.1.0",
"rocket_oauth2_server 0.1.0",
"serde 1.0.82 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_derive 1.0.82 (registry+https://github.com/rust-lang/crates.io-index)",
......
#[macro_export]
macro_rules! oauth2_server {
( $path:expr, $ClientProvider:ty, $UserProvider:ty ) => {{
use rocket::fairing::AdHoc;
......@@ -5,15 +6,15 @@ macro_rules! oauth2_server {
use rocket::request::Form;
use rocket::response::status::{BadRequest, Custom};
use rocket::response::Redirect;
use rocket::{Rocket, State};
use rocket::State;
use rocket_contrib::json::Json;
use rocket_contrib::templates::Template;
use models::*;
use oauth::*;
use $crate::models::*;
use $crate::oauth::*;
use rocket_http_authentication::BasicAuthentication;
use token_store::TokenStore;
use util::redirect_to_relative;
use $crate::token_store::TokenStore;
use $crate::util::redirect_to_relative;
#[get("/hello")]
fn hello() -> String {
......@@ -56,7 +57,7 @@ macro_rules! oauth2_server {
}
#[get("/authorize")]
pub fn authorize_parse_failed() -> BadRequest<&'static str> {
fn authorize_parse_failed() -> BadRequest<&'static str> {
let msg = r#"
The authorization request could not be processed,
there are probably some parameters missing.
......@@ -186,7 +187,7 @@ macro_rules! oauth2_server {
}
}
pub fn get_authorization(
fn get_authorization(
cp: $ClientProvider,
basic_auth: Option<BasicAuthentication>,
client_id: Option<String>,
......@@ -216,6 +217,7 @@ macro_rules! oauth2_server {
authorize,
authorize_parse_failed,
login_get,
login_parse_failed,
login_post,
grant_get,
grant_post,
......@@ -233,7 +235,6 @@ mod test {
extern crate urlencoding;
use self::serde_json::Value;
use super::*;
use models::User;
use oauth::{ClientProvider, UserProvider};
use regex::Regex;
......@@ -250,22 +251,22 @@ mod test {
struct ClientProviderImpl {}
impl ClientProvider for ClientProviderImpl {
fn client_exists(&self, client_id: &str) -> bool {
fn client_exists(&self, _client_id: &str) -> bool {
true
}
fn client_has_uri(&self, client_id: &str, redirect_uri: &str) -> bool {
fn client_has_uri(&self, _client_id: &str, _redirect_uri: &str) -> bool {
true
}
fn client_needs_grant(&self, client_id: &str) -> bool {
fn client_needs_grant(&self, _client_id: &str) -> bool {
true
}
fn authorize_client(
&self,
client_id: &str,
client_password: &str,
_client_id: &str,
_client_password: &str,
) -> bool
{
true
......@@ -276,7 +277,7 @@ mod test {
type Error = ();
fn from_request(
request: &'a Request<'r>,
_request: &'a Request<'r>,
) -> request::Outcome<Self, Self::Error> {
Outcome::Success(ClientProviderImpl {})
}
......@@ -285,7 +286,7 @@ mod test {
struct UserProviderImpl {}
impl UserProvider for UserProviderImpl {
fn authorize_user(&self, user_id: &str, user_password: &str) -> bool {
fn authorize_user(&self, _user_id: &str, _user_password: &str) -> bool {
true
}
......@@ -298,7 +299,7 @@ mod test {
type Error = ();
fn from_request(
request: &'a Request<'r>,
_request: &'a Request<'r>,
) -> request::Outcome<Self, Self::Error> {
Outcome::Success(UserProviderImpl {})
}
......
......@@ -14,11 +14,10 @@ extern crate diesel;
extern crate diesel_migrations;
extern crate lazy_static;
mod models;
mod token_store;
mod util;
pub mod fairing;
pub mod models;
pub mod oauth;
pub mod token_store;
pub mod util;
pub use self::fairing::*;
......@@ -8,7 +8,6 @@ use rocket_contrib::json::Json;
use rocket_contrib::templates::Template;
use models::*;
use rocket_http_authentication::BasicAuthentication;
use token_store::TokenStore;
pub const SESSION_VALIDITY_MINUTES: i64 = 60;
......
......@@ -13,6 +13,7 @@ rand = "0.5"
regex = "1.0"
rocket = "0.4.1"
rocket_oauth2_server = { version = "0.1", path = "../oauth/" }
rocket_http_authentication = { version = "0.1", path = "../http_authentication/" }
serde = "1.0"
serde_json = "1.0"
serde_derive = "1.0"
......
#![allow(proc_macro_derive_resolution_fallback)]
#![feature(decl_macro, proc_macro_hygiene)]
extern crate chrono;
......@@ -16,12 +17,15 @@ extern crate lazy_static;
extern crate diesel;
#[macro_use]
extern crate diesel_migrations;
#[macro_use]
extern crate rocket_oauth2_server;
extern crate rocket_http_authentication;
mod user;
mod schema;
use rocket::Rocket;
use rocket_oauth2_server::oauth::{self, ClientProvider, UserProvider};
use rocket_oauth2_server::oauth::{ClientProvider, UserProvider};
use user::User;
use self::regex::Regex;
......@@ -90,7 +94,7 @@ pub fn users(conn: DbConn) -> Json<Vec<User>> {
}
#[derive(Clone)]
struct UserProviderImpl {}
pub struct UserProviderImpl {}
impl UserProvider for UserProviderImpl {
fn authorize_user(&self, _user_id: &str, _user_password: &str) -> bool {
......@@ -98,12 +102,22 @@ impl UserProvider for UserProviderImpl {
}
fn user_access_token(&self, user_id: &str) -> String {
format!("This is an access token for {}", user_id)
String::from(format!("This is an access token for {}", user_id))
}
}
impl<'a, 'r> FromRequest<'a, 'r> for UserProviderImpl {
type Error = ();
fn from_request(
_request: &'a Request<'r>,
) -> request::Outcome<Self, Self::Error> {
Outcome::Success(UserProviderImpl {})
}
}
#[derive(Clone)]
struct ClientProviderImpl {}
pub struct ClientProviderImpl {}
impl ClientProvider for ClientProviderImpl {
fn client_exists(&self, _client_id: &str) -> bool {
......@@ -123,11 +137,22 @@ impl ClientProvider for ClientProviderImpl {
}
}
impl<'a, 'r> FromRequest<'a, 'r> for ClientProviderImpl {
type Error = ();
fn from_request(
_request: &'a Request<'r>,
) -> request::Outcome<Self, Self::Error> {
Outcome::Success(ClientProviderImpl {})
}
}
fn rocket() -> Rocket {
let rocket = rocket::ignite();
let cp = ClientProviderImpl {};
let up = UserProviderImpl {};
oauth::mount("/oauth/", rocket, cp, up)
trace_macros!(true);
let fairing = oauth2_server!("/oauth", ClientProviderImpl, UserProviderImpl);
trace_macros!(false);
rocket.attach(fairing)
.attach(DbConn::fairing())
.attach(AdHoc::on_attach("Database Migrations", |rocket| {
let conn = DbConn::get_one(&rocket).expect("database connection");
......
use diesel::{self, prelude::*};
mod schema {
table! {
user {
id -> Nullable<Integer>,
username -> Text,
password -> Text,
admin -> Bool,
}
}
}
use self::schema::user;
use self::schema::user::dsl::user as all_users;
use schema::users;
use schema::users::dsl::users as all_users;
#[table_name = "user"]
#[derive(Serialize, Queryable, Insertable, Debug, Clone)]
pub struct User {
pub id: Option<i32>,
......@@ -25,7 +13,7 @@ pub struct User {
impl User {
pub fn all(conn: &SqliteConnection) -> Vec<User> {
all_users.order(user::id.desc()).load::<User>(conn).unwrap()
all_users.order(users::id.desc()).load::<User>(conn).unwrap()
}
pub fn create(
......@@ -41,7 +29,7 @@ impl User {
password,
admin,
};
diesel::insert_into(user::table)
diesel::insert_into(users::table)
.values(&u)
.execute(conn)
.is_ok()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment