Code Monkey home page Code Monkey logo

warp-diesel-ructe-sample's Introduction

Web example: Login with warp, ructe, and diesel

This application is intended as an example of a web service handling a login session. It uses the warp web framework, the ructe template engine and the diesel database layer.

Build Status

A Session object is created for each request (except for static resources), containing a handle to a database connection pool and an Option<User> that is set if the user is logged in.

The authentication are done with bcrypt verification of hashed passwords (the hashes are stored in the database, passwords are never stored or logged in plain text).

When authenticated, the user gets a cookie (httponly, strict samesite) containing a session key, which is used for authentication through the remainder of the session.

Things that could use improvement:

  • The routing provieded by warp is very nice, but it would be nice to be able to define routers and subrouters in a more tree-like way. Perhaps it is possible, and I just havn't found out how yet?

  • I have probably missed something in how errors are supposed to be handled in warp. It feels like I am wrapping Results in Results, and I use more .map_err(...) than I like.

  • Database is not really handled asyncronously yet, so database accesses blocks the worker. See diesel-rs/diesel#399 for information.

Things that remains to be done:

  • Session keys should have a limited age. Maybe doing a request after half that time should generate a new session key?

  • The code that handles the authentication and sessions should be externalized to a separate crate, but the session data should remain application-specific. Generating and verifying the bcrypt hashes and session keys should be done by the external crate, but actually storing them in the database, including migrations to create the tables, should be done by the application.

  • CSRF protection is not yet implemented.

This project was partially inspired by rustasync/team#44 ; go there for more example projects.

Issue reports and pull requests and welcomed.

warp-diesel-ructe-sample's People

Contributors

kaj avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.