Code Monkey home page Code Monkey logo

django-users2's Introduction

django-users2

image

Latest Version

Downloads

License

image

Custom user model for django >=1.5 with support for multiple user types and lots of other awesome utils (mostly borrowed from other projects). If you are using django < 1.11, please install v0.2.1 or earlier (pip install django-users2<=0.2.1).

Features

  • email as username for authentication (barebone extendable user models)
  • support for multiple user types (using the awesome django-model-utils)
  • automatically creates superuser after syncdb/migrations (really handy during the initial development phases)
  • built in emails/passwords validators (with lots of customisable options)
  • prepackaged with all the templates, including additional templates required by views in django.contrib.auth (for a painless signup process)

Documentation

The full documentation is at https://django-users2.readthedocs.org.

Quickstart

  1. Install `django-users2`:

    pip install django-users2
  2. Add django-users2 to `INSTALLED_APPS`:

    INSTALLED_APPS = (
        ...
        'django.contrib.auth',
        'django.contrib.sites',
        'users',
        ...
    )
  3. Set your AUTH_USER_MODEL setting to use users.User:

    AUTH_USER_MODEL = 'users.User'
  4. Once you’ve done this, run the migrate command to install the model used by this package:

    python manage.py migrate
  5. Add the django-users2 URLs to your project’s URLconf as follows:

    urlpatterns = patterns('',
        ...
        url(r'^accounts/', include('users.urls')),
        ...
    )

which sets up URL patterns for the views in django-users2 as well as several useful views in django.contrib.auth (e.g. login, logout, password change/reset)

Configuration

Set USERS_VERIFY_EMAIL = True to enable email verification for registered users.

When a new User object is created, with its is_active field set to False, an activation key is generated, and an email is sent to the user containing a link to click to activate the account:

USERS_VERIFY_EMAIL = False

Upon clicking the activation link, the new account is made active (i.e. is_active field is set to True); after this, the user can log in. Optionally, you can automatically login the user after successful activation:

USERS_AUTO_LOGIN_ON_ACTIVATION = True

This is the number of days the users will have, to activate their accounts after registering:

USERS_EMAIL_CONFIRMATION_TIMEOUT_DAYS = 3

Automatically create django superuser after syncdb, by default this option is enabled when settings.DEBUG = True.

You can customise the email/password by overriding USERS_SUPERUSER_EMAIL and USERS_SUPERUSER_PASSWORD settings (highly recommended):

USERS_CREATE_SUPERUSER = settings.DEBUG
USERS_SUPERUSER_EMAIL = '[email protected]'
USERS_SUPERUSER_PASSWORD = 'django'  

Prevent automated registration by spambots, by enabling a hidden (using css) honeypot field:

USERS_SPAM_PROTECTION = True

Prevent user registrations by setting USERS_REGISTRATION_OPEN = False:

USERS_REGISTRATION_OPEN = True

Settings for validators, that check the strength of user specified passwords:

# Specifies minimum length for passwords:
USERS_PASSWORD_MIN_LENGTH = 5

#Specifies maximum length for passwords:
USERS_PASSWORD_MAX_LENGTH = None

Optionally, the complexity validator, checks the password strength:

USERS_CHECK_PASSWORD_COMPLEXITY = True

Specify number of characters within various sets that a password must contain:

USERS_PASSWORD_POLICY = {
    'UPPER': 0,       # Uppercase 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
    'LOWER': 0,       # Lowercase 'abcdefghijklmnopqrstuvwxyz'
    'DIGITS': 0,      # Digits '0123456789'
    'PUNCTUATION': 0  # Punctuation """!"#$%&'()*+,-./:;<=>?@[\]^_`{|}~"""
}

Allow/disallow registration using emails addresses from specific domains:

USERS_VALIDATE_EMAIL_DOMAIN = True

List of disallowed domains:

USERS_EMAIL_DOMAINS_BLACKLIST = []

For example, USERS_EMAIL_DOMAINS_BLACKLIST = ['mailinator.com'] will block all visitors from using mailinator.com email addresses to register.

List of allowed domains:

USERS_EMAIL_DOMAINS_WHITELIST = []

For example, USERS_EMAIL_DOMAINS_WHITELIST = ['ljworld.com'] will only allow user registration with ljworld.com domains.

django-users2's People

Contributors

alwerdani avatar caisong avatar jfmatth avatar joshblum avatar mishbahr avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

django-users2's Issues

Question - do i need django.contrib.auth enabled?

when i remove django.contrib.auth i get the following when trying to syncdb

