Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html>
- <head>
- </head>
- <body>
- <h1>Sign In</h1>
- {% if form.errors %}
- <p> Sorry thats invalid username or password</p>
- {% endif %}
- <form method="POST" action="/auth/">{% csrf_token %}
- <label for="email">E-mail</label><br><input type="email" name="email" value="" placeholder="E-mail"><br>
- <label for="password">Password</label><br><input type="password" name="password" placeholder="password">
- <input type="submit" >
- </form>
- </body>
- </html>
- from django.shortcuts import render,render_to_response
- from django.http import HttpResponse
- from django.template import RequestContext
- from .forms import SignUpForm,SignInForm
- from django.contrib import messages
- from django.contrib.auth import authenticate,login
- from django.template.context_processors import csrf
- # Create your views here.
- def home(request):
- return render_to_response('index.html')
- def signup(request):
- form=SignUpForm(request.POST or None)
- if form.is_valid():
- save_it=form.save(commit=False)
- save_it.save()
- messages.success(request,'thanku for joining')
- return render(request,'signup.html',{'form':form})
- def SignIn(request):
- c= {}
- c.update(csrf(request))
- return render_to_response('signin.html',c)
- def auth_view(request):
- if request.method == 'POST':
- email=request.POST['email']
- password=request.POST['password']
- user=authenticate(email=email,password=password)
- if user is not None:
- login(request,user)
- return render_to_response('LoggedIn.html')
- else:
- return HttpResponse('<h1>Invalid username/password<</h1>')
- from django import forms
- from .models import signup
- class SignUpForm(forms.ModelForm):
- class Meta:
- model = signup
- widgets={
- 'password':forms.PasswordInput(),
- }
- fields='__all__'
- class SignInForm(forms.ModelForm):
- class Meta:
- model= signup
- widgets={
- 'password':forms.PasswordInput(),
- }
- fields='__all__'
- from django.db import models
- # Create your models here.
- class signup(models.Model):
- first_name=models.CharField(max_length=120,null=True,blank=True)
- last_name=models.CharField(max_length=120,null=True,blank=True)
- email=models.EmailField()
- password=models.CharField(max_length=100,default="qwerty")
- timestamp=models.DateTimeField(auto_now_add=True,auto_now=False)
- updated=models.DateTimeField(auto_now_add=False,auto_now=True)
- def __str__(self):
- return self.email
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement