# Path: User/models.py
# def start_user_session(request, user_id, user_class):
# 	if request.session is not None:
# 		request.session["user_mail_id"] = user_id
# 		request.session["user_class"] = user_class
# 	return request
# 
# def check_if_auth_user(request):
# 	if (request.session is not None) and request.session.has_key("user_mail_id"):
# 		return request.session["user_mail_id"]
# 	else:
# 		return None
# 
# def stop_user_session(request):
# 	if (request.session is not None) and request.session.has_key("user_mail_id"):
# 		del request.session["user_mail_id"]
# 		del request.session["user_class"]
# 		return True
# 	return False


from django.shortcuts import render, redirect, get_object_or_404
from django.http import HttpResponse
from django.contrib import messages
from django.db import connection, transaction
from passlib.hash import bcrypt
from .models import start_user_session, check_if_auth_user, stop_user_session
from collections import namedtuple
import datetime
import re
			query = "INSERT INTO location_location ('city', 'state') Values(%s, %s)"
			cursor.execute(query, [city, state])
			transaction.commit()

			query = "SELECT loc_id FROM location_location WHERE `location_location`.city = %s and `location_location`.state = %s"
			cursor.execute(query, [city, state])
			result = namedtuplefetchall(cursor)
			loc_id = result[0].loc_id

		if category == 'Expert':
			query = "INSERT INTO User_expert('name', 'user_id', 'user_pwd', 'contact', 'location_id', 'join_timestamp') Values(%s, %s, %s, %s, %s, %s)"
		else:
			query = "INSERT INTO User_farmer('name', 'user_id', 'user_pwd', 'contact', 'location_id', 'join_timestamp') Values(%s, %s, %s, %s, %s, %s)"
		
		try:
			cursor.execute(query, [name, email, pwd, con, loc_id, datetime.datetime.now()])
		except:
			messages.error(request, "Entered mail ID is already registered.")
			return redirect("user:signup")

		transaction.commit()
		
		messages.success(request, "Sign up was successful")
		messages.success(request, "Now you may login")

		return redirect("home:welcome")
	
	return render(request, "signup.html", {})

def logout_user(request):

# Path: User/models.py
# def start_user_session(request, user_id, user_class):
# 	if request.session is not None:
# 		request.session["user_mail_id"] = user_id
# 		request.session["user_class"] = user_class
# 	return request
# 
# def check_if_auth_user(request):
# 	if (request.session is not None) and request.session.has_key("user_mail_id"):
# 		return request.session["user_mail_id"]
# 	else:
# 		return None
# 
# def stop_user_session(request):
# 	if (request.session is not None) and request.session.has_key("user_mail_id"):
# 		del request.session["user_mail_id"]
# 		del request.session["user_class"]
# 		return True
# 	return False


# Path: User/views.py
from django.shortcuts import render, redirect, get_object_or_404
from django.http import HttpResponse
from django.contrib import messages
from django.db import connection, transaction
from passlib.hash import bcrypt
from .models import start_user_session, check_if_auth_user, stop_user_session
from collections import namedtuple
import datetime
import re

			query = "INSERT INTO location_location ('city', 'state') Values(%s, %s)"
			cursor.execute(query, [city, state])
			transaction.commit()

			query = "SELECT loc_id FROM location_location WHERE `location_location`.city = %s and `location_location`.state = %s"
			cursor.execute(query, [city, state])
			result = namedtuplefetchall(cursor)
			loc_id = result[0].loc_id

		if category == 'Expert':
			query = "INSERT INTO User_expert('name', 'user_id', 'user_pwd', 'contact', 'location_id', 'join_timestamp') Values(%s, %s, %s, %s, %s, %s)"
		else:
			query = "INSERT INTO User_farmer('name', 'user_id', 'user_pwd', 'contact', 'location_id', 'join_timestamp') Values(%s, %s, %s, %s, %s, %s)"
		
		try:
			cursor.execute(query, [name, email, pwd, con, loc_id, datetime.datetime.now()])
		except:
			messages.error(request, "Entered mail ID is already registered.")
			return redirect("user:signup")

		transaction.commit()
		
		messages.success(request, "Sign up was successful")
		messages.success(request, "Now you may login")

		return redirect("home:welcome")
	
	return render(request, "signup.html", {})

def logout_user(request):

	if stop_user_session(request):