示例#1
0
def login(requests):
    form = loginform()
    if requests.method == 'POST':
        form = loginform(requests.POST)
        if form.is_valid():
            username = form.cleaned_data['username']
            password = form.cleaned_data['password']
            user = authenticate(username=username, password=password)
            if user != None:
                login_dj(requests, user)
                return redirect('dashboard')
    return render(requests, 'accounts/login.html', {'form': form})
示例#2
0
def login(request):
    if request.method == 'POST':
        username = request.POST['username']
        password = request.POST['password']
        user = authenticate(request, username=username, password=password)
        if user:
            login_dj(request, user)
            return redirect('welcome')
        else:
            return render(request, 'users/login.html',
                          {'error': 'Inicia sesión'})
    else:
        return render(request, 'users/login.html')
示例#3
0
def login(request):
    if request.method == 'POST':
        form = AuthenticationForm(data=request.POST)
        if form.is_valid():
            login_dj(request, form.get_user())
            if 'next' in request.POST:
                return redirect(request.POST.get('next'))
            else:
                return redirect('news:list')
    else:
        form = AuthenticationForm()
    context = {'user_form': form}
    return render(request, 'accounts/login.html', context)
示例#4
0
def signup(request):
    if request.method == 'POST':
        user_form = UserCreationForm(request.POST)
        profile_form = ProfileCreateForm(request.POST)
        if user_form.is_valid() and profile_form.is_valid():
            profile = profile_form.save(commit=False)
            profile.user = user_form.save()
            profile.save()
            login_dj(request, profile.user)
            if 'next' in request.POST:
                return redirect(request.POST.get('next'))
            else:
                return redirect('news:list')  # account:profile_detail
    else:
        user_form = UserCreationForm()
        profile_form = ProfileCreateForm()
    context = {
        'user_form': user_form,
        'profile_form': profile_form
    }
    return render(request, 'accounts/signup.html', context)
示例#5
0
文件: views.py 项目: Maruf520/bds
def login(request):
    # if request.user.is_authenticated:
    if request.method == 'POST':
        form = SigninForm(request.POST)
        if form.is_valid():
            user = form.user
            login_dj(request, user)
            # if request.user.is_admin == True:

            #     details = Blood_quantity.objects.get(bank__owner=request.user)
            #     context  ={
            #         'detail':details
            #     }
            #     return render (request,)

            return redirect('/')

    else:
        form = SigninForm()
    context = {'form': form}

    return render(request, 'accounts/login.html', context)
示例#6
0
def login(request):
    redirect_to = '/'
    if request.user.is_authenticated():
        return redirect(index)
    elif request.method == "POST":
        form = LoginForm(request.POST)
        if form.is_valid():
            redirect_to = form.cleaned_data['redirect_to']
            user = authenticate(username=form.cleaned_data['login'],
                    password=form.cleaned_data['password'])
            if user is not None:
                if user.is_active:
                    login_dj(request, user)
                    return redirect(redirect_to)
                else:
                    context = {'form': form,
                            'next': redirect_to,
                            'error': 'Your account is disabled.'}
                    context.update(csrf(request))
                    return render_to_response('users/login_form.tpl', context)
            else:
                context = {'form': form,
                        'next': redirect_to,
                        'error': 'Your login or password is invalid.'}
                context.update(csrf(request))
                return render_to_response('users/login_form.tpl', context)
        else:
            context = {'error': 'You submitted an invalid form.',
                    'form': form}
            context.update(csrf(request))
            return render_to_response('users/login_form.tpl', context)
    else:
        if request.GET.get('next') is not None:
            redirect_to = request.GET.get('next')
        form = LoginForm(initial={'redirect_to': redirect_to})
        context = {'form': form, 'next': redirect_to}
        context.update(csrf(request))
        return render_to_response('users/login_form.tpl', context)