def post(self, request): login_form = LoginForm(request.POST) if not login_form.is_valid(): return render(request, self.template_name, {"form": login_form}) login = login_form.cleaned_data['username'] conn = cx_Oracle.connect(dbset.URL) cursor = conn.cursor() cursor.execute("SELECT api.get_user_id('{}') FROM DUAL".format(login)) id = cursor.fetchone()[0] cursor.execute("SELECT api.is_admin('{}') FROM DUAL".format(login)) is_admin = cursor.fetchone()[0] cursor.close() conn.close() request.session['user_id'] = id request.session['is_admin'] = is_admin request.session['username'] = login return redirect(self.success_url)
def get_main_page(request): """pokaż stronę główną z formularzem logowania""" if 'user_id' in request.session: return HttpResponseRedirect("/me") if request.method == 'POST': form = LoginForm(request.POST) if form.is_valid(): # do sprawdzania czy zalogowany request.session['user_id'] = form.cleaned_data['id'] request.session['user_name'] = form.cleaned_data['name'] # login return HttpResponseRedirect("/me") else: form = LoginForm() # jak formularz niepoprawny to go też zwraca, bo tam jest wyjęty, i dane # są wpisane jakie były! return render(request, 'main_page.html', {'form': form})