├── .autogit ├── autogit.json └── logs │ ├── log-1-7-2020-23-39-45.txt │ ├── log-2-7-2020-0-40-5.txt │ └── log-2-7-2020-0-9-55.txt ├── .gitignore ├── README.md ├── accounts ├── __init__.py ├── admin.py ├── apps.py ├── backends.py ├── forms.py ├── migrations │ ├── 0001_initial.py │ └── __init__.py ├── models.py ├── templates │ ├── profile │ │ ├── profile.html │ │ └── profile_edit.html │ └── registration │ │ ├── logged_out.html │ │ ├── login.html │ │ ├── password_change_form.html │ │ ├── password_reset_complete.html │ │ ├── password_reset_confirm.html │ │ ├── password_reset_done.html │ │ ├── password_reset_email.html │ │ ├── password_reset_form.html │ │ └── signup.html ├── tests.py ├── urls.py └── views.py ├── manage.py ├── project ├── __init__.py ├── settings.py ├── urls.py └── wsgi.py └── templates └── base_generic.html /.autogit/autogit.json: -------------------------------------------------------------------------------- 1 | { 2 | "updateInterval": 1800, 3 | "logging": true, 4 | "silent": true 5 | } -------------------------------------------------------------------------------- /.autogit/logs/log-1-7-2020-23-39-45.txt: -------------------------------------------------------------------------------- 1 | -------------------- Auto-Git Log -------------------- 2 | Sat Aug 01 2020 23:39:45 GMT+0200 (Eastern European Standard Time) 3 | ------------------------------------------------------ 4 | 5 | Modified files: 6 | * accounts/views.py 7 | * project/urls.py 8 | 9 | 10 | Created files: 11 | * accounts/forms.py 12 | * accounts/urls.py 13 | 14 | 15 | Deleted files: 16 | 17 | 18 | Renamed files: 19 | -------------------------------------------------------------------------------- /.autogit/logs/log-2-7-2020-0-40-5.txt: -------------------------------------------------------------------------------- 1 | -------------------- Auto-Git Log -------------------- 2 | Sun Aug 02 2020 00:40:05 GMT+0200 (Eastern European Standard Time) 3 | ------------------------------------------------------ 4 | 5 | Modified files: 6 | 7 | 8 | Created files: 9 | * accounts/backends.py 10 | 11 | 12 | Deleted files: 13 | 14 | 15 | Renamed files: 16 | -------------------------------------------------------------------------------- /.autogit/logs/log-2-7-2020-0-9-55.txt: -------------------------------------------------------------------------------- 1 | -------------------- Auto-Git Log -------------------- 2 | Sun Aug 02 2020 00:09:55 GMT+0200 (Eastern European Standard Time) 3 | ------------------------------------------------------ 4 | 5 | Modified files: 6 | * accounts/forms.py 7 | * accounts/urls.py 8 | * accounts/views.py 9 | 10 | 11 | Created files: 12 | * .autogit/logs/log-1-7-2020-23-39-45.txt 13 | * accounts/templates/profile/profile.html 14 | * accounts/templates/profile/profile_edit.html 15 | * accounts/templates/registration/signup.html 16 | 17 | 18 | Deleted files: 19 | 20 | 21 | Renamed files: 22 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | *$py.class 5 | 6 | # C extensions 7 | *.so 8 | 9 | # Distribution / packaging 10 | .Python 11 | build/ 12 | develop-eggs/ 13 | dist/ 14 | downloads/ 15 | eggs/ 16 | .eggs/ 17 | lib/ 18 | lib64/ 19 | parts/ 20 | sdist/ 21 | var/ 22 | wheels/ 23 | pip-wheel-metadata/ 24 | share/python-wheels/ 25 | *.egg-info/ 26 | .installed.cfg 27 | *.egg 28 | MANIFEST 29 | 30 | # PyInstaller 31 | # Usually these files are written by a python script from a template 32 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 33 | *.manifest 34 | *.spec 35 | 36 | # Installer logs 37 | pip-log.txt 38 | pip-delete-this-directory.txt 39 | 40 | # Unit test / coverage reports 41 | htmlcov/ 42 | .tox/ 43 | .nox/ 44 | .coverage 45 | .coverage.* 46 | .cache 47 | nosetests.xml 48 | coverage.xml 49 | *.cover 50 | *.py,cover 51 | .hypothesis/ 52 | .pytest_cache/ 53 | 54 | # Translations 55 | *.mo 56 | *.pot 57 | 58 | # Django stuff: 59 | *.log 60 | local_settings.py 61 | db.sqlite3 62 | db.sqlite3-journal 63 | 64 | # Flask stuff: 65 | instance/ 66 | .webassets-cache 67 | 68 | # Scrapy stuff: 69 | .scrapy 70 | 71 | # Sphinx documentation 72 | docs/_build/ 73 | 74 | # PyBuilder 75 | target/ 76 | 77 | # Jupyter Notebook 78 | .ipynb_checkpoints 79 | 80 | # IPython 81 | profile_default/ 82 | ipython_config.py 83 | 84 | # pyenv 85 | .python-version 86 | 87 | # pipenv 88 | # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. 89 | # However, in case of collaboration, if having platform-specific dependencies or dependencies 90 | # having no cross-platform support, pipenv may install dependencies that don't work, or not 91 | # install all needed dependencies. 92 | #Pipfile.lock 93 | 94 | # PEP 582; used by e.g. github.com/David-OConnor/pyflow 95 | __pypackages__/ 96 | 97 | # Celery stuff 98 | celerybeat-schedule 99 | celerybeat.pid 100 | 101 | # SageMath parsed files 102 | *.sage.py 103 | 104 | # Environments 105 | .env 106 | .venv 107 | env/ 108 | venv/ 109 | ENV/ 110 | env.bak/ 111 | venv.bak/ 112 | 113 | # Spyder project settings 114 | .spyderproject 115 | .spyproject 116 | 117 | # Rope project settings 118 | .ropeproject 119 | 120 | # mkdocs documentation 121 | /site 122 | 123 | # mypy 124 | .mypy_cache/ 125 | .dmypy.json 126 | dmypy.json 127 | 128 | # Pyre type checker 129 | .pyre/ 130 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # django-accounts 2 | a simple Django Project for dealing with user auth 3 | -------------------------------------------------------------------------------- /accounts/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pythondeveloper6/django-accounts/703dd0a1fb4e391586ff2901d2a68e34b2442056/accounts/__init__.py -------------------------------------------------------------------------------- /accounts/admin.py: -------------------------------------------------------------------------------- 1 | from django.contrib import admin 2 | 3 | # Register your models here. 4 | from .models import Profile 5 | 6 | 7 | admin.site.register(Profile) -------------------------------------------------------------------------------- /accounts/apps.py: -------------------------------------------------------------------------------- 1 | from django.apps import AppConfig 2 | 3 | 4 | class AccountsConfig(AppConfig): 5 | name = 'accounts' 6 | -------------------------------------------------------------------------------- /accounts/backends.py: -------------------------------------------------------------------------------- 1 | from django.contrib.auth.backends import ModelBackend 2 | from django.contrib.auth.models import User 3 | from django.db.models import Q 4 | 5 | 6 | class EmailBackend(ModelBackend): 7 | def authenticate(self,request,username=None,password=None,**kwargs): 8 | ''' check username or email & password is a valid user''' 9 | try: 10 | user = User.objects.get( 11 | Q(username__iexact=username) | 12 | Q(email__iexact=username) 13 | ) 14 | except User.DoesNotExist: 15 | return None 16 | 17 | except MultipleObjectsReturned: 18 | return User.objects.filter(email=username).order_by('id').first() 19 | 20 | else: 21 | if user.check_password(password) and self.user_can_authenticate(user): 22 | return user 23 | 24 | 25 | def get_user(self,user_id): 26 | try : 27 | user = User.objects.get(pk=user_id) 28 | 29 | except User.DoesNotExist: 30 | return None 31 | 32 | return user if self.user_can_authenticate(user) else None 33 | 34 | -------------------------------------------------------------------------------- /accounts/forms.py: -------------------------------------------------------------------------------- 1 | from django import forms 2 | from django.contrib.auth.forms import UserCreationForm 3 | from django.contrib.auth.models import User 4 | from .models import Profile 5 | 6 | class SignupForm(UserCreationForm): 7 | class Meta: 8 | model = User 9 | fields = ['username','email','password1','password2'] 10 | 11 | 12 | 13 | class UserForm(forms.ModelForm): 14 | class Meta: 15 | model = User 16 | fields = ['username' , 'email','first_name','last_name'] 17 | 18 | 19 | class ProfileForm(forms.ModelForm): 20 | class Meta: 21 | model = Profile 22 | fields = ['phone_number' , 'addres'] -------------------------------------------------------------------------------- /accounts/migrations/0001_initial.py: -------------------------------------------------------------------------------- 1 | # Generated by Django 3.0.8 on 2020-08-01 21:06 2 | 3 | from django.conf import settings 4 | from django.db import migrations, models 5 | import django.db.models.deletion 6 | 7 | 8 | class Migration(migrations.Migration): 9 | 10 | initial = True 11 | 12 | dependencies = [ 13 | migrations.swappable_dependency(settings.AUTH_USER_MODEL), 14 | ] 15 | 16 | operations = [ 17 | migrations.CreateModel( 18 | name='Profile', 19 | fields=[ 20 | ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), 21 | ('phone_number', models.CharField(blank=True, max_length=15, null=True)), 22 | ('addres', models.CharField(blank=True, max_length=50, null=True)), 23 | ('user', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)), 24 | ], 25 | ), 26 | ] 27 | -------------------------------------------------------------------------------- /accounts/migrations/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pythondeveloper6/django-accounts/703dd0a1fb4e391586ff2901d2a68e34b2442056/accounts/migrations/__init__.py -------------------------------------------------------------------------------- /accounts/models.py: -------------------------------------------------------------------------------- 1 | from django.db import models 2 | from django.contrib.auth.models import User 3 | from django.db.models.signals import post_save 4 | from django.dispatch import receiver 5 | # Create your models here. 6 | ''' 7 | username 8 | password 9 | first_name 10 | last_name 11 | email 12 | ''' 13 | 14 | class Profile(models.Model): 15 | user = models.OneToOneField(User , on_delete=models.CASCADE) 16 | phone_number = models.CharField(max_length=15,null=True , blank=True) 17 | addres = models.CharField(max_length=50 , blank=True, null=True) 18 | # image 19 | # age 20 | # Job 21 | 22 | def __str__(self): 23 | return str(self.user) 24 | 25 | 26 | @receiver(post_save , sender=User) 27 | def create_user_profile(sender,instance,created , **kwargs): 28 | if created: 29 | Profile.objects.create( 30 | user = instance 31 | ) 32 | -------------------------------------------------------------------------------- /accounts/templates/profile/profile.html: -------------------------------------------------------------------------------- 1 |
Logged out!
5 | Click here to login again. 6 | {% endblock %} -------------------------------------------------------------------------------- /accounts/templates/registration/login.html: -------------------------------------------------------------------------------- 1 | {% extends "base_generic.html" %} 2 | 3 | {% block content %} 4 | 5 | {% if form.errors %} 6 |Your username and password didn't match. Please try again.
7 | {% endif %} 8 | 9 | {% if next %} 10 | {% if user.is_authenticated %} 11 |Your account doesn't have access to this page. To proceed, 12 | please login with an account that has access.
13 | {% else %} 14 |Please login to see this page.
15 | {% endif %} 16 | {% endif %} 17 | 18 | 33 | 34 | {# Assumes you setup the password_reset view in your URLconf #} 35 | 36 | 37 | {% endblock %} -------------------------------------------------------------------------------- /accounts/templates/registration/password_change_form.html: -------------------------------------------------------------------------------- 1 | {% extends "base_generic.html" %} 2 | 3 | {% block content %} 4 | 9 | {% endblock %} -------------------------------------------------------------------------------- /accounts/templates/registration/password_reset_complete.html: -------------------------------------------------------------------------------- 1 | {% extends "base_generic.html" %} 2 | 3 | {% block content %} 4 |Please enter (and confirm) your new password.
6 | 25 | {% else %} 26 |The password reset link was invalid, possibly because it has already been used. Please request a new password reset.
28 | {% endif %} 29 | {% endblock %} -------------------------------------------------------------------------------- /accounts/templates/registration/password_reset_done.html: -------------------------------------------------------------------------------- 1 | {% extends "base_generic.html" %} 2 | 3 | {% block content %} 4 |We've emailed you instructions for setting your password. If they haven't arrived in a few minutes, check your spam folder.
5 | {% endblock %} -------------------------------------------------------------------------------- /accounts/templates/registration/password_reset_email.html: -------------------------------------------------------------------------------- 1 | Someone asked for password reset for email {{ email }}. Follow the link below: 2 | {{ protocol}}://{{ domain }}{% url 'password_reset_confirm' uidb64=uid token=token %} -------------------------------------------------------------------------------- /accounts/templates/registration/password_reset_form.html: -------------------------------------------------------------------------------- 1 | {% extends "base_generic.html" %} 2 | 3 | {% block content %} 4 | 12 | {% endblock %} -------------------------------------------------------------------------------- /accounts/templates/registration/signup.html: -------------------------------------------------------------------------------- 1 |