Skip to content

Commit

Permalink
set up oauth for microsoft
Browse files Browse the repository at this point in the history
  • Loading branch information
alexwaeseperlman committed Feb 28, 2023
1 parent 9349dfc commit d347b2d
Show file tree
Hide file tree
Showing 11 changed files with 121 additions and 60 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,6 @@ node_modules/
test-results/
end2end/playwright-report/
playwright/.cache/

# api keys
.env
83 changes: 53 additions & 30 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 5 additions & 10 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
name = "leptos_start"
name = "pokerbots"
version = "0.1.0"
edition = "2021"

Expand All @@ -21,21 +21,16 @@ leptos_router = { git = "https://github.com/leptos-rs/leptos", default-features
log = "0.4"
simple_logger = "4"
wasm-bindgen = "0.2"
serde = "1.0.152"
diesel = { version = "2.0.3", features = "sqlite" }

[features]
hydrate = ["leptos/hydrate", "leptos_meta/hydrate", "leptos_router/hydrate"]
ssr = [
"dep:actix-files",
"dep:actix-web",
"dep:leptos_actix",
"leptos/ssr",
"leptos_meta/ssr",
"leptos_router/ssr",
]
ssr = ["dep:actix-files", "dep:actix-web", "dep:leptos_actix", "leptos/ssr", "leptos_meta/ssr", "leptos_router/ssr"]

[package.metadata.leptos]
# The name used by wasm-bindgen/cargo-leptos for the JS/WASM bundle. Defaults to the crate name
output-name = "leptos_start"
output-name = "pokerbots"
# The site root folder is where cargo-leptos generate all output. WARNING: all content of this folder will be erased on a rebuild. Use it in your server setup.
site-root = "target/site"
# The site-root relative folder where all compiled output (JS, WASM and CSS) is written
Expand Down
17 changes: 9 additions & 8 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,20 @@ use leptos_meta::*;
use leptos_router::*;

#[path = "./app_config.rs"]
mod app_config;
pub mod app_config;

mod pages {
pub mod pages {
pub mod homepage;
pub mod signup;
pub mod team;
}

mod components {
pub mod login;
use login::*;
pub mod components {
pub mod nav;
}
use pages::homepage::*;
use pages::signup::*;
use pages::team::*;

#[component]
pub fn App(cx: Scope) -> impl IntoView {
Expand All @@ -23,10 +25,9 @@ pub fn App(cx: Scope) -> impl IntoView {

view! {
cx,

// injects a stylesheet into the document <head>
// id=leptos means cargo-leptos will hot-reload this stylesheet
<Stylesheet id="leptos" href="/pkg/leptos_start.css"/>
<Stylesheet id="leptos" href="/pkg/pokerbots.css"/>

// sets the document title
<Title text="Pokerbots McGill"/>
Expand All @@ -36,7 +37,7 @@ pub fn App(cx: Scope) -> impl IntoView {
<main>
<Routes>
<Route path="" view=|cx| view! { cx, <HomePage/> }/>
<Route path="/signup" view=|cx| view! { cx, <SignUp/> }/>
<Route path="/team" view=|cx| view! { cx, <Team/> }/>
</Routes>
</main>
</Router>
Expand Down
12 changes: 12 additions & 0 deletions src/app/login.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#[path = "../app_config.rs"]
mod app_config;
use app_config::*;
use leptos::{ev::MouseEvent, *};
use leptos_meta::*;
use leptos_router::*;
use leptos_server::*;
use std::fmt;

pub(crate) fn microsoft_login_url() -> String {
format!("https://login.microsoftonline.com/common/oauth2/v2.0/authorize?client_id={}&response_type=code&redirect_uri=http%3A%2F%2Flocalhost:3000%2Fteam&response_mode=query&scope=https%3A%2F%2Fgraph.microsoft.com%2Femail", CLIENT_ID)
}
3 changes: 2 additions & 1 deletion src/app/pages.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
use leptos::*;
pub mod homepage;
pub mod signup;
pub mod team;
7 changes: 3 additions & 4 deletions src/app/pages/homepage.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
use crate::app::login::*;
use leptos::{ev::MouseEvent, *};

#[component]
pub fn HomePage(cx: Scope) -> impl IntoView {
pub(crate) fn HomePage(cx: Scope) -> impl IntoView {
view! {
cx,
<div class="px-64 bg-red-600 py-12 w-full h-72 flex content-baseline">
<h1 class="text-white mt-auto">"Pokerbots McGill"</h1>
</div>
<div class="px-64 py-12 w-full flex content-baseline gap-4">
<a class="primary big" href="/signup">"Make an team"</a>
<a class="primary big">"Log in"</a>
<a href={microsoft_login_url()}>"Log in with Microsoft"</a>
</div>

}
}
15 changes: 10 additions & 5 deletions src/app/pages/signup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ use std::vec;

use super::super::app_config::TEAM_SIZE;

use std::fmt;

#[component]
fn TeamMember(cx: Scope) -> impl IntoView {
fn TeamMember(cx: Scope, id: i32) -> impl IntoView {
view! {
cx,
<div class="w-full">"Email address: "<input class="w-full" type="email"/></div>
<div class="w-full mt-2">"Email address: "<input required name={format!("member-{}", id)} class="w-full" type="email"/></div>
}
}

Expand All @@ -18,7 +20,9 @@ pub fn SignUp(cx: Scope) -> impl IntoView {

let add_member = move || {
let mut a = member_in();
a.push(view! { cx, <TeamMember/> }.into_view(cx));
a.push(
view! { cx, <TeamMember id={member_in().len().try_into().unwrap()}/> }.into_view(cx),
);
set_member_in(a);
};
// TODO: Figure out why adding a member at the start causes the first member not to render after adding more
Expand All @@ -33,7 +37,7 @@ pub fn SignUp(cx: Scope) -> impl IntoView {

view! {
cx,
<form>
<form action="/maketeam">
<div class="w-full flex content-center flex-col flex-wrap">
<div class="w-fit text-center"><h1 class="text-center">"Create a team"</h1></div>
"Team id: " <input name="teamid"/>
Expand All @@ -48,8 +52,9 @@ pub fn SignUp(cx: Scope) -> impl IntoView {
}} prop:disabled=few_members>"Remove member"</button>
</div>
<div class="w-80">
{ member_in }
{ member_in }
</div>
<button class="primary mt-4">"Submit"</button>
</div>
</form>
}
Expand Down
15 changes: 15 additions & 0 deletions src/app/pages/team.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
use leptos::{ev::MouseEvent, *};

struct User {
email: &str;
}

#[component]
pub(crate) fn Team(cx: Scope) -> impl IntoView {
view! {
cx,
<div>
"Worked!"
</div>
}
}
1 change: 1 addition & 0 deletions src/app_config.rs
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
pub const TEAM_SIZE: i32 = 5;
pub const CLIENT_ID: &str = "42cb7f3f-e8fc-4e59-9bb6-2422f6dadbb0";
Loading

0 comments on commit d347b2d

Please sign in to comment.