def login_2(request): """ """ logged_user = user_form(request) if logged_user: return redirect('/accueil') form = LoginForm(data=request.POST or None) if form.is_valid(): user_pseudo = form.cleaned_data['pseudo'] user_password = form.cleaned_data['password'] user = authenticate(request, username=user_pseudo, password=user_password) if user: if user.is_active: logi(request, user) #request.session.set_expiry(0) url = request.META['HTTP_REFERER'].split('=') if len(url) == 2: return redirect(url[1]) return redirect('/accueil') return render(request, 'login.html', { 'form': form, 'info': "Identifiant et/ou mot de passe incorrecte." }) return render(request, 'login.html', {'form': form})
def login_view(request): if request.method == 'POST': next_url = request.POST.get('next', 'index') form = LoginForm(request.POST) if form.is_valid(): username = get_user(form.cleaned_data.get('email')) if not username: return render(request, 'auth/login.html', { 'form': form, 'error': _("User not found") }) _user = authenticate(username=username, password=form.cleaned_data.get('password')) if _user is not None: if _user.is_active: login(request, _user) return redirect(next_url) return render(request, 'auth/login.html', { 'form': form, 'error': _("Account Disabled") }) return render(request, 'auth/login.html', { 'form': form, 'error': _("Invalid login credentials") }) return render(request, 'auth/login.html', {'form': form}) # form errors form = LoginForm() return render(request, 'auth/login.html', {'form': form})
def login_crm(request): if request.user.is_authenticated: return HttpResponseRedirect('/') if request.method == 'POST': form = LoginForm(request.POST, request=request) if form.is_valid(): user = authenticate(username=request.POST.get('email'), password=request.POST.get('password')) if user is not None: if user.is_active: login(request, user) return HttpResponseRedirect('/') else: return render(request, "login.html", { "error": True, "inactiveuser": form.errors }) else: return render(request, "login.html", { "error": True, "usernone": form.errors }) else: return render(request, "login.html", { "error": True, "errors": form.errors }) return render(request, 'login.html')
def post(self, request, *args, **kwargs): form = LoginForm(request.POST, request=request) if form.is_valid(): user = authenticate(username=request.POST.get('email'), password=request.POST.get('password')) if user is not None: if user.is_active: login(request, user) return HttpResponseRedirect('/') else: return render( request, "login.html", { "error": True, "message": "Your Account is InActive. Please Contact Administrator" }) else: return render( request, "login.html", { "error": True, "message": "Your Account is not Found. Please Contact Administrator" }) else: return render( request, "login.html", { "error": True, "message": "Your username and password didn't match. Please try again." })
def login(request): if request.method == 'GET': return render(request, 'common/login.html') if request.method == 'POST': form = LoginForm(request.POST) if form.is_valid() and form.errors == {}: user = User.objects.filter( phone=form.cleaned_data.get('mobile')).first() request.session['user_id'] = user.id return HttpResponseRedirect(reverse('common:checked_index')) errors = form.errors return render(request, 'common/login.html', {'errors': errors})
def post(self, request): form = LoginForm(data=request.POST) if form.is_valid(): user = authenticate( request, username=form.cleaned_data["username"], password=form.cleaned_data["password"], ) if user: login(request, user) return HttpResponseRedirect(reverse("success")) return render(request, "login_page.html", {"login_form": form})
def post(self, request, *args, **kwargs): form = LoginForm(request.POST, request=request) if form.is_valid(): user = User.objects.filter(email=request.POST.get('email')).first() # user = authenticate(username=request.POST.get('email'), password=request.POST.get('password')) if user is not None: if user.is_active: user = authenticate(username=request.POST.get( 'email'), password=request.POST.get('password')) if user is not None: login(request, user) if user.has_sales_access: return HttpResponseRedirect('/') elif user.has_marketing_access: return redirect('marketing:dashboard') else: return HttpResponseRedirect('/') return render(request, "login.html", { "ENABLE_GOOGLE_LOGIN": settings.ENABLE_GOOGLE_LOGIN, "GP_CLIENT_SECRET": settings.GP_CLIENT_SECRET, "GP_CLIENT_ID": settings.GP_CLIENT_ID, "error": True, "message": "Your username and password didn't match. \ Please try again." }) return render(request, "login.html", { "ENABLE_GOOGLE_LOGIN": settings.ENABLE_GOOGLE_LOGIN, "GP_CLIENT_SECRET": settings.GP_CLIENT_SECRET, "GP_CLIENT_ID": settings.GP_CLIENT_ID, "error": True, "message": "Your Account is inactive. Please Contact Administrator" }) return render(request, "login.html", { "ENABLE_GOOGLE_LOGIN": settings.ENABLE_GOOGLE_LOGIN, "GP_CLIENT_SECRET": settings.GP_CLIENT_SECRET, "GP_CLIENT_ID": settings.GP_CLIENT_ID, "error": True, "message": "Your Account is not Found. Please Contact Administrator" }) return render(request, "login.html", { "ENABLE_GOOGLE_LOGIN": settings.ENABLE_GOOGLE_LOGIN, "GP_CLIENT_SECRET": settings.GP_CLIENT_SECRET, "GP_CLIENT_ID": settings.GP_CLIENT_ID, # "error": True, # "message": "Your username and password didn't match. Please try again." "form": form })
def get_blog_detail_by_id(request, blog_id): context = {} blog = get_object_or_404(Blog, id=blog_id) key = read_count_plus_one(request, blog) pre_blog = Blog.objects.filter(created_time__gt=blog.created_time).last() next_blog = Blog.objects.filter(created_time__lt=blog.created_time).first() blogTypes, blog_created_date = common_context() Blog_Class = ContentType.objects.get_for_model(blog) # comments=CommentRecord.objects.filter(content_type=Blog_Class,object_id=blog_id,parent=None)#root=None #博客相关内容 context['blog'] = blog #上下篇 context['next_blog'] = next_blog context['pre_blog'] = pre_blog #右侧栏内容 context['blogTypes'] = blogTypes context['blog_created_date'] = blog_created_date #评论表单 转移到comment-tag中了 # comment_form=CommentForm(initial={'contenttype':'blog','object_id':blog.id,'comment_be_replied_id':'0'}) # context['form']=comment_form #评论内容 # context['comments']=comments.order_by('-comment_time') context['comment_count'] = CommentRecord.objects.filter( content_type=Blog_Class, object_id=blog.id).count() #模态框登陆表单 context['form'] = LoginForm() response = render(request, 'get_blog_detail.html', context) response.set_cookie(key, 'true') return response
def index(request): title = "Lectures" user = request.user sponslectures = Lecture.objects.filter(accepted=True, person_type=0).order_by('order') lectures = Lecture.objects.filter(accepted=True, person_type__gte=1).order_by( 'person_type', 'order') lectures_null = Lecture.objects.filter(accepted=True, person_type__gte=1).order_by( 'person_type', 'order') if request.user.is_authenticated(): my_lectures = Lecture.objects.filter(author=request.user) workshops = Lecture.objects.filter(accepted=True, person_type__gte=1, type=1).order_by( 'person_type', 'order') if is_lecture_suggesting_enabled(): login_form = LoginForm() if user.is_authenticated() and user.is_active: lecture_proposition_form = LectureForm(request.POST or None) if lecture_proposition_form.is_valid(): lecture = lecture_proposition_form.save(commit=False) lecture.author = request.user lecture.save() messages = [_("thankyou")] lecture_proposition_form = LectureForm() return render_to_response('lectures.html', locals())
def manager_login(request): if request.method == "POST": form = LoginForm(request.POST) if form.is_valid(): username = form.cleaned_data["username"] password = form.cleaned_data["password"] user = authenticate(username=username, password=password) if user is not None: if user.appuser.account_type == AppUsers.MANAGER: login(request, user) # Redirect to manager subdomain return redirect("http://manager.osmith.me") else: return render(request, "login_error.html", {"form": form, "account_type": "manager", "error_message": "domain_error"}) else: form = LoginForm() return render(request, "login_error.html", {"form": form, "account_type": "manager", "error_message": "incorrect"}) else: return render(request, "login_error.html", {"form": form, "account_type": "manager", "error_message": "invalid"}) else: form = LoginForm() return render(request, "login.html", {"form": form, "account_type": "manager"})
def login(): print("进来登录了") form = LoginForm() if form.validate_on_submit(): print("进来这个函数了") user_name = request.form.get('username', None) password = request.form.get('password', None) remember_me = request.form.get('remember_me', False) print(user_name,password) user = User(user_name) if user.verify_password(password): print("进来储存用户啦") print(user.username,user.id) login_user(user, remember=remember_me) print("zheyibu") return redirect(url_for('main')) flash(u"用户名或密码错误!") return render_template('login.html', title="Sign In", form=form)
def post(self, request, *args, **kwargs): form = LoginForm(request.POST) if form.is_valid(): username = form.cleaned_data['username'] password = form.cleaned_data['password'] try: user = authenticate(username=username, password=password) except PermissionDenied as p: print(p) if user: login(request, user) nextUrl = getNextUrl(request) return HttpResponseRedirect(nextUrl) else: logger.debug('UnAuthorized user...') return self.render_form_with_error(request, form, 'login failed')
def connexion(request): erreur = False if request.method == "POST": form = LoginForm(request.POST) if form.is_valid(): username = form.cleaned_data["username"] password = form.cleaned_data["password"] user = authenticate(username=username, password=password) if user: login(request, user) next_url = request.POST['next'] or '/' return redirect(next_url) else: erreur = True else: next_url = request.GET.get('next', '') form = LoginForm() return render(request, "common/login.html", locals())
def post(self, request, *args, **kwargs): url = request.GET.get("next") login_form = LoginForm(request.POST) if login_form.is_valid(): username = request.POST["username"] password = request.POST["password"] user = auth.authenticate(username=username, password=password) if user is not None and user.is_active: auth.login(request, user) return HttpResponsePermanentRedirect(request.GET.get("next")) else: self.context = { "login_form": login_form, "password_is_wrong": True } return render(request, "common/login.html", self.context) else: self.context = { "login_form": login_form, "errors": login_form.errors } return render(request, "common/login.html", self.context)
def index(request): user = request.user blog_posts = BlogPost.objects.order_by('-pub_date') user = request.user title = "Blog" login_form = LoginForm() try: definition = ZosiaDefinition.objects.get(active_definition=True) except Exception: raise Http404('No active definitions.') return TemplateResponse(request, 'blog.html', locals())
def login(request): if request.session.get('is_login', None): return redirect(reverse('index')) if request.method == "POST": login_form = LoginForm(request.POST) if login_form.is_valid(): username = login_form.cleaned_data['username'] password = login_form.cleaned_data['password'] try: user = models.User.objects.get(username=username) if user.password == hash_code(password): # 哈希值和数据库内的值进行比对 request.session['is_login'] = True request.session['user_id'] = user.id request.session['user_name'] = user.name request.session['user_role'] = user.role return redirect(reverse('index')) else: messages.add_message(request, messages.WARNING, '密码不正确') except User.DoesNotExist: messages.add_message(request, messages.WARNING, '用户不存在') return render(request, 'login.html', locals()) login_form = LoginForm() return render(request, 'login.html', locals())
def index(request): """ """ logged_user = user_form(request) images_carousel = Carousel.objects.all() if logged_user: return render(request, 'index.html', { 'user': logged_user, 'images_carousel': images_carousel }) else: form = LoginForm() return render(request, 'index.html', { 'form': form, 'images_carousel': images_carousel })
def login_page(request): form = LoginForm() if request.method == 'POST': username = request.POST.get('username', None) password = request.POST.get('password', None) next_url = request.POST.get('next', None) # Check if all required information supplied or not if not username or not password: return render(request, 'web/login.html', { 'form': form, 'error': _('Missing Fields.') }) # Check user existence. user = get_user(username=username) if not user: return render(request, 'web/login.html', { 'form': form, 'error': _('User not found.') }) # Check is user authenticated or not. user = authenticate(username=username, password=password) if user: if user.is_active: login(request, user) return redirect(next_url) else: return render(request, 'web/login.html', { 'form': form, 'error': _('Account Disabled.') }) else: return render(request, 'web/login.html', { 'form': form, 'error': _('Invalid login credentials.') }) return render(request, 'web/login.html', {'form': form})
def get(self, request, *args, **kwargs): form = LoginForm() return self.render_form(request, form)
def get(self, request): return render(request, "login_page.html", {"login_form": LoginForm()})
def get(self, request, *args, **kwargs): login_form = LoginForm() self.context = {"login_form": login_form} return render(request, "common/login.html", self.context)