Пример #1
0
def login(request):
    """
    MediaGoblin login view.

    If you provide the POST with 'next', it'll redirect to that view.
    """
    login_form = auth_forms.LoginForm(request.form)

    login_failed = False

    if request.method == 'POST':
        
        username = login_form.data['username']

        if login_form.validate():
            user = User.query.filter(
                or_(
                    User.username == username,
                    User.email == username,

                )).first()

            if user and user.check_login(login_form.password.data):
                # set up login in session
                request.session['user_id'] = unicode(user.id)
                request.session.save()

                if request.form.get('next'):
                    return redirect(request, location=request.form['next'])
                else:
                    return redirect(request, "index")

            # Some failure during login occured if we are here!
            # Prevent detecting who's on this system by testing login
            # attempt timings
            auth_lib.fake_login_attempt()
            login_failed = True

    return render_to_response(
        request,
        'mediagoblin/auth/login.html',
        {'login_form': login_form,
         'next': request.GET.get('next') or request.form.get('next'),
         'login_failed': login_failed,
         'allow_registration': mg_globals.app_config["allow_registration"]})
Пример #2
0
def login(request):
    """
    MediaGoblin login view.

    If you provide the POST with 'next', it'll redirect to that view.
    """
    login_form = auth_forms.LoginForm(request.POST)

    login_failed = False

    if request.method == 'POST' and login_form.validate():
        user = request.db.User.one({'username': request.POST['username']})

        if user and user.check_login(request.POST['password']):
            # set up login in session
            request.session['user_id'] = unicode(user['_id'])
            request.session.save()

            if request.POST.get('next'):
                return exc.HTTPFound(location=request.POST['next'])
            else:
                return exc.HTTPFound(location=request.urlgen("index"))

        else:
            # Prevent detecting who's on this system by testing login
            # attempt timings
            auth_lib.fake_login_attempt()
            login_failed = True

    # render
    template = request.template_env.get_template('mediagoblin/auth/login.html')
    return Response(
        template.render({
            'request':
            request,
            'login_form':
            login_form,
            'next':
            request.GET.get('next') or request.POST.get('next'),
            'login_failed':
            login_failed
        }))
Пример #3
0
def login(request):
    """
    MediaGoblin login view.

    If you provide the POST with 'next', it'll redirect to that view.
    """
    login_form = auth_forms.LoginForm(request.POST)

    login_failed = False

    if request.method == "POST" and login_form.validate():
        user = request.db.User.one({"username": request.POST["username"]})

        if user and user.check_login(request.POST["password"]):
            # set up login in session
            request.session["user_id"] = unicode(user["_id"])
            request.session.save()

            if request.POST.get("next"):
                return exc.HTTPFound(location=request.POST["next"])
            else:
                return exc.HTTPFound(location=request.urlgen("index"))

        else:
            # Prevent detecting who's on this system by testing login
            # attempt timings
            auth_lib.fake_login_attempt()
            login_failed = True

    # render
    template = request.template_env.get_template("mediagoblin/auth/login.html")
    return Response(
        template.render(
            {
                "request": request,
                "login_form": login_form,
                "next": request.GET.get("next") or request.POST.get("next"),
                "login_failed": login_failed,
            }
        )
    )
Пример #4
0
def login(request):
    """
    MediaGoblin login view.

    If you provide the POST with 'next', it'll redirect to that view.
    """
    login_form = auth_forms.LoginForm(request.form)

    login_failed = False

    if request.method == 'POST' and login_form.validate():
        user = request.db.User.find_one(
            {'username': request.form['username'].lower()})

        if user and user.check_login(request.form['password']):
            # set up login in session
            request.session['user_id'] = unicode(user._id)
            request.session.save()

            if request.form.get('next'):
                return exc.HTTPFound(location=request.form['next'])
            else:
                return redirect(request, "index")

        else:
            # Prevent detecting who's on this system by testing login
            # attempt timings
            auth_lib.fake_login_attempt()
            login_failed = True

    return render_to_response(
        request,
        'mediagoblin/auth/login.html',
        {'login_form': login_form,
         'next': request.GET.get('next') or request.form.get('next'),
         'login_failed': login_failed,
         'allow_registration': mg_globals.app_config["allow_registration"]})