Pythonic SQL-Based Accounts System

Hi all,
I've been reading these forums and I see a few bits about multiplayer games, so I thought I'd share something which I stripped out of an effort of my own.

Basically I was writing a game server, when I realised many of the components were reusable, so while I considered how to precede I stripped the code down, and put the accounts system and the protocol into separate libraries, so others can hopefully benefit from them.

What you end up with is a system-agnostic accounts system.

sqlalchemy is used as a backend. You can use your existing engine if you're using sqlalchemy already - and in fact this is recommended - by passing it to the setup function:

from sqlalchemy_accounts import setup

accounts = setup(engineengine)

accounts pretends to be a module, and you can access it's methods:

account = accounts.create_account(username='john', password='rubbish_password')
assert accounts.authenticate('john', 'rubbish_password') is account
account.lock('You are not welcome.')
assert accounts.authenticate(account.username, account.password) is None

Obviously this would be fairly useless if you couldn't add extra information, so (still using SQL), you can add dictionary-style attributes:

account['email'] = 'j...@example.com'
assert account['email'] == 'j...@example.com'

If anyone finds this useful and wants me to add in more functionality, please let me know.

You can download it from:
https://github.com/chrisnorman7/sqlalchemy_accounts

I have just updated the code style so flakes8 doesn't throw a fit when it runs through it, so problems may be related to that. Either complain on here or submit an issue / pull request.

Cheers, and I hope this helps someone.



_______________________________________________
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector
  • ... AudioGames . net Forum — Developers room : chrisnorman7 via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : danny via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : chrisnorman7 via Audiogames-reflector

Reply via email to