当前位置: 首页>>代码示例>>Python>>正文


Python UserLoginForm.add_error方法代码示例

本文整理汇总了Python中accounts.forms.UserLoginForm.add_error方法的典型用法代码示例。如果您正苦于以下问题:Python UserLoginForm.add_error方法的具体用法?Python UserLoginForm.add_error怎么用?Python UserLoginForm.add_error使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在accounts.forms.UserLoginForm的用法示例。


在下文中一共展示了UserLoginForm.add_error方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: login

# 需要导入模块: from accounts.forms import UserLoginForm [as 别名]
# 或者: from accounts.forms.UserLoginForm import add_error [as 别名]
def login(request, success_url=None):
    if request.method == "POST":
        form = UserLoginForm(request.POST)
        if form.is_valid():
            try:
                user = auth.authenticate(email=request.POST.get("email"), password=request.POST.get("password"))

                if user is not None:
                    auth.login(request, user)
                    messages.error(request, "You have successfully logged in")

                    return redirect(reverse("profile"))
                else:
                    form.add_error(None, "Your email or password was not recognised")

            except SubscriptionEnded:
                form.add_error(None, "Your subscription has ended")

    else:
        form = UserLoginForm()

    args = {"form": form}
    args.update(csrf(request))

    return render(request, "login.html", args)
开发者ID:DarraghB1992,项目名称:wearesocial,代码行数:27,代码来源:views.py

示例2: login

# 需要导入模块: from accounts.forms import UserLoginForm [as 别名]
# 或者: from accounts.forms.UserLoginForm import add_error [as 别名]
def login(request):

    form = UserLoginForm()
    args = dict()
    args['form'] = form
    args['title'] = 'Login'

    if request.method == 'GET':
        return render(request, 'accounts/login.html', args)

    elif request.method == 'POST':
        form = UserLoginForm(request.POST)
        if form.is_valid():
            email = form.cleaned_data['email']
            password = form.cleaned_data['password']
            user = auth.authenticate(email=email, password=password)
            if user is not None:
                if user.is_active:
                    auth.login(request, user)
                    return redirect('accounts:profile', user.pk)
                else:
                    form.add_error(None, u'Користувач заблокований')
            else:
                form.add_error(None, u'Невірний логін або пароль')
        args['form'] = form
        return render(request, 'accounts/login.html', args)
开发者ID:AlexVoitenko,项目名称:vanga,代码行数:28,代码来源:views.py

示例3: login

# 需要导入模块: from accounts.forms import UserLoginForm [as 别名]
# 或者: from accounts.forms.UserLoginForm import add_error [as 别名]
def login(request, success_url=None):

    if request.method == 'POST':

        form = UserLoginForm(request.POST)

        if form.is_valid():

            user = auth.authenticate(email=request.POST.get('email'), password=request.POST.get('password'))

            if user is not None:

                auth.login(request, user)

                messages.error(request, "You have sucessfully logged in")

                return redirect(reverse('profile'))

            else:

                form.add_error(None, "Your email or password was not recognised")

    else:

        form = UserLoginForm()

    args = {'form':form}

    args.update(csrf(request))

    return render(request, 'login.html', args)
开发者ID:cdurri,项目名称:wearesocial,代码行数:33,代码来源:views.py

示例4: login

# 需要导入模块: from accounts.forms import UserLoginForm [as 别名]
# 或者: from accounts.forms.UserLoginForm import add_error [as 别名]
def login(request):
    """
    This method checks for post method and if not displays a an empty login form. If it is a POST then the form is
    populated and checked for validity before authentication.
    :param request:
    :return:
    """
    if request.method == 'POST':
        form = UserLoginForm(request.POST)
        if form.is_valid():
            user = auth.authenticate(email=request.POST.get('email'),
                                     password=request.POST.get('password'))

            if user is not None:
                auth.login(request, user)
                messages.error(request, "You have successfully logged in")
                return redirect(reverse('profile'))
            else:
                form.add_error(None, "Your email or password was not recognised")

    else:
        form = UserLoginForm()

    args = {'form': form}
    args.update(csrf(request))
    return render(request, 'login.html', args)
开发者ID:Code-Institute-Org,项目名称:full_stack_solutions,代码行数:28,代码来源:views.py

示例5: login

# 需要导入模块: from accounts.forms import UserLoginForm [as 别名]
# 或者: from accounts.forms.UserLoginForm import add_error [as 别名]
def login(request):
    """Return a login page"""
    if request.user.is_authenticated:
        return redirect(reverse('index'))
    if request.method == "POST":
        login_form = UserLoginForm(request.POST)
        
        if login_form.is_valid():
            user = auth.authenticate(username=request.POST['username'],
                                        password=request.POST['password'])
            if user:
                auth.login(user=user, request=request)
                messages.success(request, "You have successfully logged in")
                return redirect(reverse('index'))
            else: 
                login_form.add_error(None, "Your username or password is incorrect")
    else:
        login_form = UserLoginForm()
    return render(request, 'login.html', {"login_form": login_form})
开发者ID:sarahcrosby,项目名称:djangoproject,代码行数:21,代码来源:views.py

示例6: login

# 需要导入模块: from accounts.forms import UserLoginForm [as 别名]
# 或者: from accounts.forms.UserLoginForm import add_error [as 别名]
def login(request, success_url=None):

    if request.user.is_authenticated():
        return redirect(reverse('profile'))

    if request.method == 'POST':
        form = UserLoginForm(request.POST)
        if form.is_valid():
            try:
                user = auth.authenticate(email=request.POST.get('email'),
                                         password=request.POST.get('password'))
                if user is not None:
                    auth.login(request, user)
                    messages.error(request, "You have successfully logged in")
                    return redirect(reverse('profile'))
                else:
                    subscription_not_ended = arrow.now() < arrow.get(user.subscription_end)

                    if not subscription_not_ended:
                        form.add_error(None,"Your subscription has now ended")

                    form.add_error(None,"Your email or password was not recognised")

            except SubscriptionEnded:
                form.add_error(None,"Your subscription has now ended")

    else:
        form = UserLoginForm()

    args = {'form':form}
    args.update(csrf(request))
    return render(request, 'login.html', args)
开发者ID:amcevoy83,项目名称:musichub,代码行数:34,代码来源:views.py

示例7: login

# 需要导入模块: from accounts.forms import UserLoginForm [as 别名]
# 或者: from accounts.forms.UserLoginForm import add_error [as 别名]
def login(request):
    if request.method == 'POST':
        # if submitting form create instance of form class and populate
        form = UserLoginForm(request.POST)
        if form.is_valid():  # if login form is valid
            # authenticate user:
            # 'auth' will find our class 'EmailAuth' in backends.py via the
            # backend list in settings.py and then call the authenticate method.
            user = auth.authenticate(email=request.POST.get('email'),
                                     password=request.POST.get('password'))
            if user is not None:
                auth.login(request, user)  # login user. login() is a django method. Sets up a user session.
                messages.success(request, "You have successfully logged in.")
                return redirect(reverse('profile'))
            else:
                form.add_error(None, "Your email or password is not recognised.")

    else:
        # if login link has been clicked show the empty login form
        form = UserLoginForm()

    args = {'form': form}
    args.update(csrf(request))
    return render(request, 'login.html', args)
开发者ID:peterbristow,项目名称:codeinstitute-stream-three,代码行数:26,代码来源:views.py


注:本文中的accounts.forms.UserLoginForm.add_error方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。