Set up html files for SPA
This commit is contained in:
parent
24027ed3c5
commit
f5e3dd644f
Binary file not shown.
Binary file not shown.
|
|
@ -1,10 +1,8 @@
|
|||
use axum_session::{Session, SessionAnyPool};
|
||||
use axum::{
|
||||
extract::Query,
|
||||
response::{IntoResponse, Redirect},
|
||||
};
|
||||
use axum::
|
||||
response::{IntoResponse, Redirect}
|
||||
;
|
||||
use oauth2::{
|
||||
basic::BasicClient, reqwest::async_http_client, AuthUrl, AuthorizationCode, ClientId, ClientSecret, CsrfToken, PkceCodeChallenge, RedirectUrl, Scope, TokenResponse, TokenUrl
|
||||
basic::BasicClient, AuthUrl, ClientId, ClientSecret, CsrfToken, PkceCodeChallenge, RedirectUrl, Scope, TokenUrl
|
||||
};
|
||||
use serde::Deserialize;
|
||||
use std::env;
|
||||
|
|
@ -35,53 +33,6 @@ pub async fn google_auth() -> impl IntoResponse {
|
|||
Redirect::to(&auth_url.to_string())
|
||||
}
|
||||
|
||||
pub async fn google_authorized(_session: Session<SessionAnyPool>,
|
||||
Query(query): Query<AuthRequest>,
|
||||
// Extension(oauth_clients): Extension<HashMap<&str, BasicClient>>,
|
||||
) -> impl IntoResponse {
|
||||
// Check for Google client
|
||||
// if oauth_clients.contains_key("Google") {
|
||||
|
||||
println!("{:?}", query);
|
||||
|
||||
// Get an auth token
|
||||
let token = match google_oauth_client()
|
||||
.exchange_code(AuthorizationCode::new(query.code.clone()))
|
||||
.request_async(async_http_client)
|
||||
.await {
|
||||
Ok(token) => token,
|
||||
Err(_) => panic!("Didn't get a token"),
|
||||
};
|
||||
/*
|
||||
// Fetch user data from google
|
||||
let client = reqwest::Client::new();
|
||||
let user_data: User = client
|
||||
// https://discord.com/developers/docs/resources/user#get-current-user
|
||||
.get("https://discordapp.com/api/users/@me")
|
||||
.bearer_auth(token.access_token().secret())
|
||||
.send()
|
||||
.await
|
||||
.unwrap()
|
||||
.json::<User>()
|
||||
.await
|
||||
.unwrap();
|
||||
*/
|
||||
|
||||
//(headers, Redirect::to("/dashboard".parse().unwrap()))
|
||||
// }
|
||||
|
||||
let mut page = String::new();
|
||||
page.push_str(&"Display the data returned by Google\n".to_string());
|
||||
page.push_str(&"\nState: ".to_string());
|
||||
page.push_str(&query.state);
|
||||
page.push_str(&"\nCode: ".to_string());
|
||||
page.push_str(&query.code);
|
||||
page.push_str(&"\nAccess Token: ".to_string());
|
||||
page.push_str(&token.access_token().secret());
|
||||
|
||||
page
|
||||
}
|
||||
|
||||
pub fn google_oauth_client() -> BasicClient {
|
||||
if std::env::var_os("GOOGLE_CLIENT_ID").is_none() {
|
||||
std::env::set_var("GOOGLE_CLIENT_ID", "735264084619-clsmvgdqdmum4rvrcj0kuk28k9agir1c.apps.googleusercontent.com")
|
||||
|
|
|
|||
|
|
@ -1,10 +1,8 @@
|
|||
use std::net::SocketAddr;
|
||||
use askama::Template;
|
||||
use axum::{
|
||||
extract::{FromRef, State}, middleware, response::{Html, IntoResponse, Redirect, Response}, routing::{get, get_service}, Extension, Router
|
||||
middleware, response::{Html, IntoResponse, Response}, routing::{get, get_service}, Extension, Router
|
||||
};
|
||||
use axum_extra::TypedHeader;
|
||||
use headers::Cookie;
|
||||
use http::{Request, StatusCode};
|
||||
use sqlx::{sqlite::SqlitePoolOptions, SqlitePool};
|
||||
use tower_http::services::ServeDir;
|
||||
|
|
@ -44,13 +42,6 @@ struct IndexTemplate {
|
|||
name: String,
|
||||
}
|
||||
|
||||
#[derive(Template)]
|
||||
#[template(path = "login.html")]
|
||||
struct LoginTemplate {
|
||||
logged_in: bool,
|
||||
name: String,
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct AppState {
|
||||
pub db_pool: SqlitePool,
|
||||
|
|
@ -109,10 +100,9 @@ async fn main() {
|
|||
|
||||
async fn index<T>(
|
||||
Extension(user_data): Extension<Option<UserData>>,
|
||||
request: Request<T>,
|
||||
_request: Request<T>,
|
||||
) -> impl IntoResponse {
|
||||
let user_email = user_data.map(|s| s.user_email);
|
||||
let login_return_url = "?return_url=".to_owned() + &*request.uri().to_string();
|
||||
let logged_in = user_email.is_some();
|
||||
let name = user_email.unwrap_or_default();
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,44 @@
|
|||
<!-- Carousel -->
|
||||
<div id="demo" class="carousel slide" data-bs-ride="carousel">
|
||||
|
||||
<!-- Indicators/dots -->
|
||||
<div class="carousel-indicators">
|
||||
<button type="button" data-bs-target="#demo" data-bs-slide-to="0" class="active"></button>
|
||||
<button type="button" data-bs-target="#demo" data-bs-slide-to="1"></button>
|
||||
<button type="button" data-bs-target="#demo" data-bs-slide-to="2"></button>
|
||||
</div>
|
||||
|
||||
<div class="carousel-inner">
|
||||
<div class="carousel-item active">
|
||||
<img src="assets/images/slide-01.jpg" alt="View from the dock" class="d-block w-100">
|
||||
<div class="carousel-caption">
|
||||
<h3>Jean-Marie Family</h3>
|
||||
<p>View from the dock</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="carousel-item">
|
||||
<img src="assets/images/slide-02.jpg" alt="Sunset at 3 sisters" class="d-block w-100">
|
||||
<div class="carousel-caption">
|
||||
<h3>Jean-Marie Family</h3>
|
||||
<p>Sunset over the 3 sisters</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="carousel-item">
|
||||
<img src="assets/images/slide-03.jpg" alt="Purple sunset" class="d-block w-100">
|
||||
<div class="carousel-caption">
|
||||
<h3>Jean-Marie Family</h3>
|
||||
<p>Purple sunset</p>
|
||||
</div>
|
||||
</div>
|
||||
<!-- The slideshow/carousel -->
|
||||
|
||||
|
||||
<!-- Left and right controls/icons -->
|
||||
<button class="carousel-control-prev" type="button" data-bs-target="#demo" data-bs-slide="prev">
|
||||
<span class="carousel-control-prev-icon"></span>
|
||||
</button>
|
||||
<button class="carousel-control-next" type="button" data-bs-target="#demo" data-bs-slide="next">
|
||||
<span class="carousel-control-next-icon"></span>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
|
|
@ -10,9 +10,7 @@
|
|||
<meta name="author" content="">
|
||||
|
||||
<!-- Bootstrap CSS -->
|
||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet"
|
||||
integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
|
||||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.5.0/font/bootstrap-icons.css">
|
||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
|
||||
|
||||
<body>
|
||||
<nav class="navbar navbar-expand-sm bg-light">
|
||||
|
|
@ -24,14 +22,14 @@
|
|||
<a class="nav-link" href="/">Home</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="#">About</a>
|
||||
<a class="nav-link" href="/about">About</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="#">Contact</a>
|
||||
<a class="nav-link" href="/contactus">Contact Us</a>
|
||||
</li>
|
||||
{% if logged_in %}
|
||||
<li class="nav-item"><a class="nav-link" href="/logout">Logout</a></li>
|
||||
<li class="nav-item"><a class="nav-link" href="#">{{ name }}</a></li>
|
||||
<li class="nav-item"><a class="nav-link" href="/profile">{{ name }}</a></li>
|
||||
{% else %}
|
||||
<li class="nav-item"><a class="nav-link" href="/login">Login</a></li>
|
||||
{% endif %}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,3 @@
|
|||
{% extends "base.html" %}
|
||||
{% block content %}
|
||||
<div class="container py-5 h-100">
|
||||
<br>
|
||||
<p>This will be the private information area for the extended Jean-Marie family.</p>
|
||||
|
|
@ -17,4 +15,3 @@
|
|||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
{% endblock content %}
|
||||
|
|
@ -1,5 +1,24 @@
|
|||
{% extends "base.html" %}
|
||||
{% block content %}
|
||||
{% if logged_in %}
|
||||
<div class="container py-5 h-100">
|
||||
<br>
|
||||
<p>This will be the private information area for the extended Jean-Marie family.</p>
|
||||
<div>
|
||||
<h2>Web links</h2>
|
||||
<h3>Fonts</h3>
|
||||
<ul>
|
||||
<li><a href="https://fonts.google.com">Google fonts</a></li>
|
||||
<li><a href="https://www.fontspace.com">Font Space</a></li>
|
||||
</ul>
|
||||
<h3>Family tree</h3>
|
||||
<ul>
|
||||
<li><a href="https://www.ancestry.com">Ancestry</a></li>
|
||||
<li><a href="https://www.geni.com">Geni</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
{% else %}
|
||||
<!-- Carousel -->
|
||||
<div id="demo" class="carousel slide" data-bs-ride="carousel">
|
||||
|
||||
|
|
@ -43,4 +62,5 @@
|
|||
<span class="carousel-control-next-icon"></span>
|
||||
</button>
|
||||
</div>
|
||||
{% endif %}
|
||||
{% endblock content %}
|
||||
Loading…
Reference in New Issue