예제 #1
0
def signin(request):
    if request.method == 'POST':
        form = LoginForm(request.POST)
        if form.is_valid():
            form.save()
            request.session['User'] = form.data.get('name')
            return redirect('todos')
    else:
        return redirect('home')
예제 #2
0
def login(request):
    if request.method == 'POST':
        form = LoginForm(request.POST)
        if form.is_valid():
            user = User.objects.filter(name=form.data.get('name')).first()
            if user and user.password == form.data.get('password'):
                request.session['User'] = form.data.get('name')
                return redirect('todos')
            else:
                return redirect('home')
    else:
        return redirect('home')
예제 #3
0
파일: views.py 프로젝트: rupeshgyawali/Todo
def index(request):
    if request.user.is_authenticated:
        return HttpResponseRedirect('/todo/')
    else:
        if request.method == 'POST':

            if 'login_form' in request.POST:

                form = LoginForm(request.POST)

                if form.is_valid:
                    username = request.POST['username']
                    password = request.POST['password']
                    user = authenticate(request,
                                        username=username,
                                        password=password)

                    if user is not None:
                        if user.is_active:
                            login(request, user)
                            return HttpResponseRedirect('/todo/')

            if 'register_form' in request.POST:

                form = UserForm(request.POST)

                if form.is_valid:
                    user = form.save(commit=False)
                    username = form.cleaned_data['username']
                    password = form.cleaned_data['password']
                    user.set_password(password)
                    user.save()

                    user = authenticate(request,
                                        username=username,
                                        password=password)

                    if user is not None:
                        if user.is_active:
                            login(request, user)
                            return HttpResponseRedirect('/todo/')

        login_form = LoginForm()
        register_form = UserForm()
        return render(request, 'index.html', {
            'login_form': login_form,
            'register_form': register_form
        })
예제 #4
0
def home(request):
    request.session['User'] = None
    template = "login.html"
    form = LoginForm()
    return render(request, template, {'loginForm': form})