from django.shortcuts import render, redirect

from models import *

# Create your views here.

def index(req):
	return render(req, "landing.html", {'request': req})

def login(req):
	return render(req, "login.html", {'request': req})

def register(req):
	if req.method == 'POST':
		try:
			user = User(email = req.POST['email'])
			user.set_password(req.POST['password'])
			req.session['email'] = req.POST['email']
			return redirect("/")
		except:
			# I'm kind of lazy
			pass
	return render(req, "register.html", {'request': req})

def logout(req):
	del req.session['email']
	return redirect("/")

from django.shortcuts import render, redirect

from models import *

# Create your views here.

def index(req):
	return render(req, "landing.html", {'request': req})

def login(req):
	if req.method == 'POST':
		try:
			user = User.objects.get(email = req.POST['email'])
			if user.check_password(req.POST['password']):
				req.session['email'] = req.POST['email']
				return redirect("/")
		except:
			pass
	return render(req, "login.html", {'request': req})

def register(req):
	if req.method == 'POST':
		try:
			user = User(email = req.POST['email'])
			user.set_password(req.POST['password'])
			user.save()
			req.session['email'] = req.POST['email']
			return redirect("/")
		except:
			# I'm kind of lazy
			pass
	return render(req, "register.html", {'request': req})

def logout(req):
	del req.session['email']
	return redirect("/")

Add save for registration & login logic
Add save for registration & login logic

  from django.shortcuts import render, redirect
  
  from models import *
  
  # Create your views here.
  
  def index(req):
  	return render(req, "landing.html", {'request': req})
  
  def login(req):
+ 	if req.method == 'POST':
+ 		try:
+ 			user = User.objects.get(email = req.POST['email'])
+ 			if user.check_password(req.POST['password']):
+ 				req.session['email'] = req.POST['email']
+ 				return redirect("/")
+ 		except:
+ 			pass
  	return render(req, "login.html", {'request': req})
  
  def register(req):
  	if req.method == 'POST':
  		try:
  			user = User(email = req.POST['email'])
  			user.set_password(req.POST['password'])
+ 			user.save()
  			req.session['email'] = req.POST['email']
  			return redirect("/")
  		except:
  			# I'm kind of lazy
  			pass
  	return render(req, "register.html", {'request': req})
  
  def logout(req):
  	del req.session['email']
  	return redirect("/")
  
Add save for registration & login logic
## Code Before:
from django.shortcuts import render, redirect

from models import *

# Create your views here.

def index(req):
	return render(req, "landing.html", {'request': req})

def login(req):
	return render(req, "login.html", {'request': req})

def register(req):
	if req.method == 'POST':
		try:
			user = User(email = req.POST['email'])
			user.set_password(req.POST['password'])
			req.session['email'] = req.POST['email']
			return redirect("/")
		except:
			# I'm kind of lazy
			pass
	return render(req, "register.html", {'request': req})

def logout(req):
	del req.session['email']
	return redirect("/")

## Instruction:
Add save for registration & login logic
## Code After:
from django.shortcuts import render, redirect

from models import *

# Create your views here.

def index(req):
	return render(req, "landing.html", {'request': req})

def login(req):
	if req.method == 'POST':
		try:
			user = User.objects.get(email = req.POST['email'])
			if user.check_password(req.POST['password']):
				req.session['email'] = req.POST['email']
				return redirect("/")
		except:
			pass
	return render(req, "login.html", {'request': req})

def register(req):
	if req.method == 'POST':
		try:
			user = User(email = req.POST['email'])
			user.set_password(req.POST['password'])
			user.save()
			req.session['email'] = req.POST['email']
			return redirect("/")
		except:
			# I'm kind of lazy
			pass
	return render(req, "register.html", {'request': req})

def logout(req):
	del req.session['email']
	return redirect("/")
