Giter VIP home page Giter VIP logo

Comments (1)

xyproto avatar xyproto commented on May 23, 2024

Hi @siredwin. It warms my soul that you've used permissions2 for 4+ years.

I would be happy to help out both in making the user management system more robust and/or with details about the database setup. I can't think of any potential security issues with discussing this here, since all the code is also open source and readily reviewable by anyone.

permissions2 uses Redis in the most straightforward way I could think of, which is a hash map of users called "users". The username + ":" + property key name is the hash map key:
https://github.com/xyproto/permissions2/blob/main/userstate.go#L162

To be able to quickly index all the keys, there is also a list of all the usernames:
https://github.com/xyproto/permissions2/blob/main/userstate.go#L165

Then, there is also a list of users that have registered, but are not yet confirmed (by, say, clicking an e-mail link):
https://github.com/xyproto/permissions2/blob/main/userstate.go#L168

In order to store a username together with other properties, like for instance prefersDarkMode=true, the username + ":" + the key for the property are used as the hash map key, and "true" for the value. For example, for the user bob:

  • Redis hash map key: bob:prefersDarkMode
  • Redis hash map value: true

The layer between Redis and permissions2 is the simpleredis package. That is where the : between the two keys comes from. Here is the implementation of the HashMap, which uses the HSET command in Redis:

https://github.com/xyproto/simpleredis/blob/main/simpleredis.go#L447

Given a username, like bob as the "elementid" parameter, this function can be used for listing all the property keys:

https://github.com/xyproto/simpleredis/blob/main/simpleredis.go#L508

Redis is more robust than people generally first have the impression of, though, and has settings for persisting data to disk. It's not only a database for storing data in memory. I would be very interested in hearing about which types of robustness gains you are envisioning.

from permissions2.

Related Issues (19)

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.