use actix_identity::Identity;
use actix_web::{http::header::LOCATION, HttpResponse, Responder};
use askama::Template;
use askama_actix::TemplateToResponse;

#[derive(Template)]
#[template(path = "user/login.html")]
struct LoginTemplate {}

#[actix_web::get("/login")]
async fn get(user: Option<Identity>) -> impl Responder {
    if let Some(_) = user {
        return HttpResponse::Found()
            .insert_header((LOCATION, "/"))
            .finish();
    } else {
        let template = LoginTemplate {};

        return template.to_response();
    }
}
