Beispiel #1
0
def login(request):
    if request.method == 'POST':
        from logic.models import User
        cur_user = User()
        form = RegisterForm(request.POST)
        if form.is_valid():
            username = form.cleaned_data['uid']
            password = form.cleaned_data['password']
            q = User.objects.filter(uid=username, password=password)
            if q.__len__() != 0:
                cur_user.name = q[0].name
                cur_user.uid = q[0].uid
                q[0].lobby_id = 0
                q[0].save()
                userdict = {'uid': username, 'name': cur_user.name}
                all_lobbies = Lobby.objects.all()
                lobbies = []
                into_lobby_form = IntoLobbyForm()
                lobby_length = all_lobbies.__len__()
                for i in range(0, lobby_length):
                    lobby = {
                        'user_num':
                        User.objects.filter(lobby_id=(i + 1)).__len__(),
                        'lobby_name': all_lobbies[i].name
                    }
                    lobbies.append(lobby)
                return render(
                    request, 'login_complete.html', {
                        'lobbies': lobbies,
                        'Dict': json.dumps(userdict),
                        'into_lobby_form': into_lobby_form,
                    })
            else:
                return HttpResponse("用户名或密码错误!")
Beispiel #2
0
def login(request):
    if request.method == 'POST':
        from logic.models import User
        cur_user = User()
        form = RegisterForm(request.POST)
        if form.is_valid():
            username = form.cleaned_data['uid']
            password = form.cleaned_data['password']
            q = User.objects.filter(uid=username, password=password)
            if q.__len__() != 0:
                cur_user.name = q[0].name
                cur_user.uid = q[0].uid
                q[0].lobby_id = 0
                q[0].save()
                userdict = {'uid': username, 'name': cur_user.name}
                all_lobbies = Lobby.objects.all()
                lobbies = []
                into_lobby_form = IntoLobbyForm()
                lobby_length = all_lobbies.__len__()
                for i in range(0, lobby_length):
                    lobby = {
                        'user_num': User.objects.filter(lobby_id=(i+1)).__len__(),
                        'lobby_name': all_lobbies[i].name
                    }
                    lobbies.append(lobby)
                return render(request, 'login_complete.html', {
                    'lobbies': lobbies,
                    'Dict': json.dumps(userdict),
                    'into_lobby_form': into_lobby_form,
                })
            else:
                return HttpResponse("用户名或密码错误!")
Beispiel #3
0
def register(request):
    if request.method == 'GET':
        from logic.models import User
        new_user = User()
        new_user.uid = request.GET['reg_user']
        new_user.password = request.GET['reg_password']
        password_again = request.GET['reg_password_again']
        new_user.name = request.GET['reg_name']
        new_user.lobby_id = 0
        new_user.iconnum = request.GET['iconnum']
        new_user.status = 10000
        new_user.latest_time = "2015-01-01 12:00:00"
        new_user.score = 0
        new_user.win_num = 0
        new_user.tie_num = 0
        new_user.lose_num = 0
        dict1 = {'login': '******', 'reg': '0' }
        form = RegisterForm()
        all_lobbies = Lobby.objects.all()
        lobbies = []
        lobby_length = all_lobbies.__len__()
        for i in range(0, lobby_length):
            user_num = User.objects.filter(lobby_id=(i+1)).__len__()
            lobby = {
                'user_num': user_num,
                'lobby_name': all_lobbies[i].name
            }
            lobbies.append(lobby)
        if new_user.password == password_again :
            if not has_same_uid(new_user):
                new_user.save()
                return render(request, 'index.html', {
                    'Dict': json.dumps(dict1),
                    'lobbies': lobbies,
                    'form': form,
                })
            else:
                dict1['reg'] = '1'
                return render(request, 'index.html', {
                    'Dict': json.dumps(dict1),
                    'lobbies': lobbies,
                    'form': form,
                })
        else:
            dict1['reg'] = '2'
            return render(request, 'index.html', {
                'Dict': json.dumps(dict1),
                'lobbies': lobbies,
                'form': form,
            })
