BurkovBA / django-rest-framework-mongoengine-example

django-rest-framework-mongoengine-example
83 stars 45 forks source link

How to create new user and login? #12

Open miamor opened 5 years ago

miamor commented 5 years ago

Hello, I have managed to install and run your example, however I cannot createsuperuser to login to admin as well as I don't know how to create new user, how to login to get token. Could you help me on how to create new user, how to login, and can I use django admin panel for this? Also, after installing and migrating I don't see any new database created in mongo, is it okay or did I miss on something?

BurkovBA commented 5 years ago

I believe, this example should be using version of Mongoengine like 0.8.

In order to run management commands such as createsuperuser or createuser, it should rely upon mongoengine.django.auth module, which contains some implementations of those commands: https://github.com/MongoEngine/mongoengine/blob/0.8/mongoengine/django/auth.py#L140.

As for the authentication code with TokenAuthentication, it should reside in https://github.com/BurkovBA/django-rest-framework-mongoengine-example/blob/master/project/users/authentication.py. You just use the TokenAuthentication class in authentication_classes of your views: https://www.django-rest-framework.org/api-guide/authentication/.

If you need to implement login page, see: https://github.com/BurkovBA/django-rest-framework-mongoengine-example/blob/master/project/users/views.py