コード例 #1
0
ファイル: views.py プロジェクト: feng520ckx/django-sspanel
def userinfo(request):
    '''用户中心'''
    user = request.user

    # 获取公告
    try:
        anno = Announcement.objects.all()[0]
    except:
        anno = None
    min_traffic = '{}m'.format(int(settings.MIN_CHECKIN_TRAFFIC / 1024 / 1024))
    max_traffic = '{}m'.format(int(settings.MAX_CHECKIN_TRAFFIC / 1024 / 1024))
    remain_traffic = 100 - eval(user.ss_user.get_used_percentage())
    # 订阅地址
    sub_link = user.get_sub_link()
    # 节点导入链接
    sub_code = Node.get_sub_code(user)
    context = {
        'user': user,
        'anno': anno,
        'remain_traffic': remain_traffic,
        'min_traffic': min_traffic,
        'max_traffic': max_traffic,
        'sub_link': sub_link,
        'sub_code': sub_code,
    }
    return render(request, 'sspanel/userinfo.html', context=context)
コード例 #2
0
def userinfo(request):
    '''用户中心'''
    user = request.user

    # 获取公告
    try:
        anno = Announcement.objects.all()[0]
    except:
        anno = None
    min_traffic = '{}m'.format(int(settings.MIN_CHECKIN_TRAFFIC / 1024 / 1024))
    max_traffic = '{}m'.format(int(settings.MAX_CHECKIN_TRAFFIC / 1024 / 1024))
    remain_traffic = 100 - eval(user.ss_user.get_used_percentage())
    # 订阅地址
    sub_link = user.get_sub_link()
    # 节点导入链接
    sub_code = Node.get_sub_code(user)
    context = {
        'user': user,
        'anno': anno,
        'remain_traffic': remain_traffic,
        'min_traffic': min_traffic,
        'max_traffic': max_traffic,
        'sub_link': sub_link,
        'sub_code': sub_code,
    }
    return render(request, 'sspanel/userinfo.html', context=context)
コード例 #3
0
def Login_view(request):
    '''用户登录函数'''
    if request.method == 'POST':
        form = LoginForm(request.POST)
        if form.is_valid():
            # 获取表单用户名和密码
            username = form.cleaned_data['username']
            password = form.cleaned_data['password']
            # 进行用户验证
            user = authenticate(username=username, password=password)
            if user is not None and user.is_active:
                login(request, user)
                try:
                    anno = Announcement.objects.all()[0]
                except:
                    anno = None
                min_traffic = '{}m'.format(
                    int(settings.MIN_CHECKIN_TRAFFIC / 1024 / 1024))
                max_traffic = '{}m'.format(
                    int(settings.MAX_CHECKIN_TRAFFIC / 1024 / 1024))
                remain_traffic = 100 - eval(user.ss_user.get_used_percentage())
                registerinfo = {
                    'title': '登录成功!',
                    'subtitle': '自动跳转到用户中心',
                    'status': 'success',
                }
                context = {
                    'registerinfo': registerinfo,
                    'anno': anno,
                    'remain_traffic': remain_traffic,
                    'min_traffic': min_traffic,
                    'max_traffic': max_traffic,
                    'sub_link': user.get_sub_link(),
                    'sub_code': Node.get_sub_code(user),
                }
                return render(request,
                              'sspanel/userinfo.html',
                              context=context)
            else:
                form = LoginForm()
                registerinfo = {
                    'title': '登录失败!',
                    'subtitle': '请重新填写信息!',
                    'status': 'error',
                }
                context = {
                    'registerinfo': registerinfo,
                    'form': form,
                }
                return render(request, 'sspanel/login.html', context=context)
    else:
        context = {
            'form': LoginForm(),
            'USE_SMTP': settings.USE_SMTP,
        }

        return render(request, 'sspanel/login.html', context=context)
コード例 #4
0
ファイル: views.py プロジェクト: feng520ckx/django-sspanel
def Login_view(request):
    '''用户登录函数'''
    if request.method == 'POST':
        form = LoginForm(request.POST)
        if form.is_valid():
            # 获取表单用户名和密码
            username = form.cleaned_data['username']
            password = form.cleaned_data['password']
            # 进行用户验证
            user = authenticate(username=username, password=password)
            if user is not None and user.is_active:
                login(request, user)
                try:
                    anno = Announcement.objects.all()[0]
                except:
                    anno = None
                min_traffic = '{}m'.format(
                    int(settings.MIN_CHECKIN_TRAFFIC / 1024 / 1024))
                max_traffic = '{}m'.format(
                    int(settings.MAX_CHECKIN_TRAFFIC / 1024 / 1024))
                remain_traffic = 100 - eval(user.ss_user.get_used_percentage())
                registerinfo = {
                    'title': '登录成功!',
                    'subtitle': '自动跳转到用户中心',
                    'status': 'success',
                }
                context = {
                    'registerinfo': registerinfo,
                    'anno': anno,
                    'remain_traffic': remain_traffic,
                    'min_traffic': min_traffic,
                    'max_traffic': max_traffic,
                    'sub_link': user.get_sub_link(),
                    'sub_code': Node.get_sub_code(user),

                }
                return render(request, 'sspanel/userinfo.html', context=context)
            else:
                form = LoginForm()
                registerinfo = {
                    'title': '登录失败!',
                    'subtitle': '请重新填写信息!',
                    'status': 'error',
                }
                context = {
                    'registerinfo': registerinfo,
                    'form': form,
                }
                return render(request, 'sspanel/login.html', context=context)
    else:
        context = {'form': LoginForm(),
                   'USE_SMTP': settings.USE_SMTP, }

        return render(request, 'sspanel/login.html', context=context)