Fix logging
This commit is contained in:
parent
a71ba86e45
commit
a99e20d1e6
@ -90,7 +90,7 @@ async fn main() -> std::io::Result<()> {
|
|||||||
dotenv().ok();
|
dotenv().ok();
|
||||||
env_logger::init();
|
env_logger::init();
|
||||||
|
|
||||||
println!("Running on: http://127.0.0.1:8156");
|
println!("Running on: http://127.0.0.1:8156/admin/login/");
|
||||||
HttpServer::new(|| {
|
HttpServer::new(|| {
|
||||||
let tera = Tera::new("templates/**/*").expect("failed to initialize the templates");
|
let tera = Tera::new("templates/**/*").expect("failed to initialize the templates");
|
||||||
let generated = generate();
|
let generated = generate();
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
use crate::{forms::LinkForm, ServerError};
|
use crate::{forms::LinkForm, ServerError};
|
||||||
|
|
||||||
use super::schema::{links, users};
|
use super::schema::{links, users};
|
||||||
use argonautica::{Hasher, Verifier};
|
use argonautica::Hasher;
|
||||||
use diesel::{Insertable, Queryable};
|
use diesel::{Insertable, Queryable};
|
||||||
use dotenv::dotenv;
|
use dotenv::dotenv;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
11
src/views.rs
11
src/views.rs
@ -113,7 +113,7 @@ pub(crate) async fn view_profile(
|
|||||||
user_id: web::Path<String>,
|
user_id: web::Path<String>,
|
||||||
) -> Result<HttpResponse, ServerError> {
|
) -> Result<HttpResponse, ServerError> {
|
||||||
use super::schema::users::dsl::{id, users};
|
use super::schema::users::dsl::{id, users};
|
||||||
println!("Viewing Profile!");
|
info!("Viewing Profile!");
|
||||||
if let Some(identity) = identity.identity() {
|
if let Some(identity) = identity.identity() {
|
||||||
let connection = establish_connection()?;
|
let connection = establish_connection()?;
|
||||||
if let Ok(uid) = user_id.parse::<i32>() {
|
if let Ok(uid) = user_id.parse::<i32>() {
|
||||||
@ -146,7 +146,7 @@ pub(crate) async fn edit_profile(
|
|||||||
user_id: web::Path<String>,
|
user_id: web::Path<String>,
|
||||||
) -> Result<HttpResponse, ServerError> {
|
) -> Result<HttpResponse, ServerError> {
|
||||||
use super::schema::users::dsl::{id, users};
|
use super::schema::users::dsl::{id, users};
|
||||||
println!("Viewing Profile!");
|
info!("Editing Profile!");
|
||||||
if let Some(identity) = identity.identity() {
|
if let Some(identity) = identity.identity() {
|
||||||
let connection = establish_connection()?;
|
let connection = establish_connection()?;
|
||||||
if let Ok(uid) = user_id.parse::<i32>() {
|
if let Ok(uid) = user_id.parse::<i32>() {
|
||||||
@ -182,7 +182,7 @@ pub(crate) async fn process_edit_profile(
|
|||||||
use super::schema::users::dsl::{email, id, password, username, users};
|
use super::schema::users::dsl::{email, id, password, username, users};
|
||||||
|
|
||||||
if let Ok(uid) = user_id.parse::<i32>() {
|
if let Ok(uid) = user_id.parse::<i32>() {
|
||||||
println!("Updating userinfo: ");
|
info!("Updating userinfo: ");
|
||||||
let connection = establish_connection()?;
|
let connection = establish_connection()?;
|
||||||
diesel::update(users.filter(id.eq(uid)))
|
diesel::update(users.filter(id.eq(uid)))
|
||||||
.set((
|
.set((
|
||||||
@ -267,7 +267,6 @@ pub(crate) async fn process_signup(
|
|||||||
.values(&new_user)
|
.values(&new_user)
|
||||||
.execute(&connection)?;
|
.execute(&connection)?;
|
||||||
|
|
||||||
println!("{:?}", data);
|
|
||||||
Ok(HttpResponse::Ok().body(format!("Successfully saved user: {}", data.username)))
|
Ok(HttpResponse::Ok().body(format!("Successfully saved user: {}", data.username)))
|
||||||
} else {
|
} else {
|
||||||
Ok(redirect_builder("/admin/login/"))
|
Ok(redirect_builder("/admin/login/"))
|
||||||
@ -311,7 +310,7 @@ pub(crate) async fn process_login(
|
|||||||
.verify()?;
|
.verify()?;
|
||||||
|
|
||||||
if valid {
|
if valid {
|
||||||
println!("Login of user: {}", &u.username);
|
info!("Log-in of user: {}", &u.username);
|
||||||
let session_token = u.username;
|
let session_token = u.username;
|
||||||
id.remember(session_token);
|
id.remember(session_token);
|
||||||
Ok(redirect_builder("/admin/index/"))
|
Ok(redirect_builder("/admin/index/"))
|
||||||
@ -320,7 +319,7 @@ pub(crate) async fn process_login(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
println!("Failed to login: {}", e);
|
info!("Failed to login: {}", e);
|
||||||
Ok(redirect_builder("/admin/login/"))
|
Ok(redirect_builder("/admin/login/"))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user