Added docs about using MongoEngine with Django
This commit is contained in:
parent
d48296eacc
commit
b7e8108edd
@ -2,6 +2,14 @@
|
||||
Changelog
|
||||
=========
|
||||
|
||||
Changes is v0.1.3
|
||||
=================
|
||||
- Added Django authentication backend
|
||||
- Added Document.meta support for indexes, which are ensured just before
|
||||
querying takes place
|
||||
- A few minor bugfixes
|
||||
|
||||
|
||||
Changes in v0.1.2
|
||||
=================
|
||||
- Query values may be processed before before being used in queries
|
||||
|
@ -16,6 +16,7 @@ The source is available on `GitHub <http://github.com/hmarr/mongoengine>`_.
|
||||
tutorial
|
||||
userguide
|
||||
apireference
|
||||
django
|
||||
changelog
|
||||
|
||||
Indices and tables
|
||||
|
@ -32,6 +32,8 @@ class User(Document):
|
||||
last_login = DateTimeField(default=datetime.datetime.now)
|
||||
|
||||
def get_full_name(self):
|
||||
"""Returns the users first and last names, separated by a space.
|
||||
"""
|
||||
full_name = u'%s %s' % (self.first_name or '', self.last_name or '')
|
||||
return full_name.strip()
|
||||
|
||||
@ -42,6 +44,10 @@ class User(Document):
|
||||
return True
|
||||
|
||||
def set_password(self, raw_password):
|
||||
"""Sets the user's password - always use this rather than directly
|
||||
assigning to :attr:`~mongoengine.django.auth.User.password` as the
|
||||
password is hashed before storage.
|
||||
"""
|
||||
from random import random
|
||||
algo = 'sha1'
|
||||
salt = get_hexdigest(algo, str(random()), str(random()))[:5]
|
||||
@ -49,11 +55,19 @@ class User(Document):
|
||||
self.password = '%s$%s$%s' % (algo, salt, hash)
|
||||
|
||||
def check_password(self, raw_password):
|
||||
"""Checks the user's password against a provided password - always use
|
||||
this rather than directly comparing to
|
||||
:attr:`~mongoengine.django.auth.User.password` as the password is
|
||||
hashed before storage.
|
||||
"""
|
||||
algo, salt, hash = self.password.split('$')
|
||||
return hash == get_hexdigest(algo, salt, raw_password)
|
||||
|
||||
@classmethod
|
||||
def create_user(cls, username, password, email=None):
|
||||
"""Create (and save) a new user with the given username, password and
|
||||
email address.
|
||||
"""
|
||||
user = User(username=username, email=email)
|
||||
user.set_password(password)
|
||||
user.save()
|
||||
|
Loading…
x
Reference in New Issue
Block a user