예제 #1
0
def login(request):
    """ login(request)
    No return value

    Function called from route_url('apex_login', request)
    """
    title = _('You need to login')
    came_from = get_came_from(request)
    if 'local' not in apex_settings('provider_exclude', []):
        if asbool(apex_settings('use_recaptcha_on_login')):
            if apex_settings('recaptcha_public_key') and apex_settings(
                    'recaptcha_private_key'):
                LoginForm.captcha = RecaptchaField(
                    public_key=apex_settings('recaptcha_public_key'),
                    private_key=apex_settings('recaptcha_private_key'),
                )
            form = LoginForm(
                request.POST,
                captcha={'ip_address': request.environ['REMOTE_ADDR']})
        else:
            form = LoginForm(request.POST)
    else:
        form = None

    velruse_forms = generate_velruse_forms(request, came_from)

    if request.method == 'POST' and form.validate():
        user = AuthUser.get_by_username(form.data.get('username'))
        if user:
            headers = apex_remember(request, user.id)
            return HTTPFound(location=came_from, headers=headers)

    return {'title': title, 'form': form, 'velruse_forms': velruse_forms, \
            'form_url': request.route_url('apex_login'),
            'action': 'login'}
예제 #2
0
파일: views.py 프로젝트: jkoelker/apex
def login(request):
    """ login(request)
    No return value

    Function called from route_url('apex_login', request)
    """
    title = _('You need to login')
    came_from = get_came_from(request)
    if not apex_settings('exclude_local'):
        if asbool(apex_settings('use_recaptcha_on_login')):
            if apex_settings('recaptcha_public_key') and apex_settings('recaptcha_private_key'):
                LoginForm.captcha = RecaptchaField(
                    public_key=apex_settings('recaptcha_public_key'),
                    private_key=apex_settings('recaptcha_private_key'),
                )
            form = LoginForm(request.POST,
                            captcha={'ip_address': request.environ['REMOTE_ADDR']})
        else:
            form = LoginForm(request.POST)
    else:
        form = None

    velruse_forms = generate_velruse_forms(request, came_from)

    if request.method == 'POST' and form.validate():
        user = AuthUser.get_by_login(form.data.get('login'))
        if user:
            headers = apex_remember(request, user)
            return HTTPFound(location=came_from, headers=headers)

    return {'title': title, 'form': form, 'velruse_forms': velruse_forms, \
            'form_url': request.route_url('apex_login'),
            'action': 'login'}
예제 #3
0
파일: views.py 프로젝트: nycynik/apex
def login(request):
    """ login(request)
    No return value

    Function called from route_url('apex_login', request)
    """
    title = _('You need to login')
    came_from = get_came_from(request)

    if apex_settings('login_form_class'):
        LoginForm = get_module(apex_settings('login_form_class'))
    else:
        from apex.forms import LoginForm

    if not apex_settings('exclude_local'):
        if asbool(apex_settings('use_recaptcha_on_login')):
            if apex_settings('recaptcha_public_key') and \
                apex_settings('recaptcha_private_key'):
                LoginForm.captcha = RecaptchaField(
                    public_key=apex_settings('recaptcha_public_key'),
                    private_key=apex_settings('recaptcha_private_key'),
                )
            form = LoginForm(request.POST,
                             captcha={'ip_address': \
                             request.environ['REMOTE_ADDR']})
        else:
            form = LoginForm(request.POST)
    else:
        form = None

    velruse_forms = generate_velruse_forms(request, came_from)

    if request.method == 'POST' and form.validate():
        user = AuthUser.get_by_login(form.data.get('login'))
        if user:
            headers = apex_remember(request, user, \
                max_age=apex_settings('max_cookie_age', None))
            return HTTPFound(location=came_from, headers=headers)

    return {'title': title, 'form': form, 'velruse_forms': velruse_forms, \
            'form_url': request.route_url('apex_login'),
            'action': 'login'}
