Fakultas Ilmu Komputer UI

Commit 35876ca5 authored by Muhammad Athaqil Makarim's avatar Muhammad Athaqil Makarim
Browse files

URL Homepage Fix

parent 3a35aa0d
Pipeline #138325 passed with stages
in 2 minutes and 38 seconds
# from django.contrib.auth import authenticate, login, get_user_model, logout
# from django.views.generic import CreateView, FormView
# from django.http import HttpResponse, JsonResponse
# from django.shortcuts import render,redirect
# from django.utils.http import is_safe_url
# from .serializers import UserSerializer
# from rest_framework.views import APIView
# from rest_framework.response import Response
# from rest_framework import status
# from rest_framework.permissions import IsAdminUser
# from django.contrib.auth.models import *
# from .models import Account
# # import requests
# from homepage.forms import LoginForm, RegisterForm
# class UserRecordView(APIView):
# """
# API View to create or get a list of all the registered
# users. GET request returns the registered users whereas
# a POST request allows to create a new user.
# """
# permission_classes = [IsAdminUser]
# http_method_names = ['get', 'head', 'post']
# def get(self, request, *args, **kwargs):
# serializer = UserSerializer(Account.objects.all(), many=True)
# return Response(serializer.data, status = status.HTTP_200_OK)
# def post(self, request, *args, **kwargs):
# self.http_method_names.append("GET")
# serializer = UserSerializer(data=request.data)
# if serializer.is_valid(raise_exception=ValueError):
# serializer.create(validated_data=request.data)
# return Response(
# serializer.data,
# status=status.HTTP_201_CREATED
# )
# return Response(
# {
# "error": True,
# "error_msg": serializer.error_messages,
# },
# status=status.HTTP_400_BAD_REQUEST
# )
# class LoginView(FormView):
# form_class = LoginForm
# success_url = '/homepage/'
# template_name = 'login.html'
# def form_valid(self, form):
# request = self.request
# next_ = request.GET.get('next')
# next_post = request.POST.get('next')
# redirect_path = next_ or next_post or None
# email = form.cleaned_data.get("email")
# password = form.cleaned_data.get("password")
# user = authenticate(request, username=email, password=password)
# if user is not None:
# login(request, user)
# try:
# del request.session['guest_email_id']
# except:
# pass
# if is_safe_url(redirect_path, request.get_host()):
# return redirect(redirect_path)
# else:
# return redirect("/homepage/")
# return super(LoginView, self).form_invalid(form)
# class RegisterView(CreateView):
# form_class = RegisterForm
# template_name = 'registration.html'
# success_url ='/homepage/'
# def homepage(request):
# return render(request, 'homepage.html')
# def logout_request(request):
# logout(request)
# return redirect("/homepage/")
# def homepage(request):
# data = requests.get("https://apicovid19indonesia-v2.vercel.app/api/indonesia")
# data_json = data.json()
# context = {'data':data_json[0]}
# return render(request, "homepage.html", context)
# def covid_api(request):
# data = requests.get("https://apicovid19indonesia-v2.vercel.app/api/indonesia")
# data_json = data.json()
# return JsonResponse(data_json, safe = False)
from django.shortcuts import render, redirect
from django.views.generic import CreateView
from .models import User
......@@ -117,7 +22,7 @@ def login_request(request):
user = authenticate(username=username, password=password)
if user is not None :
login(request,user)
return redirect('/homepage/')
return redirect('/')
else:
messages.error(request,"Invalid username or password")
else:
......@@ -127,16 +32,16 @@ def login_request(request):
def logout_request(request):
logout(request)
return redirect("/homepage/")
return redirect("/")
class customer_register(CreateView):
model = User
form_class = CustomerSignUpForm
template_name = 'customer_register.html'
success_url = '/homepage/'
success_url = '/'
class developer_register(CreateView):
model = User
form_class = DeveloperSignUpForm
template_name = 'developer_register.html'
success_url = '/homepage/'
success_url = '/'
Supports Markdown
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