actix-web-sql-identity 0.1.2

A SQL-backend identity provider for Actix Web's identity system
docs.rs failed to build actix-web-sql-identity-0.1.2
Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.
Visit the last successful build: actix-web-sql-identity-0.4.3

Actix Database Identity Provider

Build Status

SQL database (diesel) integration for actix framework

SQL Backend

Uses either SQLite, Postgresql, or MySQL as the backend for an identity provider

Currently Implemented

  • SQLite
  • MySQL
  • Postgres

Example

extern crate actix_web;
extern crate actix_web_sql_identity;

use actix_web::{http, server, App, HttpRequest, Responder};
use actix_web::middleware::identity::{IdentityService, RequestIdentity};
use actix_web_sql_identity::SqlIdentityPolicy;

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("username_or_id".to_string());
    "Logged in!".to_string()
}

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(
        || App::new()
            .route("/login", http::Method::POST, login)
            .route("/profile", http::Method::GET, profile)
            .route("/logout", http::Method::POST, logout)
            .middleware(IdentityService::new(
                    SqlIdentityPolicy::sqlite(POOL_SIZE, "my.db")
                        .expect("failed to connect to database"))))
        .bind("127.0.0.1:7070").unwrap()
        .run();
}

License

BSD 3-Clause

Author

Kevin Allison kvnallsn AT gmail.com