Compare commits
No commits in common. "499b1748cecdda7770e6f8f8e3bf662033877351" and "7cb8a589ada75e1d095f88018e63bd83ba93ac34" have entirely different histories.
499b1748ce
...
7cb8a589ad
|
@ -0,0 +1 @@
|
||||||
|
jeff@seraph.8565:1606079828
|
|
@ -1,4 +1,4 @@
|
||||||
#![feature(proc_macro_hygiene, decl_macro, never_type)]
|
#![feature(proc_macro_hygiene, decl_macro, never_type, unsized_locals)]
|
||||||
|
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate rocket;
|
extern crate rocket;
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
pub mod auth;
|
pub mod auth;
|
||||||
pub mod characters;
|
pub mod characters;
|
||||||
pub mod common;
|
|
||||||
pub mod root;
|
pub mod root;
|
||||||
|
|
|
@ -6,7 +6,7 @@ use rocket_contrib::templates::Template;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
pub(crate) fn routes() -> Vec<rocket::Route> {
|
pub(crate) fn routes() -> Vec<rocket::Route> {
|
||||||
routes![login, logout, logged_in_user, login_page]
|
routes![login, logout, login_user, login_page]
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(FromForm)]
|
#[derive(FromForm)]
|
||||||
|
@ -17,13 +17,13 @@ struct Login {
|
||||||
|
|
||||||
#[post("/login", data = "<login>")]
|
#[post("/login", data = "<login>")]
|
||||||
fn login(mut cookies: Cookies, login: Form<Login>) -> Result<Redirect, Flash<Redirect>> {
|
fn login(mut cookies: Cookies, login: Form<Login>) -> Result<Redirect, Flash<Redirect>> {
|
||||||
if login.username == "test" && login.password == "test" {
|
if login.username == "Sergio" && login.password == "password" {
|
||||||
cookies.add_private(Cookie::new("user_id", 1.to_string()));
|
cookies.add_private(Cookie::new("user_id", 1.to_string()));
|
||||||
Ok(Redirect::to(uri!(super::root::index)))
|
Ok(Redirect::to(uri!(super::root::index)))
|
||||||
} else {
|
} else {
|
||||||
Err(Flash::error(
|
Err(Flash::error(
|
||||||
Redirect::to(uri!(login_page)),
|
Redirect::to(uri!(login_page)),
|
||||||
"Invalid username orpassword.",
|
"Invalid username/password.",
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -35,7 +35,7 @@ fn logout(mut cookies: Cookies) -> Flash<Redirect> {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[get("/login")]
|
#[get("/login")]
|
||||||
fn logged_in_user(_user: User) -> Redirect {
|
fn login_user(_user: User) -> Redirect {
|
||||||
Redirect::to(uri!(super::root::index))
|
Redirect::to(uri!(super::root::index))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,18 +4,13 @@ use crate::models::{
|
||||||
characters::{CharacterEntry, NewCharacter},
|
characters::{CharacterEntry, NewCharacter},
|
||||||
User,
|
User,
|
||||||
};
|
};
|
||||||
use rocket::response::Redirect;
|
use diesel::prelude::*;
|
||||||
use rocket_contrib::templates::Template;
|
use rocket_contrib::templates::Template;
|
||||||
use serde_derive::Serialize;
|
use serde_derive::Serialize;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
pub(crate) fn routes() -> Vec<rocket::Route> {
|
pub(crate) fn routes() -> Vec<rocket::Route> {
|
||||||
routes![
|
routes![view_character, edit_character]
|
||||||
view_character,
|
|
||||||
new_character,
|
|
||||||
new_character_not_logged_in,
|
|
||||||
edit_character
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO make private -- currently is referenced in homepage route.
|
//TODO make private -- currently is referenced in homepage route.
|
||||||
|
@ -42,17 +37,6 @@ fn view_character(
|
||||||
Ok(Template::render("view_character", context))
|
Ok(Template::render("view_character", context))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[get("/new")]
|
|
||||||
fn new_character(logged_in_user: User, conn: TenebrousDbConn) -> Result<Template, Error> {
|
|
||||||
let context = HashMap::<String, String>::new();
|
|
||||||
Ok(Template::render("new_character", context))
|
|
||||||
}
|
|
||||||
|
|
||||||
#[get("/new", rank = 2)]
|
|
||||||
fn new_character_not_logged_in() -> Redirect {
|
|
||||||
super::common::redirect_to_login()
|
|
||||||
}
|
|
||||||
|
|
||||||
#[get("/<owner>/<character_id>/edit")]
|
#[get("/<owner>/<character_id>/edit")]
|
||||||
fn edit_character(
|
fn edit_character(
|
||||||
character_id: i32,
|
character_id: i32,
|
||||||
|
|
|
@ -1,6 +0,0 @@
|
||||||
use rocket::response::Redirect;
|
|
||||||
|
|
||||||
/// Common redirect to the login page.
|
|
||||||
pub(super) fn redirect_to_login() -> Redirect {
|
|
||||||
Redirect::to(uri!(super::auth::login_page))
|
|
||||||
}
|
|
|
@ -37,5 +37,5 @@ fn user_index(user: User, conn: TenebrousDbConn) -> Template {
|
||||||
|
|
||||||
#[get("/", rank = 2)]
|
#[get("/", rank = 2)]
|
||||||
fn index() -> Redirect {
|
fn index() -> Redirect {
|
||||||
super::common::redirect_to_login()
|
Redirect::to(uri!(super::auth::login_page))
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<div>
|
<div>
|
||||||
<h1>Tenebrous: Login</h1>
|
<h1>Rocket Session: Please Login</h1>
|
||||||
|
|
||||||
<p>Please login to continue.</p>
|
<p>Please login to continue.</p>
|
||||||
|
|
||||||
|
|
|
@ -1,7 +0,0 @@
|
||||||
{% extends "base" %}
|
|
||||||
|
|
||||||
{% block content %}
|
|
||||||
<div>
|
|
||||||
New character page.
|
|
||||||
</div>
|
|
||||||
{% endblock content %}
|
|
Loading…
Reference in New Issue