diff --git a/accounts/__init__.py b/accounts/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/accounts/__pycache__/__init__.cpython-37.pyc b/accounts/__pycache__/__init__.cpython-37.pyc new file mode 100644 index 0000000000000000000000000000000000000000..eccf5e2a13550da4a41da1b441c8a99d7f5919c2 Binary files /dev/null and b/accounts/__pycache__/__init__.cpython-37.pyc differ diff --git a/accounts/__pycache__/admin.cpython-37.pyc b/accounts/__pycache__/admin.cpython-37.pyc new file mode 100644 index 0000000000000000000000000000000000000000..0e09fdcfbfb405e59223c7bf8dfc7f6094d6aeaf Binary files /dev/null and b/accounts/__pycache__/admin.cpython-37.pyc differ diff --git a/accounts/__pycache__/models.cpython-37.pyc b/accounts/__pycache__/models.cpython-37.pyc new file mode 100644 index 0000000000000000000000000000000000000000..7c6292b87d4061b4197fcfd887e7bff9ccf4bf19 Binary files /dev/null and b/accounts/__pycache__/models.cpython-37.pyc differ diff --git a/accounts/__pycache__/urls.cpython-37.pyc b/accounts/__pycache__/urls.cpython-37.pyc new file mode 100644 index 0000000000000000000000000000000000000000..df585f663b15326b7fe91976cb3835c605419798 Binary files /dev/null and b/accounts/__pycache__/urls.cpython-37.pyc differ diff --git a/accounts/__pycache__/views.cpython-37.pyc b/accounts/__pycache__/views.cpython-37.pyc new file mode 100644 index 0000000000000000000000000000000000000000..a57848d2696180fbae3aeb0b1f19844a87bfc3a6 Binary files /dev/null and b/accounts/__pycache__/views.cpython-37.pyc differ diff --git a/accounts/admin.py b/accounts/admin.py new file mode 100644 index 0000000000000000000000000000000000000000..8c38f3f3dad51e4585f3984282c2a4bec5349c1e --- /dev/null +++ b/accounts/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/accounts/apps.py b/accounts/apps.py new file mode 100644 index 0000000000000000000000000000000000000000..9b3fc5a44939430bfb326ca9a33f80e99b06b5be --- /dev/null +++ b/accounts/apps.py @@ -0,0 +1,5 @@ +from django.apps import AppConfig + + +class AccountsConfig(AppConfig): + name = 'accounts' diff --git a/accounts/migrations/__init__.py b/accounts/migrations/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/accounts/migrations/__pycache__/__init__.cpython-37.pyc b/accounts/migrations/__pycache__/__init__.cpython-37.pyc new file mode 100644 index 0000000000000000000000000000000000000000..31f20cd4434a2928855e203203d06d0cc077c818 Binary files /dev/null and b/accounts/migrations/__pycache__/__init__.cpython-37.pyc differ diff --git a/accounts/models.py b/accounts/models.py new file mode 100644 index 0000000000000000000000000000000000000000..71a836239075aa6e6e4ecb700e9c42c95c022d91 --- /dev/null +++ b/accounts/models.py @@ -0,0 +1,3 @@ +from django.db import models + +# Create your models here. diff --git a/accounts/templates/accounts/login.html b/accounts/templates/accounts/login.html new file mode 100644 index 0000000000000000000000000000000000000000..64fe133588eedcd0019d4a1c08242a03f09a4d3d --- /dev/null +++ b/accounts/templates/accounts/login.html @@ -0,0 +1,18 @@ +{% extends 'base_layout.html' %} + +{% block content %} + <h1>Log in</h1> + <form class="site-form" action="{% url 'accounts:login' %}" method="post"> + {% csrf_token %} + {{ form }} + {% if request.GET.next %} + <input type="hidden" name="next" value="{{ request.GET.next }}" /> + {% endif %} + <input type="submit" value="Login" /> + </form> + <p>Not got an account? <a href="{% url 'accounts:signup' %}">Sign Up</a></p> +{% endblock %} + + + +#5 in the accounts url i want to use login url diff --git a/accounts/templates/accounts/signup.html b/accounts/templates/accounts/signup.html new file mode 100644 index 0000000000000000000000000000000000000000..2a81b105d630eb4709c97db7b69c9c00b63d0d0b --- /dev/null +++ b/accounts/templates/accounts/signup.html @@ -0,0 +1,12 @@ +{% extends 'base_layout.html' %} + +{% block content %} + <h1>Signup</h1> + <form class="site-form" action="/accounts/signup/" method="post"> + {% csrf_token %} + {{ form }} + <input type="submit" value="Signup"> + </form> +{% endblock %} + +#6 is the security csrf_token which server gets and knows that data is comming from your application diff --git a/accounts/tests.py b/accounts/tests.py new file mode 100644 index 0000000000000000000000000000000000000000..7ce503c2dd97ba78597f6ff6e4393132753573f6 --- /dev/null +++ b/accounts/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/accounts/urls.py b/accounts/urls.py new file mode 100644 index 0000000000000000000000000000000000000000..5ac094159a429f15c2127d808582d97bf68b79cb --- /dev/null +++ b/accounts/urls.py @@ -0,0 +1,10 @@ +from django.conf.urls import url +from . import views + +app_name = 'accounts' + +urlpatterns = [ + url(r'^signup/$', views.signup_view, name="signup"), + url(r'^login/$', views.login_view, name="login"), + url(r'^logout/$', views.logout_view, name="logout"), +] diff --git a/accounts/views.py b/accounts/views.py new file mode 100644 index 0000000000000000000000000000000000000000..391aa97a7eccffbf02113d1684072a95ca21920d --- /dev/null +++ b/accounts/views.py @@ -0,0 +1,38 @@ +from django.shortcuts import render, redirect +from django.contrib.auth.forms import UserCreationForm, AuthenticationForm +from django.contrib.auth import login, logout + +def signup_view(request): + if request.method == 'POST': + form = UserCreationForm(request.POST) + if form.is_valid(): + user = form.save() + # log the user in + login(request, user) + return redirect('articles:list') + else: + form = UserCreationForm() + return render(request, 'accounts/signup.html', { 'form': form }) + +def login_view(request): + if request.method == 'POST': + form = AuthenticationForm(data=request.POST) + if form.is_valid(): + # log the user in + user = form.get_user() + login(request, user) + return redirect('articles:list') + else: + form = AuthenticationForm() + return render(request, 'accounts/login.html', { 'form': form }) + +def logout_view(request): + if request.method == 'POST': + logout(request) + return redirect('articles:list') + + + +#user is varialbe in 22 which is going to retrieve the info of the user trying to login + + #on 10 and 21 we are not logging in the users but redirecting them