CommandError: One or more models did not validate:
users.user: 'groups' has an m2m relation with model <class 'django.contrib.auth.models.Group'>, whic
h has either not been installed or is abstract.
users.user: 'user_permissions' has an m2m relation with model <class 'django.contrib.auth.models.Per
mission'>, which has either not been installed or is abstract.

researching this and will create a Pull request if i find it.

Hmm, I see you're referencing the the app in

from django.contrib.auth.models import (
    AbstractBaseUser,
    PermissionsMixin
)

How to manage user types ?

@mishbahr have read #9 issue but my concern is i need to differentiate user by employer and employee how can i implement that one ? I am a beginner in django and python

Leaking of password reset token through the reset url

I think it is possible to leak the password reset token since it is left in the url.

In Django 1.11 the token is stripped during a redirect (docs, code) to prevent the token from being taken in the referrer header from 3rd party apps on the page. I haven't dug too deeply into the source for this project but at a first glance it seems that the vulnerability exists.

If this is the case would be happy to help fix similar to django-registration-redux, or at the very least alert you to the issue. Let me know if you guys need any help!

Migration file missing?

My django model is like this,

class Person(User):
    person_id = models.CharField('person id', max_length=254)
    person_id_type = models.CharField('person id type', max_length=254)
    first_name = models.CharField('first name', max_length=254)
    last_name = models.CharField('last name', max_length=254)
    phone = models.CharField('phone', max_length=254)
    photo = models.ImageField(upload_to='photos', max_length=254)

    class Meta:
        verbose_name = 'Person'
        verbose_name_plural = 'Persons'

Migrations work fine if I run this locally. These migration scripts (from ./manage.py makemigrations) are committed in the repo. I have docker container that will copy this repo and run ./manage.py migrate but this will fail with error:

django.db.migrations.exceptions.NodeNotFoundError: Migration accounts.0001_initial dependencies reference nonexistent parent node ('users', '0003_auto_20160105_0955')

Reason it fails because my model migration script depends on 0003_auto_20160105_0955.py and this script is no where to be found because it was generated by django-users2.

To fix this I have to connect into the container and delete all the migration script, and recreate by running ./manage.py makemigrations, only then the migration will work.

Any idea on how to solve this?

django 1.7 compatibility

Just tried installing django-users2 with 1.7, and it blows up due to create_superuser() being moved. I'm not sure what else has changed, but here's the scenario:

  1. Install django-users2 (0.1.11)
  2. install django 1.7
  3. django-admin startproject userstest
  4. cd userstest
    5 python manage.py migrate
Traceback (most recent call last):
  File "manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "C:\Users\jmatthew\Development\vusers2\lib\site-packages\django-1.7-py2.7.egg\django\core\man
agement\__init__.py", line 385, in execute_from_command_line
    utility.execute()
  File "C:\Users\jmatthew\Development\vusers2\lib\site-packages\django-1.7-py2.7.egg\django\core\man
agement\__init__.py", line 354, in execute
    django.setup()
  File "C:\Users\jmatthew\Development\vusers2\lib\site-packages\django-1.7-py2.7.egg\django\__init__
.py", line 21, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "C:\Users\jmatthew\Development\vusers2\lib\site-packages\django-1.7-py2.7.egg\django\apps\reg
istry.py", line 115, in populate
    app_config.ready()
  File "C:\Users\jmatthew\Development\vusers2\lib\site-packages\django-1.7-py2.7.egg\django\contrib\
admin\apps.py", line 22, in ready
    self.module.autodiscover()
  File "C:\Users\jmatthew\Development\vusers2\lib\site-packages\django-1.7-py2.7.egg\django\contrib\
admin\__init__.py", line 23, in autodiscover
    autodiscover_modules('admin', register_to=site)
  File "C:\Users\jmatthew\Development\vusers2\lib\site-packages\django-1.7-py2.7.egg\django\utils\mo
dule_loading.py", line 74, in autodiscover_modules
    import_module('%s.%s' % (app_config.name, module_to_search))
  File "c:\python27\Lib\importlib\__init__.py", line 37, in import_module
    __import__(name)
  File "C:\Users\jmatthew\Development\vusers2\lib\site-packages\django_users2-0.1.11-py2.7.egg\users
\admin.py", line 10, in <module>
    from .utils import send_activation_email
  File "C:\Users\jmatthew\Development\vusers2\lib\site-packages\django_users2-0.1.11-py2.7.egg\users
\utils.py", line 8, in <module>
    from django.contrib.auth.management import create_superuser
ImportError: cannot import name create_superuser

(vusers2) C:\Users\jmatthew\Development\usersTest>pip list
django (1.7)
django-appconf (0.6)
django-model-utils (2.2)
django-users2 (0.1.11)
six (1.8.0)

