Remove remaining bits of web front-end

This commit is contained in:
Nathan Sobo
2022-04-21 09:30:08 -06:00
parent 9f83417b58
commit 0cf7bba483
6 changed files with 25 additions and 521 deletions
-9
View File
@@ -1,11 +1,2 @@
DATABASE_URL = "postgres://postgres@localhost/zed"
SESSION_SECRET = "6E1GS6IQNOLIBKWMEVWF1AFO4H78KNU8"
HTTP_PORT = 8080
# Available at https://github.com/organizations/zed-industries/settings/apps/zed-local-development
GITHUB_APP_ID = 115633
GITHUB_CLIENT_ID = "Iv1.768076c9becc75c4"
GITHUB_CLIENT_SECRET = ""
GITHUB_PRIVATE_KEY = """\
"""
-8
View File
@@ -22,19 +22,11 @@ async-std = { version = "1.8.0", features = ["attributes"] }
async-trait = "0.1.50"
async-tungstenite = "0.16"
base64 = "0.13"
clap = "3.1"
comrak = "0.10"
either = "1.6"
envy = "0.4.2"
futures = "0.3"
handlebars = "3.5"
http-auth-basic = "0.1.3"
json_env_logger = "0.1"
jwt-simple = "0.10.0"
lipsum = { version = "0.8", optional = true }
log = { version = "0.4.16", features = ["kv_unstable_serde"] }
oauth2 = { version = "4.0.0", default_features = false }
oauth2-surf = "0.1.1"
parking_lot = "0.11.1"
rand = "0.8"
scrypt = "0.7"
+1 -36
View File
@@ -2,31 +2,18 @@ use super::{
db::{self, UserId},
errors::TideResultExt,
};
use crate::{github, Request, RequestExt as _};
use crate::Request;
use anyhow::{anyhow, Context};
use async_trait::async_trait;
pub use oauth2::basic::BasicClient as Client;
use rand::thread_rng;
use rpc::auth as zed_auth;
use scrypt::{
password_hash::{PasswordHash, PasswordHasher, PasswordVerifier, SaltString},
Scrypt,
};
use serde::Serialize;
use std::convert::TryFrom;
use surf::StatusCode;
use tide::Error;
static CURRENT_GITHUB_USER: &'static str = "current_github_user";
#[derive(Serialize)]
pub struct User {
pub github_login: String,
pub avatar_url: String,
pub is_insider: bool,
pub is_admin: bool,
}
pub async fn process_auth_header(request: &Request) -> tide::Result<UserId> {
let mut auth_header = request
.header("Authorization")
@@ -71,28 +58,6 @@ pub async fn process_auth_header(request: &Request) -> tide::Result<UserId> {
Ok(user_id)
}
#[async_trait]
pub trait RequestExt {
async fn current_user(&self) -> tide::Result<Option<User>>;
}
#[async_trait]
impl RequestExt for Request {
async fn current_user(&self) -> tide::Result<Option<User>> {
if let Some(details) = self.session().get::<github::User>(CURRENT_GITHUB_USER) {
let user = self.db().get_user_by_github_login(&details.login).await?;
Ok(Some(User {
github_login: details.login,
avatar_url: details.avatar_url,
is_insider: user.is_some(),
is_admin: user.map_or(false, |user| user.admin),
}))
} else {
Ok(None)
}
}
}
const MAX_ACCESS_TOKENS_TO_STORE: usize = 8;
pub async fn create_access_token(db: &dyn db::Db, user_id: UserId) -> tide::Result<String> {
-7
View File
@@ -1,7 +0,0 @@
use serde::{Deserialize, Serialize};
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct User {
pub login: String,
pub avatar_url: String,
}
+3 -4
View File
@@ -3,7 +3,6 @@ mod auth;
mod db;
mod env;
mod errors;
mod github;
mod rpc;
use ::rpc::Peer;
@@ -84,13 +83,13 @@ pub async fn run_server(
rpc: Arc<Peer>,
listener: TcpListener,
) -> tide::Result<()> {
let mut app = tide::with_state(state.clone());
rpc::add_routes(&mut app, &rpc);
let mut web = tide::with_state(state.clone());
web.with(CompressMiddleware::new());
api::add_routes(&mut web);
let mut app = tide::with_state(state.clone());
rpc::add_routes(&mut app, &rpc);
app.at("/").nest(web);
app.listen(listener).await?;