def register(request): email = ' ' if request.method == 'POST': print('Post request sent.') form = LoginForm(request.POST) if form.is_valid(): print('Form is valid.') email = form.cleaned_data['email'] password = request.POST.get('password', None) first_name = request.POST.get('first_name') last_name = request.POST.get('last_name') username = request.POST.get('username') createUser(username, email, password, first_name, last_name) print(email) else: print(form.errors) args = { 'form': form, 'email': email, 'username': username, 'password': password, 'first_name': first_name, 'last_name': last_name } return render(request, 'subjects_user.html', args) else: form = LoginForm() if form.is_valid(): email = form.cleaned_data['email'] print(email) return render(request, 'register_page.html', { 'form': form, 'email': email })
def login(request): """ Handles the login action. """ form = LoginForm(None, data=request.POST) if form.is_valid(): auth_login(request, form.get_user()) return JsonResponse(data={'redirect_to': reverse('webapp.pages.user_profile', args=(request.user.id, ))}) return JsonResponse(errors=form.errors)
def sign_in(request): if (request.method == 'POST'): form_login = LoginForm(request.POST) if (form_login.is_valid()): username = form_login.cleaned_data['username'] password = form_login.cleaned_data['password'] user = authenticate(request, username=username, password=password) if user is not None: login(request, user) return redirect('/wizard/')
def login_view(request): # Check if the user is already authenticated if not request.user.is_authenticated: # If a login is attempted if request.method == "POST": form = LoginForm(data=request.POST) # Check if the data entered in the form is valid if form.is_valid(): # Get email and password email = form.cleaned_data['email'] password = form.cleaned_data['password'] # Try to authenticate user user = authenticate(request, username=email, password=password) # If the credentials exist and are correct if user is not None: # Check whether the user is an admin or the superuser user_check = User.objects.get(email=email) if user_check.is_staff or user_check.is_superuser: # Login user and return template with success message auth_login(request, user) return render(request, 'webapp/authentication/login.html', {'success': True}) # Otherwise, show error message else: return render(request, 'webapp/authentication/login.html', {'not_admin': True}) # If the login is not valid, show the login form again else: form = LoginForm() return render(request, 'webapp/authentication/login.html', {'form': form}) # If the data is not valid, show the form again else: form = LoginForm() return render(request, 'webapp/authentication/login.html', {'form': form}) # If there is no POST data, show the form else: form = LoginForm() return render(request, 'webapp/authentication/login.html', {'form': form}) # User already authenticated else: return redirect('index')
def login(request): """ Handles the login action. """ form = LoginForm(None, data=request.POST) if form.is_valid(): auth_login(request, form.get_user()) return JsonResponse( data={'redirect_to': reverse('webapp.pages.my_flights')}) return JsonResponse(errors=form.errors)
def login(request): '''Login page.''' lang = settings.LANGUAGE_CODE if request.method == 'POST': form = LoginForm(request.POST) if form.is_valid(): login = form.cleaned_data['login'] pwd = form.cleaned_data['password'] user = auth.authenticate( username=login, password=pwd) # print(user) if user and user.is_active: auth.login(request, user) try: lang = user.i18nuser.lang.lower() except ObjectDoesNotExist: pass request.session['django_language'] = lang return HttpResponseRedirect('/') else: request.session['django_language'] = lang translation.activate(lang) form = LoginForm() return render(request, 'webapp/login.html', { 'form': form, })
def login_user(request): if request.method == "POST": form = LoginForm(request.POST) if form.is_valid(): cd = form.cleaned_data user = authenticate(request, username=cd['username'], password=cd['password']) if user is not None: login(request, user) return HttpResponse('Authentication was successful') else: return HttpResponse('Authentication failed') else: form = LoginForm() return render(request, 'login.html', {'form': form})
def login(request): '''Login page.''' lang = settings.LANGUAGE_CODE if request.method == 'POST': form = LoginForm(request.POST) if form.is_valid(): login = form.cleaned_data['login'] pwd = form.cleaned_data['password'] user = auth.authenticate(username=login, password=pwd) # print(user) if user and user.is_active: auth.login(request, user) try: lang = user.i18nuser.lang.lower() except ObjectDoesNotExist: pass request.session['django_language'] = lang return HttpResponseRedirect('/') else: request.session['django_language'] = lang translation.activate(lang) form = LoginForm() return render(request, 'webapp/login.html', { 'form': form, })
def Login_View(request): if request.method == "POST": lform = LoginForm(request.POST) if lform.is_valid(): uname = request.POST.get('user_name') pwd = request.POST.get('password') user = RegistrationData.objects.filter(user_name=uname) password = RegistrationData.objects.filter(password=pwd) if user and password: return redirect('/home_page/') # return HttpResponse("Success") else: return HttpResponse("Fail") else: return HttpResponse('User Invalid Data') else: lform = LoginForm() return render(request, 'movie_htmlfiles/logindata.html', {'lform': lform})