Example #1
0
def login():
    from uliweb.contrib.auth import login

    form = functions.get_form('auth.LoginForm')()

    if request.user:
        next = request.GET.get('next')
        if next:
            return redirect(next)

    if request.method == 'GET':
        form.next.data = request.GET.get('next', request.referrer or add_prefix('/'))
        return {'form':form, 'msg':''}
    if request.method == 'POST':
        flag = form.validate(request.params)
        if flag:
            f, d = functions.authenticate(username=form.username.data, password=form.password.data)
            if f:
                request.session.remember = form.rememberme.data
                login(form.username.data)
                next = urllib.unquote(request.POST.get('next', add_prefix('/')))
                return redirect(next)
            else:
                form.errors.update(d)
        msg = form.errors.get('_', '') or _('Login failed!')
        return {'form':form, 'msg':str(msg)}
Example #2
0
def login():
    from uliweb.contrib.auth import login

    form = functions.get_form('auth.LoginForm')()

    if request.user:
        next = request.values.get('next')
        if next:
            return redirect(next)

    next = request.values.get('next')
    if not next:
        next = add_prefix('/')
    if request.method == 'GET':
        form.next.data = next
        return {'next': next}
    if request.method == 'POST':
        flag = form.validate(request.values)
        if flag:
            f, d = functions.authenticate(username=form.username.data, password=form.password.data)
            if f:
                request.session.remember = form.rememberme.data
                login(form.username.data)
                next = unquote(next)
                return redirect(next)
            else:
                form.errors.update(d)
        if request.is_xhr:
            return json({'success': False, '_': 'Login Failed', 'errors': form.errors})
        else:
            msg = form.errors.get('_', '') or _('Login failed!')
            return {'form': form, 'msg': str(msg)}
Example #3
0
def login():
    from uliweb.contrib.auth import login

    form = functions.get_form('auth.LoginForm')()

    if request.user:
        next = request.values.get('next')
        if next:
            return redirect(next)

    next = request.values.get('next')
    if not next:
        next = request.referrer
        if not next or (next and next.endswith('/login')):
            next = add_prefix('/')
    if request.method == 'GET':
        form.next.data = next
        return {}
    if request.method == 'POST':
        flag = form.validate(request.params)
        if flag:
            f, d = functions.authenticate(username=form.username.data, password=form.password.data)
            if f:
                request.session.remember = form.rememberme.data
                login(form.username.data)
                next = urllib.unquote(next)
                return redirect(next)
            else:
                form.errors.update(d)
        if request.is_xhr:
            return json({'success':False, 'errors':form.errors})
        else:
            msg = form.errors.get('_', '') or _('Login failed!')
            return {'form':form, 'msg':str(msg)}
Example #4
0
def login():
    from uliweb.contrib.auth import login

    form = functions.get_form('auth.LoginForm')()

    if request.user:
        next = request.GET.get('next')
        if next:
            return redirect(next)

    if request.method == 'GET':
        form.next.data = request.GET.get('next', request.referrer
                                         or add_prefix('/'))
        return {'form': form, 'msg': ''}

    if request.method == 'POST':
        flag = form.validate(request.params)
        if flag:
            f, d = functions.authenticate(username=form.username.data,
                                          password=form.password.data)
            if f:
                request.session.remember = form.rememberme.data
                login(form.username.data)
                next = unquote(request.POST.get('next', add_prefix('/')))
                return redirect(next)
            else:
                form.errors.update(d)
        msg = form.errors.get('_', '') or _('Login failed!')
        return {'form': form, 'msg': str(msg)}