basic web server functionality
This commit is contained in:
950
Cargo.lock
generated
950
Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
@@ -6,9 +6,11 @@ edition = "2021"
|
|||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
actix-web = "4.3.1"
|
||||||
chrono = "0.4.24"
|
chrono = "0.4.24"
|
||||||
env_logger = "0.10.0"
|
env_logger = "0.10.0"
|
||||||
log = "0.4.17"
|
log = "0.4.17"
|
||||||
oracle = "0.5.7"
|
oracle = "0.5.7"
|
||||||
rand = "0.8.5"
|
rand = "0.8.5"
|
||||||
|
serde = { version = "1.0.160", features = ["derive"] }
|
||||||
sha2 = "0.10.6"
|
sha2 = "0.10.6"
|
||||||
|
|||||||
53
src/main.rs
53
src/main.rs
@@ -3,26 +3,49 @@ use rand::{prelude::Rng, distributions::Alphanumeric };
|
|||||||
use oracle::{Connection, Error};
|
use oracle::{Connection, Error};
|
||||||
use log::{info, warn, error};
|
use log::{info, warn, error};
|
||||||
use env_logger::Env;
|
use env_logger::Env;
|
||||||
|
use actix_web::{web, get, post, web::Json, App, HttpResponse, HttpServer, Responder};
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
static SQL_USERNAME: &str = "group09_user";
|
static SQL_USERNAME: &str = "group09_user";
|
||||||
static SQL_PASSWORD: &str = "group09_user";
|
static SQL_PASSWORD: &str = "group09_user";
|
||||||
static SALT_LEN: usize = 16;
|
static SALT_LEN: usize = 16;
|
||||||
|
static PORT: u16 = 8009;
|
||||||
|
|
||||||
fn main() {
|
|
||||||
|
#[derive(Default, Debug, Serialize, Deserialize, Clone)]
|
||||||
|
struct Login {
|
||||||
|
net_id: String,
|
||||||
|
password: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#[actix_web::main]
|
||||||
|
async fn main() -> std::io::Result<()> {
|
||||||
|
|
||||||
//init logging system
|
//init logging system
|
||||||
let env = Env::default().filter_or("LOG_LEVEL", "info");
|
let env = Env::default().filter_or("LOG_LEVEL", "info");
|
||||||
env_logger::init_from_env(env);
|
env_logger::init_from_env(env);
|
||||||
|
|
||||||
|
let result = HttpServer::new( || {
|
||||||
|
App::new()
|
||||||
|
.service(index)
|
||||||
|
.service(login)
|
||||||
|
.service(homepage)
|
||||||
|
.service(plan_page)
|
||||||
|
})
|
||||||
|
.bind(("127.0.0.1", PORT))?
|
||||||
|
.run()
|
||||||
|
.await;
|
||||||
//Temporary for testing purposes, should write something to make a random salt
|
//Temporary for testing purposes, should write something to make a random salt
|
||||||
let username = "cmckechn";
|
let username = "cmckechn";
|
||||||
let password = "password";
|
let password = "password";
|
||||||
|
|
||||||
//proof of concept tests, create_user should fail in this instance because user was already
|
//proof of concept tests, create_user should fail in this instance because user was already
|
||||||
//created
|
//created
|
||||||
println!("{}",authenticate(username, password).unwrap());
|
//println!("{}",authenticate(username, password).unwrap());
|
||||||
create_user("test", "test_create", "test_first", "test_last").unwrap();
|
//create_user("test", "test_create", "test_first", "test_last").unwrap();
|
||||||
println!("{}", authenticate("test", "test_create").unwrap());
|
//println!("{}", authenticate("test", "test_create").unwrap());
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -95,3 +118,25 @@ fn create_user(username: &str, password: &str, first_name: &str, last_name: &str
|
|||||||
Ok(())
|
Ok(())
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[get("/")]
|
||||||
|
async fn index() -> impl Responder {
|
||||||
|
HttpResponse::Ok().body("Hello world!")
|
||||||
|
}
|
||||||
|
|
||||||
|
#[get("/login")]
|
||||||
|
async fn login(json: Json<Login>) -> Result<String, actix_web::Error> {
|
||||||
|
Ok(format!("{} {}", json.net_id, json.password))
|
||||||
|
}
|
||||||
|
|
||||||
|
#[get("/{net_id}/home")]
|
||||||
|
async fn homepage(path: web::Path<String>) -> impl Responder {
|
||||||
|
let net_id = path.into_inner();
|
||||||
|
HttpResponse::Ok().body(format!("You have reached the homepage of {} user", net_id) )
|
||||||
|
}
|
||||||
|
|
||||||
|
#[get("/{net_id}/plans")]
|
||||||
|
async fn plan_page(path: web::Path<String>) -> impl Responder {
|
||||||
|
let net_id = path.into_inner();
|
||||||
|
HttpResponse::Ok().body(format!("You have reached the plan page of {}", net_id))
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user