(vusers2) C:\Users\jmatthew\Development\usersTest>

error while installing django-users2

Hi, i'm trying to install the package via pip3 on digitalocean droplet.
I get this error msg:

pip3 install django-users2
Downloading/unpacking django-users2
  Downloading django-users2-0.1.14.tar.gz
  Running setup.py (path:/tmp/pip_build_root/django-users2/setup.py) egg_info for package django-users2
    Traceback (most recent call last):
      File "<string>", line 17, in <module>
      File "/tmp/pip_build_root/django-users2/setup.py", line 23, in <module>
        readme = open('README.rst').read()
      File "/usr/lib/python3.4/encodings/ascii.py", line 26, in decode
        return codecs.ascii_decode(input, self.errors)[0]
    UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position 1959: ordinal not in range(128)
    Complete output from command python setup.py egg_info:
    Traceback (most recent call last):

  File "<string>", line 17, in <module>

  File "/tmp/pip_build_root/django-users2/setup.py", line 23, in <module>

    readme = open('README.rst').read()

  File "/usr/lib/python3.4/encodings/ascii.py", line 26, in decode

    return codecs.ascii_decode(input, self.errors)[0]

UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position 1959: ordinal not in range(128)

----------------------------------------
Cleaning up...
Command python setup.py egg_info failed with error code 1 in /tmp/pip_build_root/django-users2
Storing debug log for failure in /root/.pip/pip.log

Multiple user types

Hi!

Do you happen to have a working example/demo that implements multiple user types with various fields? It would be very helpful as the documentation is a bit scarce atm.

Thank you!

Override `delete` in queryset

How do I override delete in queryset? I can override delete in each model but that will only work if I'm dealing with object directly like so, Person.objects.get(pk=1).delete().

But this won't work, Person.objects.filter(pk=1).delete() because it is returning a queryset object, and it is calling delete from the queryset. I tried to inherit your UserManager and override the delete method there, but it doesn't work.

Multi type users django.db.utils.ProgrammingError: relation does not exist

I'm a bit confused on how to implement the multi type users. I followed the instructions on how to setup this based on previous issues, but have not managed to get it to work.

So I have this in my accounts module (app) under the models.py.

class Guard(User):
    employee_no = models.CharField('employee number', max_length=30)

    class Meta:
        verbose_name = 'Guard'
        verbose_name_plural = 'Guards'

Then I fire up django shell with ./manage.py shell and I execute the following commands.

$  ./manage.py shell
>>> Guard.objects.create_user(employee_no='1234567', email='[email protected]', password='12345678')
django.db.utils.ProgrammingError: relation "accounts_guard" does not exist
LINE 1: UPDATE "accounts_guard" SET "employee_no" = '123456' WHERE "...
               ^

How do I set this up properly?

Support UUID as primary key

Is there a way I can make my custom user model primary key to use UUID? Right now, I can have another primary key column set as UUIDField but this leads to integer out of range error when adding user to group.

The table users_user_groups is expecting user_id as int4 and this doesn't match with my user model which used UUIDField causing the integer out of range error.

AttributeError

AttributeError: Manager isn't available; 'auth.User' has been swapped for 'users.User'

