def login(request): if request.user.is_authenticated(): return HttpResponseRedirect('http://localhost') best_members = member_manager(5) best_tags = tag_manager(9) tmp = request.GET.get("next", "/") if request.method == 'POST': form = LoginForm(request.POST) if form.is_valid(): my_username = request.POST.get('login', '') my_password = request.POST.get('password1', '') user = dj_authenticate(username=my_username, password=my_password) if user: auth_login(request, user) return HttpResponseRedirect('http://localhost' + tmp) else: form = LoginForm(request.POST) return render( request, 'login.html', { 'members': best_members, 'best_tags': best_tags, 'user': request.user, 'temp': tmp, 'form': form })
def login(request): if request.user.is_authenticated(): return redirect('new-questions') top_tags = get_popular_tags() best_members = get_best_members() cont = request.GET.get('next', 'new-questions') if request.method == 'POST': form = LoginForm(request.POST) user = auth.authenticate(username=request.POST['login'], password=request.POST['password']) if user is not None: auth.login(request, user) return redirect(cont) else: form.add_error(None, "Incorrect login/password") else: form = LoginForm() context = { 'top_tags': top_tags, 'best_members': best_members, 'form': form, } return render(request, 'login.html', context)
def login_me(request): tbags = Tag.objects.all() error_message = '' form = LoginForm() if request.method == 'POST': form = LoginForm(request.POST) if form.is_valid(): username = request.POST['usernameField'] password = request.POST['passwordField'] user = authenticate(username=username, password=password) if user is not None: login(request, user) return redirect('ask') else: error_message = 'User is not found' else: error_message = 'Form\'s not valid' context = { 'tags': tbags, 'error_message': error_message, 'form': form, 'user': request.user, } context.update(csrf(request)) return render_to_response('login.html', context)
def loginator(request): if (request.method == 'POST'): form = LoginForm(request.POST) if form.is_valid(): user = authenticate(username=form.cleaned_data['name'], password=form.cleaned_data['password']) else: newDict = defaultDict newDict["stat"] = "badData" newDict["curUser"] = request.user return render(request, "login.html", newDict) if user is not None: if not user.is_active: newDict = defaultDict newDict["stat"] = "unactive" newDict["curUser"] = request.user return render(request, "login.html", newDict) else: login(request, user) return redirect('/user/' + user.username) else: newDict = defaultDict newDict["stat"] = "badData" newDict["curUser"] = request.user return render(request, "login.html", newDict) else: if (request.user.is_authenticated): newDict = defaultDict newDict["curUser"] = request.user return render(request, "login.html", newDict)
def loginSite(request, *args, **kwargs): if request.method == "POST": form = LoginForm(request.POST) if form.is_valid(): user = form.save() login(request, user) return HttpResponseRedirect("/") else: form = LoginForm() return render(request, 'login.html', {'form': form})
def signin(request): error = '' if request.method == 'POST': form = LoginForm(request.POST) if form.is_valid(): user = authenticate(request, username=form.cleaned_data['username'], password=form.cleaned_data['password']) if user is not None: login(request, user) return HttpResponseRedirect(form.cleaned_data['url']) else: error = u'Неверный логин\пароль' else: if request.GET.get('next'): form = LoginForm(initial={'url': request.GET.get('next')}) else: form = LoginForm(initial={'url': '/'}) context = { 'form': form, 'error': error, } return render(request, 'login.html', context)
def login(request): if not request.user.is_authenticated(): login_form = LoginForm(request.POST) if login_form.is_valid(): username = login_form.cleaned_data["username"] password = login_form.cleaned_data["password"] user = auth.authenticate(username=username, password=password) if user is not None and user.is_active: auth.login(request, user) request.session["message"] = "Successful authorization!!" request.session["flag"] = 1 else: request.session["message"] = "Wrong login or password!!" request.session["flag"] = 0 else: request.session["message"] = "You are already login!!" request.session["flag"] = 0 return HttpResponseRedirect(reverse("questions"))
def login(request): if request.user.is_authenticated(): return HttpResponseRedirect('http://localhost') best_members = member_manager(5) best_tags = tag_manager(9) tmp = request.GET.get("next","/") if request.method == 'POST': form = LoginForm(request.POST) if form.is_valid(): my_username = request.POST.get('login', '') my_password = request.POST.get('password1', '') user = dj_authenticate(username = my_username, password = my_password) if user: auth_login(request, user) return HttpResponseRedirect('http://localhost'+tmp) else: form = LoginForm(request.POST) return render(request, 'login.html', { 'members': best_members, 'best_tags': best_tags,'user':request.user, 'temp': tmp, 'form': form })
def login(request): redirect = request.GET.get('continue', '/') if request.user.is_authenticated(): request.session['img'] = Profile.objects.filter( user_id=request.user.id)[0].get_avatar() print(connection.queries) return HttpResponseRedirect(redirect) if request.method == "POST": form = LoginForm(request.POST) if form.is_valid(): auth.login(request, form.cleaned_data['user']) request.session['img'] = Profile.objects.filter( user_id=request.user.id)[0].get_avatar() print(connection.queries) return HttpResponseRedirect(redirect) else: #request.img = None form = LoginForm() context = {"form": form} print(connection.queries) return render(request, 'login.html', context)
def login(request): if request.method == "POST": form = LoginForm(request.POST) if form.is_valid(): user = form.save() log_in(request, user) return HttpResponseRedirect("/") else: form = LoginForm() return render(request, 'ask/login.html', {'form': form, 'username': request.user.username})
# Create your views here. from django.template import loader, Context from django.http import HttpResponse, HttpResponseRedirect from django.shortcuts import render, redirect from django.core.paginator import Paginator from ask.models import User, Question, Answer, Comments, Tag, UserTokens, Rates, Notifications from django.contrib.auth import authenticate, login, logout from ask.forms import LoginForm, RegistrationForm, NewQuestionForm, NewAnswerForm, SearchForm, NewCommentForm, ActivationForm from django.core.mail import send_mail from ask.methods import generateToken, popularTags, lastUsers, countRating, sortQuest, mailNotify, lastNotifs from django.utils import simplejson defaultDict = { "newQuestionForm": NewQuestionForm(), "loginForm": LoginForm(), "searchForm": SearchForm(), "tags": popularTags(5), "lastUsers": lastUsers(5), } mimetype = 'application/json' QuestionConTypeID = 10 AnswerConTypeID = 12 def index(request): newDict = defaultDict newDict["curUser"] = request.user return render(request, "index.html", newDict)