Beispiel #4
0
def register(request):
    if request.method == 'GET':
        from logic.models import User
        new_user = User()
        new_user.uid = request.GET['reg_user']
        new_user.password = request.GET['reg_password']
        password_again = request.GET['reg_password_again']
        new_user.name = request.GET['reg_name']
        new_user.lobby_id = 0
        new_user.iconnum = request.GET['iconnum']
        new_user.status = 10000
        new_user.latest_time = "2015-01-01 12:00:00"
        new_user.score = 0
        new_user.win_num = 0
        new_user.tie_num = 0
        new_user.lose_num = 0
        dict1 = {'login': '******', 'reg': '0'}
        form = RegisterForm()
        all_lobbies = Lobby.objects.all()
        lobbies = []
        lobby_length = all_lobbies.__len__()
        for i in range(0, lobby_length):
            user_num = User.objects.filter(lobby_id=(i + 1)).__len__()
            lobby = {'user_num': user_num, 'lobby_name': all_lobbies[i].name}
            lobbies.append(lobby)
        if new_user.password == password_again:
            if not has_same_uid(new_user):
                new_user.save()
                return render(request, 'index.html', {
                    'Dict': json.dumps(dict1),
                    'lobbies': lobbies,
                    'form': form,
                })
            else:
                dict1['reg'] = '1'
                return render(request, 'index.html', {
                    'Dict': json.dumps(dict1),
                    'lobbies': lobbies,
                    'form': form,
                })
        else:
            dict1['reg'] = '2'
            return render(request, 'index.html', {
                'Dict': json.dumps(dict1),
                'lobbies': lobbies,
                'form': form,
            })
Beispiel #5
0
def register(request):
    if request.method == 'GET':
        from logic.models import User
        new_user = User()
        new_user.uid = request.GET['reg_user']
        new_user.password = request.GET['reg_password']
        password_again = request.GET['reg_password_again']
        new_user.name = request.GET['reg_name']
        new_user.lobby_id = 0
        if new_user.password == password_again:
            if not has_same_uid(new_user):
                new_user.save()
                return HttpResponseRedirect("http://127.0.0.1:8000")
            else:
                return HttpResponse("same name!")
        else:
            return HttpResponse("两次密码输入不一致!")
Beispiel #6
0
def register(request):
    if request.method == 'GET':
        from logic.models import User
        new_user = User()
        new_user.uid = request.GET['reg_user']
        new_user.password = request.GET['reg_password']
        password_again = request.GET['reg_password_again']
        new_user.name = request.GET['reg_name']
        new_user.lobby_id = 0
        if new_user.password == password_again:
            if not has_same_uid(new_user):
                new_user.save()
                return HttpResponseRedirect("http://127.0.0.1:8000")
            else:
                return HttpResponse("same name!")
        else:
            return HttpResponse("两次密码输入不一致!")
Beispiel #7
0
def login(request):
    if request.method == 'POST':
        if request.session['has_loggedin']:
            from logic.models import User
            cur_user = User.objects.get(uid=request.session['uid'])
            userdict = {
                'uid': cur_user.uid,
                'name': cur_user.name,
                'iconnum': cur_user.iconnum
            }
            all_lobbies = Lobby.objects.all()
            lobbies = []
            lobby_length = all_lobbies.__len__()
            for i in range(0, lobby_length):
                lobby = {
                    'user_num':
                    User.objects.filter(lobby_id=(i + 1)).__len__(),
                    'lobby_name': all_lobbies[i].name
                }
                lobbies.append(lobby)
            into_lobby_form = IntoLobbyForm()
            return render(
                request, 'login_complete.html', {
                    'Dict': json.dumps(userdict),
                    'lobbies': lobbies,
                    'into_lobby_form': into_lobby_form,
                })
        from logic.models import User
        cur_user = User()
        form = RegisterForm(request.POST)
        if form.is_valid():
            username = form.cleaned_data['uid']
            password = form.cleaned_data['password']
            q = User.objects.filter(uid=username, password=password)
            if q.__len__() != 0:
                cur_user.name = q[0].name
                cur_user.uid = q[0].uid
                cur_user.iconnum = q[0].iconnum
                userdict = {
                    'uid': username,
                    'name': cur_user.name,
                    'iconnum': cur_user.iconnum
                }
                request.session['has_loggedin'] = True
                request.session['uid'] = cur_user.uid
                all_lobbies = Lobby.objects.all()
                lobbies = []
                lobby_length = all_lobbies.__len__()
                for i in range(0, lobby_length):
                    lobby = {
                        'user_num':
                        User.objects.filter(lobby_id=(i + 1)).__len__(),
                        'lobby_name': all_lobbies[i].name
                    }
                    lobbies.append(lobby)
                into_lobby_form = IntoLobbyForm()
                return render(
                    request, 'login_complete.html', {
                        'Dict': json.dumps(userdict),
                        'lobbies': lobbies,
                        'into_lobby_form': into_lobby_form,
                    })
            else:
                all_lobbies = Lobby.objects.all()
                lobbies = []
                lobby_length = all_lobbies.__len__()
                for i in range(0, lobby_length):
                    lobby = {
                        'user_num':
                        User.objects.filter(lobby_id=(i + 1)).__len__(),
                        'lobby_name': all_lobbies[i].name
                    }
                    lobbies.append(lobby)
                dict1 = {'login': '******', 'reg': '0'}
                return render(request, 'index.html', {
                    'Dict': json.dumps(dict1),
                    'lobbies': lobbies,
                    'form': form,
                })

    else:
        form = RegisterForm()
        all_lobbies = Lobby.objects.all()
        lobbies = []
        lobby_length = all_lobbies.__len__()
        for i in range(0, lobby_length):
            lobby = {
                'user_num': User.objects.filter(lobby_id=(i + 1)).__len__(),
                'lobby_name': all_lobbies[i].name
            }
            lobbies.append(lobby)
        return render_to_response("index.html", {
            'form': form,
            'lobbies': lobbies,
        },
                                  context_instance=RequestContext(request))
Beispiel #8
0
def login(request):
    if request.method == 'POST':
        if request.session['has_loggedin']:
            from logic.models import User
            cur_user = User.objects.get(uid=request.session['uid'])
            userdict = {'uid': cur_user.uid, 'name': cur_user.name, 'iconnum': cur_user.iconnum}
            all_lobbies = Lobby.objects.all()
            lobbies =[]
            lobby_length = all_lobbies.__len__()
            for i in range(0, lobby_length):
                 lobby = {
                    'user_num': User.objects.filter(lobby_id=(i+1)).__len__(),
                    'lobby_name': all_lobbies[i].name
                 }
                 lobbies.append(lobby)
            into_lobby_form = IntoLobbyForm()
            return render(request, 'login_complete.html', {
                'Dict': json.dumps(userdict),
                'lobbies': lobbies,
                'into_lobby_form': into_lobby_form,
            })
        from logic.models import User
        cur_user = User()
        form = RegisterForm(request.POST)
        if form.is_valid():
            username = form.cleaned_data['uid']
            password = form.cleaned_data['password']
            q = User.objects.filter(uid=username, password=password)
            if q.__len__() != 0:
                cur_user.name = q[0].name
                cur_user.uid = q[0].uid
                cur_user.iconnum = q[0].iconnum
                userdict = {'uid': username, 'name': cur_user.name, 'iconnum': cur_user.iconnum}
                request.session['has_loggedin'] = True
                request.session['uid'] = cur_user.uid
                all_lobbies = Lobby.objects.all()
                lobbies =[]
                lobby_length = all_lobbies.__len__()
                for i in range(0, lobby_length):
                    lobby = {
                        'user_num': User.objects.filter(lobby_id=(i+1)).__len__(),
                        'lobby_name': all_lobbies[i].name
                    }
                    lobbies.append(lobby)
                into_lobby_form = IntoLobbyForm()
                return render(request, 'login_complete.html', {
                    'Dict': json.dumps(userdict),
                    'lobbies': lobbies,
                    'into_lobby_form': into_lobby_form,
                })
            else:
                all_lobbies = Lobby.objects.all()
                lobbies = []
                lobby_length = all_lobbies.__len__()
                for i in range(0, lobby_length):
                    lobby = {
                        'user_num': User.objects.filter(lobby_id=(i+1)).__len__(),
                        'lobby_name': all_lobbies[i].name
                    }
                    lobbies.append(lobby)
                dict1 = {'login': '******', 'reg': '0'}
                return render(request, 'index.html', {
                    'Dict': json.dumps(dict1),
                    'lobbies': lobbies,
                    'form': form,
                })

    else:
        form = RegisterForm()
        all_lobbies = Lobby.objects.all()
        lobbies = []
        lobby_length = all_lobbies.__len__()
        for i in range(0, lobby_length):
            lobby = {
                'user_num': User.objects.filter(lobby_id=(i+1)).__len__(),
                'lobby_name': all_lobbies[i].name
            }
            lobbies.append(lobby)
        return render_to_response("index.html",
                            {'form': form, 'lobbies': lobbies, }, context_instance=RequestContext(request))