SQL database (diesel) integration for actix framework
Uses either SQLite, Postgresql, or MySQL as the backend for an identity provider
```rust extern crate actixweb; extern crate actixwebsqlidentity;
use actixweb::{http, server, App, HttpRequest, Responder}; use actixweb::middleware::identity::{IdentityService, RequestIdentity}; use actixwebsql_identity::SqlIdentityBuilder;
const POOL_SIZE: usize = 3; // Number of connections per pool
fn login(mut req: HttpRequest) -> impl Responder { // Should pull username/id from request req.remember("usernameorid".tostring()); "Logged in!".tostring() }
fn profile(req: HttpRequest) -> impl Responder { if let Some(user) = req.identity() { format!("Hello, {}!", user) } else { "Hello, anonymous user!".to_string() } }
fn logout(mut req: HttpRequest) -> impl Responder { req.forget(); "Logged out!".to_string() }
fn main() { server::new(|| { let policy = SqlIdentityBuilder::new("my.db") .poolsize(POOLSIZE);
App::new()
.route("/login", http::Method::POST, login)
.route("/profile", http::Method::GET, profile)
.route("/logout", http::Method::POST, logout)
.middleware(IdentityService::new(
policy.sqlite()
.expect("failed to connect to database")))
})
.bind("127.0.0.1:7070").unwrap()
.run();
} ```
BSD 3-Clause
Kevin Allison kvnallsn AT gmail.com