Exemplo n.º 1
0
def user_login(request):
    if request.method == 'GET':
        form = LoginForm()
        return render(request, 'accounts/login_new.html', locals())
    else:
        form = LoginForm(request.POST)
        login_errors = []
        if form.is_valid():
            username = request.POST.get('username', '')
            password = request.POST.get('password', '')
            print "username:%s password:%s" % (username, password)
            user = authenticate(username=username, password=password)
            if user is not None and user.is_active:
                login(request, user)
                auth_data = auth_class(request.user)
                request.session["fun_auth"] = auth_data
                user_data = User.objects.get(username=request.user)
                user_data.session_key = request.session.session_key
                user_data.save()
                request.session.set_expiry(
                    1728000)  #用户20天不登录,session将过期,session_key将被清空
                return HttpResponseRedirect('/index/')
            else:
                login_errors.append("用户或密码错误,请联系管理员!")

                return render(request, 'accounts/login_new.html', locals())
        else:
            return render(request, 'accounts/login_new.html', locals())
Exemplo n.º 2
0
def auth_session_class(uuid):
    u"""当权限组被禁用的时候调用此函数,重置当前用户权限"""
    data_id = auth_group.objects.get(uuid=uuid)
    all_user = data_id.group_user.all()
    for i in all_user:
        if i.session_key:
            s = SessionStore(session_key=i.session_key)
            s["fun_auth"] = auth_class(i)
            s.save()
    return True
Exemplo n.º 3
0
def auth_session_class(uuid):
    u"""当权限组被禁用的时候调用此函数,重置当前用户权限"""
    data = department_Mode.objects.get(id=uuid)
    all_user = data.members.all()
    for user in all_user:
        print "用户:%s"% user.first_name
        if user.session_key:
            s = SessionStore(session_key=user.session_key)
            s["fun_auth"] = auth_class(user)
            print s["fun_auth"]
            s.save()
    return True
Exemplo n.º 4
0
Arquivo: views.py Projeto: voilet/cmdb
def auth_session_clsss(uuid):
    """

    :return:
    """
    data_id = auth_group.objects.get(uuid=uuid)
    all_user = data_id.group_user.all()
    for i in all_user:
        if i.session_key:
            s = SessionStore(session_key=i.session_key)
            s["fun_auth"] = auth_class(i)
            s.save()

    return True
Exemplo n.º 5
0
def auth_session_clsss(uuid):
    """

    :return:
    """
    data_id = auth_group.objects.get(uuid=uuid)
    all_user = data_id.group_user.all()
    for i in all_user:
        if i.session_key:
            s = SessionStore(session_key=i.session_key)
            s["fun_auth"] = auth_class(i)
            s.save()

    return True
Exemplo n.º 6
0
def user_session_expiry(request):
    """

    :return:
    """

    user_id = request.session.get('username')
    expirty_data = auth_class(user_id)
    user_id = request.session.get('user_id')
    role_id = request.session.get('role_id')
    user_total_num = CustomUser.objects.all().count()
    user_active_num = CustomUser.objects.filter(is_active=True).count()
    expirty_data["user_id"] = user_id
    expirty_data["role_id"] = role_id
    expirty_data["user_total_num"] = user_total_num
    expirty_data["user_active_num"] = user_active_num
    request.session.set_expiry(28800)

    return expirty_data
Exemplo n.º 7
0
def user_login(request):
    """
    select,    edit    update    delete
    project_nam
    add_user    edit_user    edit_pass    delete_user
    :param request:
    :return:
    """
    if request.method == "POST":
        # form = LoginForm(request=request, data=request.POST)
        # if form.is_valid():
        #     auth_data = auth_class(request.user)
        #     request.session["fun_auth"] = auth_data
        #     user_data = CustomUser.objects.get(first_name=request.user)
        #     user_data.session_key = request.session.session_key
        #     user_data.save()
        #     return HttpResponseRedirect('/')
        form = LoginForm(request.POST)
        if form.is_valid():
            username = request.POST.get('username', '')
            password = request.POST.get('password', '')
            try:
                data = CustomUser.objects.get(username=username)
                check_data = check_password(password, data.password)
                if check_data:
                    data.backend = 'django.contrib.auth.backends.ModelBackend'
                    login(request, data)
                    auth_data = auth_class(request.user)
                    request.session["fun_auth"] = auth_data
                    user_data = CustomUser.objects.get(email=request.user)
                    user_data.session_key = request.session.session_key
                    user_data.save()
                    request.session.set_expiry(28800)
                    return HttpResponseRedirect(request.GET['next'])
            except:
                return render_to_response(
                    'user/login.html',
                    locals(),
                    context_instance=RequestContext(request))

    return render_to_response('user/login.html',
                              locals(),
                              context_instance=RequestContext(request))
Exemplo n.º 8
0
def user_login(request):
    """
    select,    edit    update    delete
    project_nam
    add_user    edit_user    edit_pass    delete_user
    :param request:
    :return:
    """
    if request.method == "POST":
        # form = LoginForm(request=request, data=request.POST)
        # if form.is_valid():
        #     auth_data = auth_class(request.user)
        #     request.session["fun_auth"] = auth_data
        #     user_data = CustomUser.objects.get(first_name=request.user)
        #     user_data.session_key = request.session.session_key
        #     user_data.save()
        #     return HttpResponseRedirect('/')
        form = LoginForm(request.POST)
        if form.is_valid():
            username = request.POST.get('username', '')
            password = request.POST.get('password', '')
            try:
                data = CustomUser.objects.get(username=username)
                check_data = check_password(password, data.password)
                if check_data:
                    data.backend = 'django.contrib.auth.backends.ModelBackend'
                    login(request, data)
                    auth_data = auth_class(request.user)
                    request.session["fun_auth"] = auth_data
                    user_data = CustomUser.objects.get(email=request.user)
                    user_data.session_key = request.session.session_key
                    user_data.save()
                    request.session.set_expiry(28800)
                    return HttpResponseRedirect(request.GET['next'])
            except:
                return render_to_response('user/login.html', locals(), context_instance=RequestContext(request))

    return render_to_response('user/login.html', locals(), context_instance=RequestContext(request))