Django Auth/Sessions with mongokit

296 views
Skip to first unread message

BRLYNS

unread,
Apr 28, 2010, 6:05:09 PM4/28/10
to mong...@googlegroups.com
Has anyone successfully integrated mongokit as a django auth and sessions backend? If so, could you share the code?

Cheers and thanks to everyone in this group for helping out!

Peter Bengtsson

unread,
Apr 28, 2010, 6:37:14 PM4/28/10
to mong...@googlegroups.com
I certainly have. It works great! First I set this in settings.py:

AUTHENTICATION_BACKENDS = (
'mongo_auth.UserBackend',
)

mongo_auth.py looks like this::

from django.contrib.auth.backends import ModelBackend
from django_mongokit import connection, get_database
from users.models import User

class UserBackend(ModelBackend):

def authenticate(self, username=None, password=None):
collection = get_database(connection).users
user = collection.User.one({'username': username})
if user and user.check_password(password):
return user

def get_user(self, username):
collection = get_database(connection).users
user = collection.User.one({'username':username})
if user:
return user



As you probably know now I'm using django-mongokit to wrap the
MongoKit stuff and I've developed a model for the User which has
worked really well for me. I've attached it to this email. I hope that
works.



On 28 April 2010 23:05, BRLYNS <brl...@gmail.com> wrote:
> Has anyone successfully integrated mongokit as a django auth and sessions backend? If so, could you share the code?
>
> Cheers and thanks to everyone in this group for helping out!



--
Peter Bengtsson,
work www.fry-it.com
home www.peterbe.com
hobby www.issuetrackerproduct.com
fun crosstips.org
models.py

BRLYNS

unread,
May 5, 2010, 6:31:34 PM5/5/10
to mong...@googlegroups.com
Thanks for this. One question though . . . . how do you create users? I didn't see that, but maybe I overlooked.
> <models.py>

mohamed shawky

unread,
Mar 2, 2017, 1:31:58 AM3/2/17
to MongoKit
Creating a User Registration Page using MongoEngine
which database is mongodb
and working with django-rest-framework
frontend is angularJs
please help me thank you for advance

Reply all
Reply to author
Forward
0 new messages