Mongoengine user authentication

Does anyone have specific examples of using authentication with Mongoengine?

A few questions that I have:

User class extension

from mongoengine.django.auth import User
from mongoengine import *

class User(User):
    location =  GeoPointField()

When I create a user without documents saved

User.create_user('bob','bobpass','bobsaget@fullhouse.gov')
User.objects
>>>[]

explicitly calling the .save () method has the same effect

Can a user class not be inherited?

Besides

Is there a login () method like in the standard authentication backend?

I'm starting to feel like I'm trying to put a square anchor in a circular hole with MongoDB and Django ...

+3
source share
2 answers

I did not use MongoEngine, but I looked at the documentation for it.

-, User , . , , Profile:

from mongoengine.django.auth import User
from mongoengine import *

class Profile(User):
    location =  GeoPointField()

, :

class Profile(Document):
    user = ReferenceField(User)
    location =  GeoPointField()

, .

+2

.

user = User.create_user('bob','bobpass','bobsaget@fullhouse.gov')
user.save()

user = User(username='bob', password='bobpass', email='bobsaget@fullhouse.gov')
user.save()

user = User()
user.username = 'bob'
user.password = 'bobpass'
user.email = 'bobsaget@fullhouse.gov'
user.save()
0

Source: https://habr.com/ru/post/1773177/


All Articles