Commit 1d1bdfec by Joel Marpaung

no message

parent aa0723c9
from django.contrib import admin
# Register your models here.
from django.apps import AppConfig
class HomepageConfig(AppConfig):
name = 'homepage'
from django.db import models
# Create your models here.
from django.test import TestCase
# Create your tests here.
from django.shortcuts import render, redirect
from django.http import HttpResponse,HttpResponseRedirect
from django.contrib.auth.decorators import login_required
from django.contrib.auth import authenticate
from django.contrib.auth import logout as auth_logout
from django.contrib.auth import login as auth_login
from django.core.urlresolvers import reverse
from django.conf import settings
# from django.contrib.auth.hashers import make_password
from django.contrib.auth.models import User
from farmer.models import *
# Create your views here.
def register(request):
if request.method == 'POST':
user = User(
username = request.POST['username'],
)
user.set_password(request.POST['password'],)
user.save()
farmer = Pengguna(
username = request.POST['username'],
full_name = request.POST['full_name'],
phone = request.POST['phone'],
email = request.POST['email'],
provinsi = request.POST['provinsi'],
kabupaten = request.POST['kabupaten'],
kecamatan = request.POST['kecamatan'],
alamat = request.POST['alamat'],
photo = request.FILES['photo'],
)
farmer.save()
account = Akun(
akun = User.objects.get(username=request.POST['username']),
pengguna = Pengguna.objects.get(username=request.POST['username']),
akun_id = User.objects.get(username=request.POST['username']).id,
pengguna_id = Pengguna.objects.get(username=request.POST['username']).id,
jenis_akun = "farmer",
)
account.save()
return redirect('/login')
else:
return render(request,'homepage/register.html')
def login(request):
if request.POST:
username = request.POST.get('username')
password = request.POST.get('password')
user = authenticate(username=username, password=password)
if user is not None:
if user.is_active:
akun = Akun.objects.get(akun_id=user.id)
auth_login(request, user)
request.session['pengguna_id'] = akun.pengguna.id
request.session['username'] = request.POST['username']
return redirect('/')
else:
print("Account Not Active")
else:
print("Account Not Active")
else:
return render(request,'homepage/login.html')
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment