Compare commits
2 Commits
7cb8a589ad
...
499b1748ce
Author | SHA1 | Date |
---|---|---|
jeff | 499b1748ce | |
jeff | ea506ab54b |
|
@ -1 +0,0 @@
|
||||||
jeff@seraph.8565:1606079828
|
|
|
@ -1,4 +1,4 @@
|
||||||
#![feature(proc_macro_hygiene, decl_macro, never_type, unsized_locals)]
|
#![feature(proc_macro_hygiene, decl_macro, never_type)]
|
||||||
|
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate rocket;
|
extern crate rocket;
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
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, login_user, login_page]
|
routes![login, logout, logged_in_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 == "Sergio" && login.password == "password" {
|
if login.username == "test" && login.password == "test" {
|
||||||
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/password.",
|
"Invalid username orpassword.",
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -35,7 +35,7 @@ fn logout(mut cookies: Cookies) -> Flash<Redirect> {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[get("/login")]
|
#[get("/login")]
|
||||||
fn login_user(_user: User) -> Redirect {
|
fn logged_in_user(_user: User) -> Redirect {
|
||||||
Redirect::to(uri!(super::root::index))
|
Redirect::to(uri!(super::root::index))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,13 +4,18 @@ use crate::models::{
|
||||||
characters::{CharacterEntry, NewCharacter},
|
characters::{CharacterEntry, NewCharacter},
|
||||||
User,
|
User,
|
||||||
};
|
};
|
||||||
use diesel::prelude::*;
|
use rocket::response::Redirect;
|
||||||
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![view_character, edit_character]
|
routes![
|
||||||
|
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.
|
||||||
|
@ -37,6 +42,17 @@ 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,
|
||||||
|
|
|
@ -0,0 +1,6 @@
|
||||||
|
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 {
|
||||||
Redirect::to(uri!(super::auth::login_page))
|
super::common::redirect_to_login()
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<div>
|
<div>
|
||||||
<h1>Rocket Session: Please Login</h1>
|
<h1>Tenebrous: Login</h1>
|
||||||
|
|
||||||
<p>Please login to continue.</p>
|
<p>Please login to continue.</p>
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,7 @@
|
||||||
|
{% extends "base" %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
<div>
|
||||||
|
New character page.
|
||||||
|
</div>
|
||||||
|
{% endblock content %}
|
Loading…
Reference in New Issue