def login(request): if request.method == 'POST': form = loginForm(request.POST) if form.is_valid(): form.save() username = form.cleaned_data.get('username') raw_password = form.cleaned_data.get('password1') user = authenticate(username=username, password=raw_password) login(request, user) return redirect('home') else: form = loginForm() return render(request, 'registration/login.html', {'form': form})
def login(): #we imported current user above as we want to avoid if user logged in # and retuned back to this page to be opened as if he didn't submit it if current_user.is_authenticated: return redirect(url_for('home')) form = loginForm() if form.validate_on_submit(): user = User.query.filter_by(email=form.email.data).first() #user.password as it's from db query not from the form itself like user.password.data #if condition is true we want to log user in #need to import login user function if user and bcrypt.check_password_hash(user.password, form.password.data): login_user(user, remember=form.remember.data) #args is a dictionnary but we're using get() instead of [] # next parameter which is in the URL (eg.next=%2Faccount) it tells us where the user was heading to next_page = request.args.get('next') #a ternary conditon directs us to the next page if it exists else returns us to the home return redirect(next_page) if next_page else redirect( url_for('home')) else: flash('Login Unsucessful. Please check username and password', 'danger') return render_template('login.html', title='Login', form=form)
def loginAction(request, next='index'): page_title = 'Loginform' if request.method == 'POST': form = forms.loginForm(request.POST) if form.is_valid(): data = form.cleaned_data try: user = authenticate(username=data['name'], password = data['password']) if user is not None: if user.is_active: auth_login(request, user) #print (next_page) return HttpResponseRedirect('/index') #return render_to_response('layout/index.html', {'user': user}, context_instance=RequestContext(request)) else: print ("here4") return HttpResponseRedirect('/login/form') else: form.add_error(None, "로그인 실패") return render_to_response('login_form.html', {'form': form,'page_title' : page_title}) except: form.add_error(None, "잘못된 접근입니다.") return render_to_response('login_form.html', {'form': form,'page_title' : page_title}) print ("here7") return HttpResponseRedirect('/index')
def loginUser(request): if request.method == 'POST': username = request.POST.get('username', '') password = request.POST.get('password', '') if password == '' or username == '': state = 'there is empty.Please try again' return render_to_response('error.html', {'state': state}) try: loginuser = User.objects.get(username=username) except User.DoesNotExist: raise Http404 user = authenticate(username=username, password=password) if user is not None: if user.is_active: login(request, user) return HttpResponseRedirect( reverse('personal', args=(loginuser.id, ))) else: return HttpResponseRedirect( reverse('personal', args=(loginuser.id, ))) else: state = 'not exist or password error' return render_to_response('error.html', {'state': state}) else: form = loginForm() return render_to_response('login.html', {'form': form}, context_instance=RequestContext(request))
def login(request): if request.method == 'POST': form = loginForm(request.POST) regiform = registrationForm() if form.is_valid(): email = form.cleaned_data.get('email') password = form.cleaned_data.get('password') user = authenticate(username=email, password=password) if user is not None: auth_login(request, user) request.session['username'] = email return render(request, 'blog/blog.htm', {'Name': email, 'nav': 'Nav'}) else: return render(request, 'blog/registration.htm', {'form': regiform}) else: form = loginForm() return render(request, 'blog/login.htm', {'form': form})
def login(): form = loginForm() if form.validate_on_submit(): if form.email.data == '*****@*****.**' and form.password.data == 'password': flash("Logged Successfully") return redirect(url_for('home')) else: flash('Login Unsucessfuly please check username and password', 'danger') return render_template('login.html', title='Login', form=form)
def register(request): if request.method == 'POST': form = registrationForm(request.POST) loginForm = loginForm() if form.is_valid(): email = form.cleaned_data.get('email') password = form.cleaned_data.get('password') user = User.objects.create_user( username=email, email=email, password=password) user.save() request.session['username'] = email return render(request, 'blog/login.htm', {'form': loginForm}) else: form = registrationForm() return render(request, 'blog/register.htm', {'form': form})
def post(self, request): form = loginForm(request.POST) if form.is_valid(): data = form.cleaned_data Username = data['username'] Password = data['password'] print "post" user = authenticate(username=Username, password=Password) if user is not None: print user # A backend authenticated the credentials else: print user # No backend authenticated the credentials return HttpResponseRedirect('/') return render(request, 'Blog_templates/login.html', {"form": form})
def login(): if current_user.is_authenticated: return redirect(url_for('home')) form = loginForm() if form.validate_on_submit(): user = User.query.filter_by(email=form.email.data).first() if user and bcrypt.check_password_hash(user.password, form.password.data): login_user(user, remember=form.remember.data) next_page = request.args.get('next') return redirect(next_page) if next_page else redirect( url_for('home')) else: flash('Login Unsucessful. Please check username and password', 'danger') return render_template('login.html', title='Login', form=form)
def loginUser(request): if request.method == 'POST': username = request.POST.get('username', '') password = request.POST.get('password', '') if password == '' or username == '': state = 'there is empty.Please try again' return render_to_response('error.html', {'state': state}) try: loginuser = User.objects.get(username=username) except User.DoesNotExist: raise Http404 user = authenticate(username=username, password=password) if user is not None: if user.is_active: login(request, user) return HttpResponseRedirect(reverse('personal', args=(loginuser.id,))) else: return HttpResponseRedirect(reverse('personal', args=(loginuser.id,))) else: state = 'not exist or password error' return render_to_response('error.html', {'state': state}) else: form = loginForm() return render_to_response('login.html', {'form': form}, context_instance=RequestContext(request))
def login(request): form2 = loginForm() return render(request, 'login.html', locals())
def get(self, request): form = loginForm() return render(request, 'Blog_templates/login.html', {"form": form})