Sign up form and other stuff
This commit is contained in:
parent
b1ffd1a04a
commit
45d4867cb3
18 changed files with 817 additions and 107 deletions
32
backend/src/config.rs
Normal file
32
backend/src/config.rs
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
use std::{fmt, fs::File};
|
||||
|
||||
use ron::de::from_reader;
|
||||
use serde::Deserialize;
|
||||
|
||||
use crate::consts;
|
||||
|
||||
#[derive(Deserialize, Clone)]
|
||||
pub struct Config {
|
||||
pub port: u16,
|
||||
pub smtp_login: String,
|
||||
pub smtp_password: String,
|
||||
}
|
||||
|
||||
// Avoid to print passwords.
|
||||
impl fmt::Debug for Config {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
f.debug_struct("Config")
|
||||
.field("port", &self.port)
|
||||
.field("smtp_login", &self.smtp_login)
|
||||
.field("smtp_password", &"*****")
|
||||
.finish()
|
||||
}
|
||||
}
|
||||
|
||||
pub fn load() -> Config {
|
||||
let f = File::open(consts::FILE_CONF).unwrap_or_else(|_| panic!("Failed to open configuration file {}", consts::FILE_CONF));
|
||||
match from_reader(f) {
|
||||
Ok(c) => c,
|
||||
Err(e) => panic!("Failed to load config: {}", e)
|
||||
}
|
||||
}
|
||||
|
|
@ -1,4 +1,6 @@
|
|||
|
||||
pub const FILE_CONF: &str = "conf.ron";
|
||||
pub const DB_DIRECTORY: &str = "data";
|
||||
pub const DB_FILENAME: &str = "data/recipes.sqlite";
|
||||
pub const SQL_FILENAME: &str = "sql/version_{VERSION}.sql";
|
||||
pub const DB_FILENAME: &str = "recipes.sqlite";
|
||||
pub const SQL_FILENAME: &str = "sql/version_{VERSION}.sql";
|
||||
pub const VALIDATION_TOKEN_DURATION: i64 = 1 * 60 * 60; // 1 hour. [s].
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
use std::{fmt::Display, fs::{self, File}, path::Path, io::Read};
|
||||
use std::{fmt, fs::{self, File}, path::Path, io::Read};
|
||||
|
||||
use itertools::Itertools;
|
||||
use chrono::{prelude::*, Duration};
|
||||
|
|
@ -22,6 +22,14 @@ pub enum DBError {
|
|||
Other(String),
|
||||
}
|
||||
|
||||
impl fmt::Display for DBError {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> std::result::Result<(), fmt::Error> {
|
||||
write!(f, "{:?}", self)
|
||||
}
|
||||
}
|
||||
|
||||
impl std::error::Error for DBError { }
|
||||
|
||||
impl From<rusqlite::Error> for DBError {
|
||||
fn from(error: rusqlite::Error) -> Self {
|
||||
DBError::SqliteError(error)
|
||||
|
|
@ -95,7 +103,7 @@ impl Connection {
|
|||
Self::create_connection(SqliteConnectionManager::file(file))
|
||||
}
|
||||
|
||||
fn create_connection(manager: SqliteConnectionManager) -> Result<Connection> {;
|
||||
fn create_connection(manager: SqliteConnectionManager) -> Result<Connection> {
|
||||
let pool = r2d2::Pool::new(manager).unwrap();
|
||||
let connection = Connection { pool };
|
||||
connection.create_or_update()?;
|
||||
|
|
@ -206,11 +214,11 @@ impl Connection {
|
|||
}
|
||||
|
||||
///
|
||||
pub fn sign_up(&self, password: &str, email: &str) -> Result<SignUpResult> {
|
||||
self.sign_up_with_given_time(password, email, Utc::now())
|
||||
pub fn sign_up(&self, email: &str, password: &str) -> Result<SignUpResult> {
|
||||
self.sign_up_with_given_time(email, password, Utc::now())
|
||||
}
|
||||
|
||||
fn sign_up_with_given_time(&self, password: &str, email: &str, datetime: DateTime<Utc>) -> Result<SignUpResult> {
|
||||
fn sign_up_with_given_time(&self, email: &str, password: &str, datetime: DateTime<Utc>) -> Result<SignUpResult> {
|
||||
let mut con = self.pool.get()?;
|
||||
let tx = con.transaction()?;
|
||||
let token =
|
||||
|
|
@ -313,7 +321,7 @@ impl Connection {
|
|||
}
|
||||
|
||||
/// Execute a given SQL file.
|
||||
pub fn execute_file<P: AsRef<Path> + Display>(&self, file: P) -> Result<()> {
|
||||
pub fn execute_file<P: AsRef<Path> + fmt::Display>(&self, file: P) -> Result<()> {
|
||||
let con = self.pool.get()?;
|
||||
let sql = load_sql_file(file)?;
|
||||
con.execute_batch(&sql).map_err(DBError::from)
|
||||
|
|
@ -334,7 +342,7 @@ impl Connection {
|
|||
}
|
||||
}
|
||||
|
||||
fn load_sql_file<P: AsRef<Path> + Display>(sql_file: P) -> Result<String> {
|
||||
fn load_sql_file<P: AsRef<Path> + fmt::Display>(sql_file: P) -> Result<String> {
|
||||
let mut file = File::open(&sql_file).map_err(|err| DBError::Other(format!("Cannot open SQL file ({}): {}", &sql_file, err.to_string())))?;
|
||||
let mut sql = String::new();
|
||||
file.read_to_string(&mut sql).map_err(|err| DBError::Other(format!("Cannot read SQL file ({}) : {}", &sql_file, err.to_string())))?;
|
||||
|
|
@ -352,7 +360,7 @@ mod tests {
|
|||
#[test]
|
||||
fn sign_up() -> Result<()> {
|
||||
let connection = Connection::new_in_memory()?;
|
||||
match connection.sign_up("12345", "paul@test.org")? {
|
||||
match connection.sign_up("paul@test.org", "12345")? {
|
||||
SignUpResult::UserCreatedWaitingForValidation(_) => (), // Nominal case.
|
||||
other => panic!("{:?}", other),
|
||||
}
|
||||
|
|
@ -372,7 +380,7 @@ mod tests {
|
|||
0,
|
||||
NULL
|
||||
);", [])?;
|
||||
match connection.sign_up("12345", "paul@test.org")? {
|
||||
match connection.sign_up("paul@test.org", "12345")? {
|
||||
SignUpResult::UserAlreadyExists => (), // Nominal case.
|
||||
other => panic!("{:?}", other),
|
||||
}
|
||||
|
|
@ -393,7 +401,7 @@ mod tests {
|
|||
0,
|
||||
:token
|
||||
);", named_params! { ":token": token })?;
|
||||
match connection.sign_up("12345", "paul@test.org")? {
|
||||
match connection.sign_up("paul@test.org", "12345")? {
|
||||
SignUpResult::UserCreatedWaitingForValidation(_) => (), // Nominal case.
|
||||
other => panic!("{:?}", other),
|
||||
}
|
||||
|
|
@ -404,7 +412,7 @@ mod tests {
|
|||
fn sign_up_then_send_validation_at_time() -> Result<()> {
|
||||
let connection = Connection::new_in_memory()?;
|
||||
let validation_token =
|
||||
match connection.sign_up("12345", "paul@test.org")? {
|
||||
match connection.sign_up("paul@test.org", "12345")? {
|
||||
SignUpResult::UserCreatedWaitingForValidation(token) => token, // Nominal case.
|
||||
other => panic!("{:?}", other),
|
||||
};
|
||||
|
|
@ -419,7 +427,7 @@ mod tests {
|
|||
fn sign_up_then_send_validation_too_late() -> Result<()> {
|
||||
let connection = Connection::new_in_memory()?;
|
||||
let validation_token =
|
||||
match connection.sign_up_with_given_time("12345", "paul@test.org", Utc::now() - Duration::days(1))? {
|
||||
match connection.sign_up_with_given_time("paul@test.org", "12345", Utc::now() - Duration::days(1))? {
|
||||
SignUpResult::UserCreatedWaitingForValidation(token) => token, // Nominal case.
|
||||
other => panic!("{:?}", other),
|
||||
};
|
||||
|
|
@ -434,7 +442,7 @@ mod tests {
|
|||
fn sign_up_then_send_validation_with_bad_token() -> Result<()> {
|
||||
let connection = Connection::new_in_memory()?;
|
||||
let _validation_token =
|
||||
match connection.sign_up("12345", "paul@test.org")? {
|
||||
match connection.sign_up("paul@test.org", "12345")? {
|
||||
SignUpResult::UserCreatedWaitingForValidation(token) => token, // Nominal case.
|
||||
other => panic!("{:?}", other),
|
||||
};
|
||||
|
|
@ -450,12 +458,12 @@ mod tests {
|
|||
fn sign_up_then_send_validation_then_sign_in() -> Result<()> {
|
||||
let connection = Connection::new_in_memory()?;
|
||||
|
||||
let password = "12345";
|
||||
let email = "paul@test.org";
|
||||
let password = "12345";
|
||||
|
||||
// Sign up.
|
||||
let validation_token =
|
||||
match connection.sign_up(password, email)? {
|
||||
match connection.sign_up(email, password)? {
|
||||
SignUpResult::UserCreatedWaitingForValidation(token) => token, // Nominal case.
|
||||
other => panic!("{:?}", other),
|
||||
};
|
||||
|
|
@ -479,12 +487,12 @@ mod tests {
|
|||
fn sign_up_then_send_validation_then_authentication() -> Result<()> {
|
||||
let connection = Connection::new_in_memory()?;
|
||||
|
||||
let password = "12345";
|
||||
let email = "paul@test.org";
|
||||
let password = "12345";
|
||||
|
||||
// Sign up.
|
||||
let validation_token =
|
||||
match connection.sign_up(password, email)? {
|
||||
match connection.sign_up(email, password)? {
|
||||
SignUpResult::UserCreatedWaitingForValidation(token) => token, // Nominal case.
|
||||
other => panic!("{:?}", other),
|
||||
};
|
||||
|
|
@ -519,12 +527,12 @@ mod tests {
|
|||
fn sign_up_then_send_validation_then_sign_out_then_sign_in() -> Result<()> {
|
||||
let connection = Connection::new_in_memory()?;
|
||||
|
||||
let password = "12345";
|
||||
let email = "paul@test.org";
|
||||
let password = "12345";
|
||||
|
||||
// Sign up.
|
||||
let validation_token =
|
||||
match connection.sign_up(password, email)? {
|
||||
match connection.sign_up(email, password)? {
|
||||
SignUpResult::UserCreatedWaitingForValidation(token) => token, // Nominal case.
|
||||
other => panic!("{:?}", other),
|
||||
};
|
||||
|
|
|
|||
22
backend/src/email.rs
Normal file
22
backend/src/email.rs
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
use lettre::{transport::smtp::{authentication::Credentials}, Message, SmtpTransport, Transport};
|
||||
|
||||
///
|
||||
pub fn send_validation(site_url: &str, email: &str, token: &str, smtp_login: &str, smtp_password: &str) -> Result<(), Box<dyn std::error::Error>> {
|
||||
|
||||
let email = Message::builder()
|
||||
.message_id(None)
|
||||
.from("recipes@gburri.org".parse()?)
|
||||
.to(email.parse()?)
|
||||
.subject("Recipes.gburri.org account validation")
|
||||
.body(format!("Follow this link to confirm your inscription: {}/validation?token={}", site_url, token))?;
|
||||
|
||||
let credentials = Credentials::new(smtp_login.to_string(), smtp_password.to_string());
|
||||
|
||||
let mailer = SmtpTransport::relay("mail.gandi.net")?.credentials(credentials).build();
|
||||
|
||||
if let Err(error) = mailer.send(&email) {
|
||||
println!("Error when sending E-mail:\n{:?}", &error);
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
|
@ -1,19 +1,21 @@
|
|||
use std::fs::File;
|
||||
use std::sync::Mutex;
|
||||
use std::{collections::HashMap, net::ToSocketAddrs};
|
||||
|
||||
use actix_files as fs;
|
||||
use actix_web::{get, web, Responder, middleware, App, HttpServer, HttpRequest};
|
||||
use askama_actix::Template;
|
||||
use chrono::prelude::*;
|
||||
use actix_web::{http::header, get, post, web, Responder, middleware, App, HttpServer, HttpRequest, HttpResponse};
|
||||
use askama_actix::{Template, TemplateToResponse};
|
||||
use chrono::{prelude::*, Duration};
|
||||
use clap::Parser;
|
||||
use ron::de::from_reader;
|
||||
use serde::Deserialize;
|
||||
|
||||
use config::Config;
|
||||
|
||||
mod consts;
|
||||
mod db;
|
||||
mod hash;
|
||||
mod model;
|
||||
mod user;
|
||||
mod email;
|
||||
mod config;
|
||||
|
||||
#[derive(Template)]
|
||||
#[template(path = "home.html")]
|
||||
|
|
@ -21,6 +23,11 @@ struct HomeTemplate {
|
|||
recipes: Vec<(i32, String)>,
|
||||
}
|
||||
|
||||
#[derive(Template)]
|
||||
#[template(path = "sign_in_form.html")]
|
||||
struct SignInFormTemplate {
|
||||
}
|
||||
|
||||
#[derive(Template)]
|
||||
#[template(path = "view_recipe.html")]
|
||||
struct ViewRecipeTemplate {
|
||||
|
|
@ -28,27 +35,219 @@ struct ViewRecipeTemplate {
|
|||
current_recipe: model::Recipe,
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
pub struct Request {
|
||||
m: Option<String>
|
||||
#[derive(Template)]
|
||||
#[template(path = "message.html")]
|
||||
struct MessageTemplate {
|
||||
recipes: Vec<(i32, String)>,
|
||||
message: String,
|
||||
}
|
||||
|
||||
#[get("/")]
|
||||
async fn home_page(req: HttpRequest, connection: web::Data<db::Connection>) -> impl Responder {
|
||||
HomeTemplate { recipes: connection.get_all_recipe_titles().unwrap() } // TODO: unwrap.
|
||||
HomeTemplate { recipes: connection.get_all_recipe_titles().unwrap_or_default() }
|
||||
}
|
||||
|
||||
//// SIGN UP /////
|
||||
|
||||
#[derive(Template)]
|
||||
#[template(path = "sign_up_form.html")]
|
||||
struct SignUpFormTemplate {
|
||||
email: String,
|
||||
message: String,
|
||||
message_email: String,
|
||||
message_password: String,
|
||||
}
|
||||
|
||||
impl SignUpFormTemplate {
|
||||
fn new() -> Self {
|
||||
SignUpFormTemplate { email: String::new(), message: String::new(), message_email: String::new(), message_password: String::new() }
|
||||
}
|
||||
}
|
||||
|
||||
enum SignUpError {
|
||||
InvalidEmail,
|
||||
PasswordsNotEqual,
|
||||
InvalidPassword,
|
||||
UserAlreadyExists,
|
||||
DatabaseError,
|
||||
UnableSendEmail,
|
||||
}
|
||||
|
||||
#[get("/signup")]
|
||||
async fn sign_up_get(req: HttpRequest, query: web::Query<HashMap<String, String>>, connection: web::Data<db::Connection>) -> impl Responder {
|
||||
SignUpFormTemplate::new()
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
struct SignUpFormData {
|
||||
email: String,
|
||||
password_1: String,
|
||||
password_2: String,
|
||||
}
|
||||
|
||||
#[post("/signup")]
|
||||
async fn sign_up_post(req: HttpRequest, form: web::Form<SignUpFormData>, connection: web::Data<db::Connection>, config: web::Data<Config>) -> impl Responder {
|
||||
println!("Sign Up, email: {}, passwords: {}/{}", form.email, form.password_1, form.password_2);
|
||||
|
||||
fn error_response(error: SignUpError, form: &web::Form<SignUpFormData>) -> HttpResponse {
|
||||
SignUpFormTemplate {
|
||||
email: form.email.clone(),
|
||||
message_email:
|
||||
match error {
|
||||
SignUpError::InvalidEmail => "Invalid email",
|
||||
_ => "",
|
||||
}.to_string(),
|
||||
message_password:
|
||||
match error {
|
||||
SignUpError::PasswordsNotEqual => "Passwords don't match",
|
||||
SignUpError::InvalidPassword => "Password must have at least eight characters",
|
||||
_ => "",
|
||||
}.to_string(),
|
||||
message:
|
||||
match error {
|
||||
SignUpError::UserAlreadyExists => "This email is already taken",
|
||||
SignUpError::DatabaseError => "Database error",
|
||||
SignUpError::UnableSendEmail => "Unable to send the validation email",
|
||||
_ => "",
|
||||
}.to_string(),
|
||||
}.to_response()
|
||||
}
|
||||
|
||||
// Validation of email and password.
|
||||
if let common::utils::EmailValidation::NotValid = common::utils::validate_email(&form.email) {
|
||||
return error_response(SignUpError::InvalidEmail, &form);
|
||||
}
|
||||
|
||||
if form.password_1 != form.password_2 {
|
||||
return error_response(SignUpError::PasswordsNotEqual, &form);
|
||||
}
|
||||
|
||||
if let common::utils::PasswordValidation::TooShort = common::utils::validate_password(&form.password_1) {
|
||||
return error_response(SignUpError::InvalidPassword, &form);
|
||||
}
|
||||
|
||||
match connection.sign_up(&form.email, &form.password_1) {
|
||||
Ok(db::SignUpResult::UserAlreadyExists) => {
|
||||
error_response(SignUpError::UserAlreadyExists, &form)
|
||||
},
|
||||
Ok(db::SignUpResult::UserCreatedWaitingForValidation(token)) => {
|
||||
let url = {
|
||||
let host = req.headers().get(header::HOST).map(|v| v.to_str().unwrap_or_default()).unwrap_or_default();
|
||||
let port: Option<i32> = 'p: {
|
||||
let split_port: Vec<&str> = host.split(':').collect();
|
||||
if split_port.len() == 2 {
|
||||
if let Ok(p) = split_port[1].parse::<i32>() {
|
||||
break 'p Some(p)
|
||||
}
|
||||
}
|
||||
None
|
||||
};
|
||||
format!("http{}://{}", if port.is_some() && port.unwrap() != 443 { "" } else { "s" }, host)
|
||||
};
|
||||
match email::send_validation(&url, &form.email, &token, &config.smtp_login, &config.smtp_password) {
|
||||
Ok(()) =>
|
||||
HttpResponse::Found()
|
||||
.insert_header((header::LOCATION, "/signup_check_email"))
|
||||
.finish(),
|
||||
Err(error) => {
|
||||
eprintln!("Email validation error: {:?}", error);
|
||||
error_response(SignUpError::UnableSendEmail, &form)
|
||||
},
|
||||
}
|
||||
},
|
||||
Err(error) => {
|
||||
eprintln!("Signup database error: {:?}", error);
|
||||
error_response(SignUpError::DatabaseError, &form)
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
#[get("/signup_check_email")]
|
||||
async fn sign_up_check_email(connection: web::Data<db::Connection>) -> impl Responder {
|
||||
let recipes = connection.get_all_recipe_titles().unwrap_or_default();
|
||||
MessageTemplate {
|
||||
recipes,
|
||||
message: "An email has been sent, follow the link to validate your account.".to_string(),
|
||||
}
|
||||
}
|
||||
|
||||
#[get("/validation")]
|
||||
async fn sign_up_validation(req: HttpRequest, query: web::Query<HashMap<String, String>>, connection: web::Data<db::Connection>) -> impl Responder {
|
||||
|
||||
println!("req:\n{:#?}", req);
|
||||
|
||||
let client_user_agent = req.headers().get(header::USER_AGENT).map(|v| v.to_str().unwrap_or_default()).unwrap_or_default();
|
||||
let client_ip = req.peer_addr().map(|addr| addr.ip().to_string()).unwrap_or_default();
|
||||
|
||||
let recipes = connection.get_all_recipe_titles().unwrap_or_default();
|
||||
match query.get("token") {
|
||||
Some(token) => {
|
||||
match connection.validation(token, Duration::seconds(consts::VALIDATION_TOKEN_DURATION), &client_ip, client_user_agent).unwrap() {
|
||||
db::ValidationResult::Ok(token, user_id) =>
|
||||
// TODO: set token to cookie.
|
||||
MessageTemplate {
|
||||
recipes,
|
||||
message: "Email validation successful, your account has been created".to_string(),
|
||||
},
|
||||
db::ValidationResult::ValidationExpired =>
|
||||
MessageTemplate {
|
||||
recipes,
|
||||
message: "The validation has expired. Try to sign up again.".to_string(),
|
||||
},
|
||||
db::ValidationResult::UnknownUser =>
|
||||
MessageTemplate {
|
||||
recipes,
|
||||
message: "Validation error.".to_string(),
|
||||
},
|
||||
}
|
||||
},
|
||||
None => {
|
||||
MessageTemplate {
|
||||
recipes,
|
||||
message: format!("No token provided"),
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
///// SIGN IN /////
|
||||
|
||||
#[get("/signinform")]
|
||||
async fn sign_in_form(req: HttpRequest, connection: web::Data<db::Connection>) -> impl Responder {
|
||||
SignInFormTemplate {
|
||||
}
|
||||
}
|
||||
|
||||
#[post("/signin")]
|
||||
async fn sign_in(req: HttpRequest) -> impl Responder {
|
||||
"todo"
|
||||
}
|
||||
|
||||
#[get("/recipe/view/{id}")]
|
||||
async fn view_recipe(req: HttpRequest, path: web::Path<(i32,)>, connection: web::Data<db::Connection>) -> impl Responder {
|
||||
ViewRecipeTemplate {
|
||||
recipes: connection.get_all_recipe_titles().unwrap(),
|
||||
current_recipe: connection.get_recipe(path.0).unwrap(),
|
||||
let (id,)= path.into_inner();
|
||||
let recipes = connection.get_all_recipe_titles().unwrap_or_default();
|
||||
println!("{:?}", recipes);
|
||||
match connection.get_recipe(id) {
|
||||
Ok(recipe) =>
|
||||
ViewRecipeTemplate {
|
||||
recipes,
|
||||
current_recipe: recipe,
|
||||
}.to_response(),
|
||||
Err(_error) =>
|
||||
MessageTemplate {
|
||||
recipes,
|
||||
message: format!("Unable to get recipe #{}", id),
|
||||
}.to_response(),
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
struct Config {
|
||||
port: u16
|
||||
async fn not_found(req: HttpRequest, connection: web::Data<db::Connection>) -> impl Responder {
|
||||
let recipes = connection.get_all_recipe_titles().unwrap_or_default();
|
||||
MessageTemplate {
|
||||
recipes,
|
||||
message: "404: Not found".to_string(),
|
||||
}
|
||||
}
|
||||
|
||||
fn get_exe_name() -> String {
|
||||
|
|
@ -66,36 +265,36 @@ async fn main() -> std::io::Result<()> {
|
|||
|
||||
println!("Starting Recipes as web server...");
|
||||
|
||||
let config: Config = {
|
||||
let f = File::open(consts::FILE_CONF).unwrap_or_else(|_| panic!("Failed to open configuration file {}", consts::FILE_CONF));
|
||||
match from_reader(f) {
|
||||
Ok(c) => c,
|
||||
Err(e) => panic!("Failed to load config: {}", e)
|
||||
}
|
||||
};
|
||||
let config = web::Data::new(config::load());
|
||||
let port = config.as_ref().port;
|
||||
|
||||
println!("Configuration: {:?}", config);
|
||||
|
||||
let db_connection = web::Data::new(db::Connection::new().unwrap()); // TODO: remove unwrap.
|
||||
let db_connection = web::Data::new(db::Connection::new().unwrap());
|
||||
|
||||
std::env::set_var("RUST_LOG", "actix_web=info");
|
||||
|
||||
let mut server =
|
||||
HttpServer::new(
|
||||
move || {
|
||||
App::new()
|
||||
.wrap(middleware::Logger::default())
|
||||
.wrap(middleware::Compress::default())
|
||||
.app_data(db_connection.clone())
|
||||
.service(home_page)
|
||||
.service(view_recipe)
|
||||
.service(fs::Files::new("/static", "static").show_files_listing())
|
||||
}
|
||||
);
|
||||
let server =
|
||||
HttpServer::new(move || {
|
||||
App::new()
|
||||
.wrap(middleware::Logger::default())
|
||||
.wrap(middleware::Compress::default())
|
||||
.app_data(db_connection.clone())
|
||||
.app_data(config.clone())
|
||||
.service(home_page)
|
||||
.service(sign_up_get)
|
||||
.service(sign_up_post)
|
||||
.service(sign_up_check_email)
|
||||
.service(sign_up_validation)
|
||||
.service(sign_in_form)
|
||||
.service(sign_in)
|
||||
.service(view_recipe)
|
||||
.service(fs::Files::new("/static", "static"))
|
||||
.default_service(web::to(not_found))
|
||||
//.default_service(not_found)
|
||||
});
|
||||
|
||||
server = server.bind(&format!("0.0.0.0:{}", config.port)).unwrap();
|
||||
|
||||
server.run().await
|
||||
server.bind(&format!("0.0.0.0:{}", port))?.run().await
|
||||
}
|
||||
|
||||
#[derive(Parser, Debug)]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue