示例#1
0
def ChangeSsPass(request):
    '''改变用户ss连接密码'''
    ss_user = request.user.ss_user

    if request.method == 'POST':
        form = ChangeSsPassForm(request.POST)

        if form.is_valid():
            # 获取用户提交的password
            ss_pass = request.POST.get('password')
            ss_user.password = ss_pass
            ss_user.save()
            clear_node_user_cache()
            registerinfo = {
                'title': '修改成功!',
                'subtitle': '请及时更换客户端密码!',
                'status': 'success',
            }
            context = {
                'registerinfo': registerinfo,
                'ss_user': ss_user,
            }
            return render(request,
                          'sspanel/userinfoedit.html',
                          context=context)
        else:
            return redirect('/')
    else:
        form = ChangeSsPassForm()
        return render(request, 'sspanel/sspasschanged.html', {'form': form})
示例#2
0
def ChangeSsObfs(request):
    '''改变用户ss连接混淆'''
    ss_user = request.user.ss_user

    if request.method == 'POST':
        ss_obfs = request.POST.get('obfs')
        ss_user.obfs = ss_obfs
        ss_user.save()
        registerinfo = {
            'title': '修改成功!',
            'subtitle': '请及时更换客户端配置!',
            'status': 'success',
        }
        methods = [m[0] for m in METHOD_CHOICES]
        protocols = [p[0] for p in PROTOCOL_CHOICES]
        obfss = [o[0] for o in OBFS_CHOICES]
        clear_node_user_cache()
        context = {
            'registerinfo': registerinfo,
            'ss_user': ss_user,
            'methods': methods,
            'protocols': protocols,
            'obfss': obfss,
        }
        return render(request, 'sspanel/userinfoedit.html', context=context)
示例#3
0
def purchase(request):
    '''
    购买商品的逻辑
    返回是否成功
    '''
    if request.method == "POST":
        user = request.user
        ss_user = user.ss_user
        goodId = request.POST.get('goodId')
        good = Goods.objects.get(pk=goodId)
        if user.balance < good.money:
            registerinfo = {
                'title': '金额不足!',
                'subtitle': '请去捐赠界面/联系站长充值',
                'status': 'error',
            }
        else:
            # 验证成功进行提权操作
            ss_user.enable = True
            ss_user.transfer_enable += good.transfer
            user.balance -= good.money
            if (user.level == good.level
                    and user.level_expire_time > datetime.datetime.now()):
                user.level_expire_time += datetime.timedelta(days=good.days)
            else:
                user.level_expire_time = datetime.datetime.now() \
                    + datetime.timedelta(days=good.days)
            user.level = good.level
            user.save()
            ss_user.save()
            # 增加购买记录
            record = PurchaseHistory(good=good,
                                     user=user,
                                     money=good.money,
                                     purchtime=timezone.now())
            record.save()
            # 增加返利记录
            inviter = User.objects.get(pk=user.invited_by)
            rebaterecord = RebateRecord(user_id=inviter.pk,
                                        money=good.money *
                                        Decimal(settings.INVITE_PERCENT))
            inviter.balance += rebaterecord.money
            inviter.save()
            rebaterecord.save()
            registerinfo = {
                'title': '购买成功',
                'subtitle': '请在用户中心检查最新信息',
                'status': 'success',
            }
            # 删除缓存
            clear_node_user_cache()
        return JsonResponse(registerinfo)
    else:
        return HttpResponse('errors')
示例#4
0
def register(request):
    '''用户注册时的函数'''
    if request.method == 'POST':
        form = RegisterForm(request.POST)

        if form.is_valid():
            # 获取用户填写的邀请码
            code = request.POST.get('invitecode')
            # 数据库查询邀请码
            code_query = InviteCode.objects.filter(code=code, isused=False)
            # 判断邀请码是否存在并返回信息
            if len(code_query) == 0:
                registerinfo = {
                    'title': '邀请码失效',
                    'subtitle': '请重新获取邀请码',
                    'status': 'error',
                }
                context = {
                    'registerinfo': registerinfo,
                    'form': form,
                }
                return render(request,
                              'sspanel/register.html',
                              context=context)

            else:
                registerinfo = {
                    'title': '注册成功!',
                    'subtitle': '请登录使用吧!',
                    'status': 'success',
                }
                context = {'registerinfo': registerinfo}
                form.save()
                # 改变表邀请码状态
                code = code_query[0]
                code.isused = True
                code.save()
                # 将user和ssuser关联
                user = User.objects.get(username=request.POST.get('username'))
                # 绑定邀请人
                user.invited_by = code.code_id
                user.save()
                max_port_user = SSUser.objects.order_by('-port').first()
                port = max_port_user.port + randint(2, 3)
                SSUser.objects.create(user=user, port=port)
                clear_node_user_cache()
                return render(request, 'sspanel/index.html', context=context)

    else:
        form = RegisterForm()

    return render(request, 'sspanel/register.html', {'form': form})
示例#5
0
def change_ss_port(request):
    '''
    随机重置用户用端口
    返回是否成功
    '''
    user = request.user.ss_user
    # 找到端口池中最大的端口
    port = SSUser.randomPord()
    user.port = port
    user.save()
    clear_node_user_cache()
    registerinfo = {
        'title': '修改成功!',
        'subtitle': '端口修改为:{}!'.format(port),
        'status': 'success',
    }
    return JsonResponse(registerinfo)