Unhandled exception in thread started by <function check_errors.<locals>.wrapper at 0x7fef43ee30d0>
Traceback (most recent call last):
  File "/home/antonio/anaconda3/envs/myhome-cloud/lib/python3.6/site-packages/django/utils/autoreload.py", line 225, in wrapper
    fn(*args, **kwargs)
  File "/home/antonio/anaconda3/envs/myhome-cloud/lib/python3.6/site-packages/django/core/management/commands/runserver.py", line 120, in inner_run
    self.check(display_num_errors=True)
  File "/home/antonio/anaconda3/envs/myhome-cloud/lib/python3.6/site-packages/django/core/management/base.py", line 364, in check
    include_deployment_checks=include_deployment_checks,
  File "/home/antonio/anaconda3/envs/myhome-cloud/lib/python3.6/site-packages/django/core/management/base.py", line 351, in _run_checks
    return checks.run_checks(**kwargs)
  File "/home/antonio/anaconda3/envs/myhome-cloud/lib/python3.6/site-packages/django/core/checks/registry.py", line 73, in run_checks
    new_errors = check(app_configs=app_configs)
  File "/home/antonio/anaconda3/envs/myhome-cloud/lib/python3.6/site-packages/django/core/checks/urls.py", line 13, in check_url_config
    return check_resolver(resolver)
  File "/home/antonio/anaconda3/envs/myhome-cloud/lib/python3.6/site-packages/django/core/checks/urls.py", line 23, in check_resolver
    return check_method()
  File "/home/antonio/anaconda3/envs/myhome-cloud/lib/python3.6/site-packages/django/urls/resolvers.py", line 397, in check
    for pattern in self.url_patterns:
  File "/home/antonio/anaconda3/envs/myhome-cloud/lib/python3.6/site-packages/django/utils/functional.py", line 36, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
  File "/home/antonio/anaconda3/envs/myhome-cloud/lib/python3.6/site-packages/django/urls/resolvers.py", line 536, in url_patterns
    patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
  File "/home/antonio/anaconda3/envs/myhome-cloud/lib/python3.6/site-packages/django/utils/functional.py", line 36, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
  File "/home/antonio/anaconda3/envs/myhome-cloud/lib/python3.6/site-packages/django/urls/resolvers.py", line 529, in urlconf_module
    return import_module(self.urlconf_name)
  File "/home/antonio/anaconda3/envs/myhome-cloud/lib/python3.6/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 994, in _gcd_import
  File "<frozen importlib._bootstrap>", line 971, in _find_and_load
  File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 678, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/home/antonio/workspace-legrand/myhome-cloud/mhc/mhc/urls.py", line 26, in <module>
    url(r'^', include('app.urls')),
  File "/home/antonio/anaconda3/envs/myhome-cloud/lib/python3.6/site-packages/django/urls/conf.py", line 34, in include
    urlconf_module = import_module(urlconf_module)
  File "/home/antonio/anaconda3/envs/myhome-cloud/lib/python3.6/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 994, in _gcd_import
  File "<frozen importlib._bootstrap>", line 971, in _find_and_load
  File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 678, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/home/antonio/workspace-legrand/myhome-cloud/mhc/app/urls.py", line 5, in <module>
    from . import views
  File "/home/antonio/workspace-legrand/myhome-cloud/mhc/app/views.py", line 58, in <module>
    class UserViewSet(viewsets.ReadOnlyModelViewSet):
  File "/home/antonio/workspace-legrand/myhome-cloud/mhc/app/views.py", line 62, in UserViewSet
    queryset = User.objects.all()
  File "/home/antonio/anaconda3/envs/myhome-cloud/lib/python3.6/site-packages/django/db/models/manager.py", line 190, in __get__
    cls._meta.swapped,
AttributeError: Manager isn't available; 'auth.User' has been swapped for 'users.User'

any ideas ?

Extending User model

I'm new to django so please be gentle.
I tried to understand how can I extend the user model. I couldn't find any references in the docs.
It's says: "support for multiple user types (using the awesome django-model-utils)",
but I couldn't find any reference of how it can be done.

Tying into signals

I have a need to tie into your signals for activation and registration.

I found the signals.py code, but was unsuccessful in using it in my application.

An example would be great.

thanks

superusers inactive when USERS_VERIFY_EMAIL = True

Scenario 1

settings.USERS_VERIFY_EMAIL = True

New install, python manage.py syncdb + create superuser = Can't login into Admin site :(

In checking the Users_user table, it does show that the field for is_active is 0. Setting that to 1 in scenario 1 allows me to login.

Scenario 2

settings.USERS_VERIFY_EMAIL = False (or not there).

New install, python manage.py syncdb + create superuser = Login fine.

I'm not sure the correct solution here, but it seems if i ask it to create a superuser from the command line, that should override any settings.

user Auto login after register

Hello ,
when i set USERS_AUTO_LOGIN_ON_ACTIVATION = True and ``USERS_VERIFY_EMAIL = False` the user not automatically login after register .

model_utils not installing on first pass

The current pypi version does not include model_utils, so you get an error when running syncdb.

I have to manually install model_utils to get things to work.

I'm running on Windows.

Accept both username or email for authentication

Today we have been seeing authentications that accept bot username or emails for validating an user. We would be great to have that here.

At first, you could add a settings attribute giving the possibility to authenticate user by email or username or both.

NoReverseMatch at /accounts/register/

this is the message:

Reverse for 'users_activate' with arguments '(b'MjA', '4wk-069fbbd3930ffb71a6c1')' not found. 1 pattern(s) tried: ['accounts/activate/(?P<uidb64>[0-9A-Za-z_\\-]+)/(?P<token>[0-9A-Za-z]{1,13}-[0-9A-Za-z]{1,20})/$']

what is the problem ?

Add migrations

I think we should add migration support in case our users are using Django 1.7.

Where does this user come from?

I'm trying to determine where this [email protected] is coming from?

I see the setup for the details in Conf.py under the UsersAppConf class, but how is that being called?

No users should automatically be generated, just like stock django.

J

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.