예제 #1
0
def loginform_view(request):
    form = LoginForm()
    if request.method == 'POST':
        form = LoginForm(request.POST)
        if form.is_valid():
            print("Validated")
            print(form.cleaned_data['name'])
            print(form.cleaned_data['email'])
    return render(request, 'form_page.html', {'form': form})
예제 #2
0
파일: routes.py 프로젝트: muthu-kr/Mig2
def login():
    if current_user.is_authenticated:
        return redirect(url_for('index'))
    form = LoginForm()
    if form.validate_on_submit():
        user = User.query.filter_by(username=form.username.data).first()
        if user is None or not user.check_password(form.password.data):
            flash('Invalid username or password')
            return redirect(url_for('login'))
        login_user(user, remember=form.remember_me.data)
        next_page = request.args.get('next')
        if not next_page or url_parse(next_page).netloc != '':
            next_page = url_for('index')
        return redirect(next_page)
    return render_template('login.html', title='Sign In', form=form)
예제 #3
0
파일: views.py 프로젝트: hth945/pytest
def user_login(request):
    if request.user.is_authenticated:
        return HttpResponseRedirect('/')

    state = None

    if request.method == 'POST':
        username = request.POST.get('username')
        password = request.POST.get('password')

        user = auth.authenticate(username=username, password=password)

        if user:
            if user.is_active:
                auth.login(request, user)
                return HttpResponseRedirect('/')
            else:
                return HttpResponse(u'Your account is disabled.')
        else:
            state = 'not_exist_or_password_error'

    context = {
        'loginForm': LoginForm(),
        'state': state,
    }
    return render(request, 'login.html', context)
def logout(request):
    form=LoginForm()
    response=render(request,'app1/signin.html',{'form':form,'status':1})
    response.delete_cookie('id')
    # try:
    #   del request.session['id']
    # except:
    #     pass
    return response
예제 #5
0
def login():

    if current_user.is_authenticated:
        return redirect(url_for('hey'))

    Form = LoginForm()
    if Form.validate_on_submit():
        user = User.query.filter_by(username=Form.username.data).first()
        if user is None or not user.check_password(Form.password.data):
            flash('Invalid Username')
            return redirect(url_for('login'))
        login_user(user, remember=Form.remember_me.data)
        next_page = request.args.get('next')
        if not next_page or url_parse(next_page).netloc != '':
            next_page = url_for('hey')
        return redirect(next_page)
        return redirect(url_for('hey'))
        flash('Login requested by user {} and remember me given {}'.format(
            Form.username.data, Form.remember_me.data))
        return redirect(url_for('hey'))
    return render_template('login.html', title='LoginForm', form=Form)
예제 #6
0
def login1(request):
    form = LoginForm(request.POST or None)
    if request.POST:
        uemail = request.POST['email']
        password = request.POST['pass']
        try:
            data = Register_Data.objects.get(email=uemail, passw=password)
            if data:
                request.session['name'] = data.name
                #request.session['email'] = data.email
                return redirect('show')
            else:
                return HttpResponseRedirect('/app1/login1/')
        except:
            return HttpResponseRedirect('/app1/login1/')
    return render(request, 'login1.html', {'form': form})
예제 #7
0
def user_login(request):
    if (request.method == 'POST'):
        login_form = LoginForm(request.POST)
        print(request.POST)
        # First get the username and password supplied
        username = request.POST["username"]
        password = request.POST["password"]
        # Django's built-in authentication function:
        user = authenticate(username=username, password=password)
        # If we have a user
        if user:
            #Check it the account is active
            if user.is_active:
                # Log the user in.
                login(request, user)
                # Send the user back to homepage
                return redirect("/history")
            else:
                # If account is not active:
                return HttpResponse("Your account is not active.")

    else:
        #Nothing has been provided for username or password.
        return render(request, 'app1/login.html', {})