def login(request): from forms import AdminLoginForm if request.method == 'POST': post = request.POST.copy() admin_form = AdminLoginForm(post) if admin_form.is_valid(): usuario = auth.authenticate(username=post['usuario'], password=post['password']) if usuario is not None: if usuario.is_staff(): auth.login(request, usuario) else: admin_form = AdminLoginForm() return 'admin.html', { 'admin': admin_form }
def admin_login(request): if request.method == 'POST': form = AdminLoginForm(request.POST) if form.is_valid(): data = form.cleaned_data username = data["id"] password = data["password"] user = authenticate(username=username, password=password) if user is not None: login(request, user) return HttpResponseRedirect(reverse("admin")) form = AdminLoginForm() return render(request, "scanner/admin_login.html", {"form": form})
def admin(request): unconfirmedSongVideos = Video.objects.filter( is_confirmed__exact=False ).prefetch_related( 'songs', 'songs__composers', 'songs__styles', 'groups' ).order_by('title') formattedUnconfirmedVideos = [] for video in unconfirmedSongVideos : formattedUnconfirmedVideos.append(formattedVideoData(video)) response = render( request, 'unconfirmed-list.html', {"data": json.dumps({ "unconfirmed_songs": { "videos" : { "items" : formattedUnconfirmedVideos, "metadata" : rekeyAndFormatVideoData(unconfirmedSongVideos), }, }, })} ) if request.COOKIES.get(ADMIN_COOKIE, False): return response elif request.method == 'POST': form = AdminLoginForm(request.POST) if form.is_valid(): if form.cleaned_data['password'] == ADMIN_PASSWORD: response.set_cookie( key=ADMIN_COOKIE, value=True, max_age=ADMIN_COOKIE_EXPIRE ) return response else: form = AdminLoginForm() return render(request, 'admin-login.html', {'form': form})