예제 #4
0
def login(request):
    """ login(request)
    No return value

    Function called from route_url('apex_login', request)
    """
    if request.user:
        if 'came_from' in request.params:
            return HTTPFound(location=request.params['came_from'])
    title = _('You need to login')
    came_from = get_came_from(request)
    velruse_forms = generate_velruse_forms(request, came_from)
    providers = get_providers()
    use_captcha = asbool(apex_settings('use_recaptcha_on_login'))
    if 'local' not in apex_settings('provider_exclude', []):
        if use_captcha:
            if apex_settings('recaptcha_public_key') and apex_settings('recaptcha_private_key'):
                LoginForm.captcha = RecaptchaField(
                    public_key=apex_settings('recaptcha_public_key'),
                    private_key=apex_settings('recaptcha_private_key'),
                )
        form = LoginForm(request.POST,
                         captcha={'ip_address': request.environ['REMOTE_ADDR']})
    else:
        form = None

    for vform in velruse_forms:
        if getattr(vform, 'velruse_login', None):
            vform.action = vform.velruse_login

    # allow to include this as a portlet inside other pages
    if (request.method == 'POST'
        and (request.route_url('apex_login') in request.url)):
        local_status = form.validate()
        username = form.data.get('username')
        password = form.data.get('password')
        user = search_user(username)
        if local_status and user:
            if user.active == 'Y':
                headers = apex_remember(request, user.id, internal_user=True)
                return HTTPFound(location=came_from, headers=headers)
        else:
            stop = False
            if use_captcha:
                if 'captcha' in form.errors:
                    stop = True
                    form.came_from.data = came_from
                    form.data['came_from'] = came_from
            if not stop:
                end_point='%s?%s' % (
                    request.route_url('apex_callback'),
                    urlencode(dict(
                        csrf_token=request.session.get_csrf_token(),
                        came_from=came_from,
                    ))
                )
                # try ldap auth if present on velruse
                # idea is to let the browser to the request with
                # an autosubmitted form
                if 'velruse.providers.ldapprovider' in providers:
                    response = AUTOSUBMITED_VELRUSE_LDAP_FORM%(
                        providers['velruse.providers.ldapprovider']['login'],
                        end_point,
                        username,
                        password)
                    return Response(response)

    if not came_from:
        came_from = request.url
    form.came_from.data = came_from

    return {'title': title,
            'form': form,
            'velruse_forms': velruse_forms,
            'form_url': request.route_url('apex_login'),
            'action': 'login'}
예제 #5
0
def login(request):
    """ login(request)
    No return value

    Function called from route_url('apex_login', request)
    """
    if request.user:
        if 'came_from' in request.params:
            return HTTPFound(location=request.params['came_from'])
    title = _('You need to login')
    came_from = get_came_from(request)
    velruse_forms = generate_velruse_forms(request, came_from)
    providers = get_providers()
    use_captcha = asbool(apex_settings('use_recaptcha_on_login'))
    if 'local' not in apex_settings('provider_exclude', []):
        if use_captcha:
            if apex_settings('recaptcha_public_key') and apex_settings(
                    'recaptcha_private_key'):
                LoginForm.captcha = RecaptchaField(
                    public_key=apex_settings('recaptcha_public_key'),
                    private_key=apex_settings('recaptcha_private_key'),
                )
        form = LoginForm(
            request.POST,
            captcha={'ip_address': request.environ['REMOTE_ADDR']})
    else:
        form = None

    for vform in velruse_forms:
        if getattr(vform, 'velruse_login', None):
            vform.action = vform.velruse_login

    # allow to include this as a portlet inside other pages
    if (request.method == 'POST'
            and (request.route_url('apex_login') in request.url)):
        local_status = form.validate()
        username = form.data.get('username')
        password = form.data.get('password')
        user = search_user(username)
        if local_status and user:
            if user.active == 'Y':
                headers = apex_remember(request, user.id, internal_user=True)
                return HTTPFound(location=came_from, headers=headers)
        else:
            stop = False
            if use_captcha:
                if 'captcha' in form.errors:
                    stop = True
                    form.came_from.data = came_from
                    form.data['came_from'] = came_from
            if not stop:
                end_point = '%s?%s' % (
                    request.route_url('apex_callback'),
                    urlencode(
                        dict(
                            csrf_token=request.session.get_csrf_token(),
                            came_from=came_from,
                        )))
                # try ldap auth if present on velruse
                # idea is to let the browser to the request with
                # an autosubmitted form
                if 'velruse.providers.ldapprovider' in providers:
                    response = AUTOSUBMITED_VELRUSE_LDAP_FORM % (
                        providers['velruse.providers.ldapprovider']['login'],
                        end_point, username, password)
                    return Response(response)

    if not came_from:
        came_from = request.url
    form.came_from.data = came_from

    return {
        'title': title,
        'form': form,
        'velruse_forms': velruse_forms,
        'form_url': request.route_url('apex_login'),
        'action': 'login'
    }