From 84778b24fea25edfd2df144296aa33047228e75f Mon Sep 17 00:00:00 2001 From: sa23587 <saif.ali2@stud.th-deg.de> Date: Thu, 23 May 2019 01:59:24 +0200 Subject: [PATCH] Saif Ali: login and signup python codes along with html and css codes --- accounts/__init__.py | 0 accounts/__pycache__/__init__.cpython-37.pyc | Bin 0 -> 152 bytes accounts/__pycache__/admin.cpython-37.pyc | Bin 0 -> 193 bytes accounts/__pycache__/models.cpython-37.pyc | Bin 0 -> 190 bytes accounts/__pycache__/urls.cpython-37.pyc | Bin 0 -> 419 bytes accounts/__pycache__/views.cpython-37.pyc | Bin 0 -> 1143 bytes accounts/admin.py | 3 ++ accounts/apps.py | 5 +++ accounts/migrations/__init__.py | 0 .../__pycache__/__init__.cpython-37.pyc | Bin 0 -> 163 bytes accounts/models.py | 3 ++ accounts/templates/accounts/login.html | 18 +++++++++ accounts/templates/accounts/signup.html | 12 ++++++ accounts/tests.py | 3 ++ accounts/urls.py | 10 +++++ accounts/views.py | 38 ++++++++++++++++++ 16 files changed, 92 insertions(+) create mode 100644 accounts/__init__.py create mode 100644 accounts/__pycache__/__init__.cpython-37.pyc create mode 100644 accounts/__pycache__/admin.cpython-37.pyc create mode 100644 accounts/__pycache__/models.cpython-37.pyc create mode 100644 accounts/__pycache__/urls.cpython-37.pyc create mode 100644 accounts/__pycache__/views.cpython-37.pyc create mode 100644 accounts/admin.py create mode 100644 accounts/apps.py create mode 100644 accounts/migrations/__init__.py create mode 100644 accounts/migrations/__pycache__/__init__.cpython-37.pyc create mode 100644 accounts/models.py create mode 100644 accounts/templates/accounts/login.html create mode 100644 accounts/templates/accounts/signup.html create mode 100644 accounts/tests.py create mode 100644 accounts/urls.py create mode 100644 accounts/views.py diff --git a/accounts/__init__.py b/accounts/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/accounts/__pycache__/__init__.cpython-37.pyc b/accounts/__pycache__/__init__.cpython-37.pyc new file mode 100644 index 0000000000000000000000000000000000000000..eccf5e2a13550da4a41da1b441c8a99d7f5919c2 GIT binary patch literal 152 zcmZ?b<>g`k0=Ib&VnFm`5CH>>K!yVl7qb9~6oz01O-8?!3`HPe1o6w!*(xTqIJKxa z#@Ep=*xx@$A=uH!)zvq~CAB!aB)=dgB`Yy6JwGq8v?Mb*CNViVzcjC;I3_+mGcU6w ZK3=b&@)n0pZhlH>PO2Tq=+8jR008DNC5Zq4 literal 0 HcmV?d00001 diff --git a/accounts/__pycache__/admin.cpython-37.pyc b/accounts/__pycache__/admin.cpython-37.pyc new file mode 100644 index 0000000000000000000000000000000000000000..0e09fdcfbfb405e59223c7bf8dfc7f6094d6aeaf GIT binary patch literal 193 zcmZ?b<>g`k0=Ib&Vw`~VV-N=hn1BoiATAaF5-AKRj5!Rsj8Tk?3@J>(44TX@fuanW zjJH@5Q*tx&{4|-O_)@YG^V0M6lJoOQiZYXmKnAR2C}IXuVB(jZvsFxJacWU<jIX0# zu)lwhLa?KctE+E}OKNd;Nq#{L#DKiS(vr;Nn8f7d{L;LV;ux?6dIgoYIBatBQ%ZAE M?HGYZeg<L&05IP$)&Kwi literal 0 HcmV?d00001 diff --git a/accounts/__pycache__/models.cpython-37.pyc b/accounts/__pycache__/models.cpython-37.pyc new file mode 100644 index 0000000000000000000000000000000000000000..7c6292b87d4061b4197fcfd887e7bff9ccf4bf19 GIT binary patch literal 190 zcmZ?b<>g`k0=Ib&Vr+o)V-N=hn1BoiATAaF5-AKRj5!Rsj8Tk?3@J>(44TX@fuanW zjJMcw^HWlDiv2X1ZgHk$CFZ5)>!l<Wfi$mVC}IIpVB(j(vsFxJacWU<jIX0#u)lwh zLa?KctE+E}OKNd;Nq#{LL~mYVX-Q^sOk#3!eraAwaSX(8y@JYH95z69X-=vgBhbvx HK+FIDt<5kR literal 0 HcmV?d00001 diff --git a/accounts/__pycache__/urls.cpython-37.pyc b/accounts/__pycache__/urls.cpython-37.pyc new file mode 100644 index 0000000000000000000000000000000000000000..df585f663b15326b7fe91976cb3835c605419798 GIT binary patch literal 419 zcmXw$K~BRk5Jl}cNz<l5a03?Ibkpt;APRIxTZsw@SyrnkHc?7qM{xq8ci<pg$y?a; z3al6>)RJfZvqpc$_H7gm5Ul6X4?DvMeOoxL9*7&*dI^Cej&oFCiZS92C%ID)N<h2R z6_|U1>^$!C-X{SHfPCKnrvXrphn7-813p}%adZGrG{%NBRepfZR(o%mc-JO~lSDPL z*8BcOXQ^z;>4^HBf+|<Wh1dt1T&0<uj*Qm|sD-SW8czI9EysOx%6G9$)g)2!Wdf~q z<v=fkD%YkUF3YX8qhV*iwG+@m>)7eA^J>9_;84bOEh?$MP!)kk8-B0uF4&V6m1c|C za=ltTp08&Q^ZA0^3;kNFl67OqxT&**9q-5NK$G&r1eb;4O)jqOLumUWLp*d`a)M9r EAH%nHwEzGB literal 0 HcmV?d00001 diff --git a/accounts/__pycache__/views.cpython-37.pyc b/accounts/__pycache__/views.cpython-37.pyc new file mode 100644 index 0000000000000000000000000000000000000000..a57848d2696180fbae3aeb0b1f19844a87bfc3a6 GIT binary patch literal 1143 zcmZva%We}f6ozfjCC&{3Eenu9Y-f{hQB_qfrASC^S`pZcB2~lKB-75N*q$P)bQQL| z16}e;-XSC;UV#<ocxXUvJ@WDG$n&4i|MPyoL!kY9^?lL~2>F4FtHxlm1zqn!5Jb?N z6f~v<iy6f=%e}&n{UV41xAyX|XvM99#~jwa2tJdzEke<Pu_L%>!`Ky_F^Rgr;6@TL z8!A}}sVrAgWJ;z6_6BdYR69y0CacPql`8E0?b^&_X|i;=2YEqWO|#O5FjTckDP9T9 zgASFD9q4)lVNQ-g`w3Ie423yc&<i@JU%gABHevKH$ptgPoXpt*>N25#j4>%gLl@+N zn%0~MPxy11(S--vgOT+Q55{lK`-uWYxzy`<rp@_klBQK%8oj2oX<45RXQs%l{~ij6 zxD5+wW|dGr2vQt^<(WP@OY%%uUngf$g?NJE6>^U}+fwpFEwxc?O!sS`@{Opwu=u^X zvpzveda}Pg8Xp|IemdUX+uhxtypa0DRHqYhoRrh5OlnX#xe_)x%j8ErJpE+5jl?6| zKvsGHfzS?ooN@*u3#qyXd$(gfgp(!K^#-e8U;csJx)rQ<11y+i2{s%#FcG!BNKA5_ z@5)sfYwq10UWX>)3O%f_5O;&>!p!oiG)D;S23gg|Or)yrU_hizKn%9y?ssgEz>-Z5 z$Z%wYY*yi9$p)>5kLE1*1SU&1kC4rRf~{C%D?z|QUQ_9{3L~$nqXic@BSf@OdQD%q zF}xG_7;-f_2Op19^#Eq0sAmU_0fu^3DU;SlJ5#w^?ZdxkX;m7Py&Hl_W<#{8Zrq6+ p?aD1l4M-;s!8iu)kN**LS{+8dQB<PN<tEb6_(B5;ALBjV`vdH~1t$Oi literal 0 HcmV?d00001 diff --git a/accounts/admin.py b/accounts/admin.py new file mode 100644 index 0000000..8c38f3f --- /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 0000000..9b3fc5a --- /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 0000000..e69de29 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 GIT binary patch literal 163 zcmZ?b<>g`k0=Ib&VnFm`5CH>>K!yVl7qb9~6oz01O-8?!3`HPe1o6wq*(xTqIJKxa z#@Ep=*xx@$A=uH!)zvq~CAB!aB)=dgB`Yy6JwGq8v?Mb*CNViVzcjC;I3_nUy(qCH kGe565CO$qhFS8^*Uaz3?7Kcr4eoARhsvXFd&p^xo0LZK=EdT%j literal 0 HcmV?d00001 diff --git a/accounts/models.py b/accounts/models.py new file mode 100644 index 0000000..71a8362 --- /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 0000000..64fe133 --- /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 0000000..2a81b10 --- /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 0000000..7ce503c --- /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 0000000..5ac0941 --- /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 0000000..391aa97 --- /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 -- GitLab