Example #1
0
def call_toss(request):
    game_url = request.session['game']['_id']
    if request.session['team'] == request.session['game']['team1']:
        description = "Enter an integer from 1 to 6. "
        description += "To win the toss, enter the integer in such a way that"
        description += " your opponent incorrectly guesses "
        description += "whether it is odd or even."
        return render(
            request, 'game/toss.html', {
                "description": description,
                "toss": Toss1(),
                "game_redirect": game_url,
                "stylesheet": choose.getTheme(),
            })
    elif request.session['team'] == request.session['game']['team2']:
        description = "Your opponent will enter an integer from 1 to 6. "
        description += "To win the toss, you have to correctly decide "
        description += "whether that number is odd or even."
        return render(
            request, 'game/toss.html', {
                "description": description,
                "toss": Toss2(),
                "game_redirect": game_url,
                "stylesheet": choose.getTheme(),
            })
def profile_view(request):
    if 'team' in request.session:
        signin = request.session['team']
        signin_action = "/profile/"
        return render(
            request, 'templates/profile.html', {
                "appbar": 'templates/appbar.html',
                "stylesheet": choose.getTheme(),
                "settingsicon": settings_icon,
                "signin": signin,
                "signin_action": signin_action
            })
    else:
        return HttpResponseRedirect('/login/')
Example #3
0
def open(request):
    signin = "Sign In"
    signin_action = "/login/"
    if 'team' in request.session:
        signin = request.session['team']
        signin_action = "/profile/"
    return render(
        request, 'docs/license.html', {
            "appbar": 'templates/appbar.html',
            "settingsicon": settings_icon,
            "signin": signin,
            "signin_action": signin_action,
            "stylesheet": choose.getTheme()
        })
Example #4
0
def form_view(request):
    if request.method == "POST":
        postform = CloseAccountForm(request.POST)
        if postform.is_valid():
            try:
                user_team_name = request.session['team']
                database = mongo_client.getConnection()
                if not mongo_client.ifCollectionExists(database, "accounts"):
                    database.create_collection("accounts")
                accounts = database.get_collection("accounts")
                param = dict(_id=user_team_name)
                team_data_json = accounts.find_one(param)
                if(team_data_json['isHuman']):
                    isHuman = "Human"
                else:
                    isHuman = "Bot"
                form = EditprofileForm({
                    "team_name": request.session['team'],
                    "member1": team_data_json['team_members'][0],
                    "member2": team_data_json['team_members'][1],
                    "member3": team_data_json['team_members'][2],
                    "member4": team_data_json['team_members'][3],
                    "member5": team_data_json['team_members'][4],
                    "member6": team_data_json['team_members'][5],
                    "member7": team_data_json['team_members'][6],
                    "member8": team_data_json['team_members'][7],
                    "member9": team_data_json['team_members'][8],
                    "member10": team_data_json['team_members'][9],
                    "member11": team_data_json['team_members'][10],
                    "password": postform.cleaned_data['password'],
                    "Account_type": isHuman
                })
                signin = request.session['team']
                signin_action = "/profile/"
                return render(
                    request, 
                    'templates/editteam.html', 
                    {
                        "appbar": 'templates/appbar.html',
                        "form": form,
                        "stylesheet": choose.getTheme(),
                        "settingsicon": settings_icon,
                        "signin": signin,
                        "signin_action": signin_action
                    }
                )
            except:
                return HttpResponseRedirect('/login/')
Example #5
0
def profile_view(request):
    if 'team' in request.session:
        signin = request.session['team']
        signin_action = "/profile/"
        form = CloseAccountForm()
        return render(
            request, 'templates/closeaccount.html', {
                "appbar": 'templates/appbar.html',
                "stylesheet": choose.getTheme(),
                "form": form,
                "settingsicon": settings_icon,
                "warningicon": mark_icon,
                "signin": signin,
                "signin_action": signin_action
            })
    else:
        return HttpResponseRedirect('/login/')
Example #6
0
def close(request):
    if request.method == "POST":
        form = CloseAccountForm(request.POST)
        if form.is_valid():
            try:
                user_team_name = request.session['team']
                user_password = form.cleaned_data['password']
                database = mongo_client.getConnection()
                if not mongo_client.ifCollectionExists(database, "accounts"):
                    database.create_collection("accounts")
                accounts = database.get_collection("accounts")
                param = dict(_id=user_team_name)
                team_data_json = accounts.find_one(param)
                if check_password(user_password, team_data_json['team_key']):
                    # Close the team account
                    accounts.update_one({"_id": request.session['team']},
                                        {"$set": {
                                            "online": False
                                        }})
                    accounts.update_one({"_id": request.session['team']},
                                        {"$set": {
                                            "disabled": True
                                        }})
                    del request.session['team']
                    return HttpResponseRedirect('/')
                else:
                    return HttpResponseRedirect('/login/')
            except:
                return HttpResponseRedirect('/login/')
        else:
            return HttpResponseRedirect('/login/')
    else:
        signin = "Sign In"
        signin_action = "/login/"
        if 'team' in request.session:
            signin = request.session['team']
            signin_action = "/profile/"
        return render(
            request, 'templates/lobby.html', {
                "appbar": 'templates/appbar.html',
                "stylesheet": choose.getTheme(),
                "settingsicon": settings_icon,
                "signin": signin,
                "signin_action": signin_action
            })
def initial(request):
    signin = "Sign In"
    signin_action = "/login/"
    if 'team' in request.session:
        signin = request.session['team']
        signin_action = "/profile/"
    return render(
        request, 
        'game/setup.html', 
        {
            "appbar": 'templates/appbar.html',
            "form": setupform.GameSetup(),
            "setup_location": "/setup/ai/play/",
            "stylesheet": choose.getTheme(),
            "settingsicon": settings_icon,
            "signin": signin,
            "signin_action": signin_action
        }
    )
def response_500(request):
    data = {"name": "test"}
    return render(request, 'oops/500.html', {
        "notice_icon": mark_icon,
        "stylesheet": getTheme()
    })
Example #9
0
def response_404(request, exception):
    data = {"name": "test"}
    return render(request, 'oops/404.html', {
        "notice_icon": mark_icon,
        "stylesheet": getTheme()
    })
def profile_view(request, teamname):
    if 'team' in request.session:
        signin = request.session['team']
    else:
        signin = "Sign In"
    signin_action = "/profile/"
    try:
        team_data = getTeam(teamname)
        if team_data['disabled']:
            return render(
                request, 'account/closed.html', {
                    "appbar": 'templates/appbar.html',
                    "teamname": teamname,
                    "teamstatus": "This account is closed.",
                    "gamedata": None,
                    "stylesheet": choose.getTheme(),
                    "settingsicon": settings_icon,
                    "signin": signin,
                    "signin_action": signin_action
                })
        else:
            notSameProfile = 'team' not in request.session or request.session[
                'team'] != teamname
            if notSameProfile:
                if team_data['tosViolation']:
                    return render(
                        request, 'account/marked.html', {
                            "appbar":
                            'templates/appbar.html',
                            "stats":
                            "account/openprofiles.html",
                            "teamname":
                            teamname,
                            "notice_icon":
                            mark_icon,
                            "membersince":
                            str(datetime.date.fromtimestamp(1600000000)),
                            "lastactive":
                            "1 month ago",
                            "gamedata":
                            None,
                            "stylesheet":
                            choose.getTheme(),
                            "settingsicon":
                            settings_icon,
                            "signin":
                            signin,
                            "signin_action":
                            signin_action
                        })
                else:
                    return render(
                        request, 'account/good.html', {
                            "appbar":
                            'templates/appbar.html',
                            "stats":
                            "account/openprofiles.html",
                            "teamname":
                            teamname,
                            "membersince":
                            str(datetime.date.fromtimestamp(1600000000)),
                            "lastactive":
                            "1 month ago",
                            "gamedata":
                            None,
                            "stylesheet":
                            choose.getTheme(),
                            "settingsicon":
                            settings_icon,
                            "signin":
                            signin,
                            "signin_action":
                            signin_action
                        })
            else:
                return render(
                    request, 'account/good.html', {
                        "appbar": 'templates/appbar.html',
                        "stats": "account/openprofiles.html",
                        "teamname": teamname,
                        "membersince": str(
                            datetime.date.fromtimestamp(1600000000)),
                        "lastactive": "1 month ago",
                        "gamedata": None,
                        "stylesheet": choose.getTheme(),
                        "settingsicon": settings_icon,
                        "signin": signin,
                        "signin_action": signin_action
                    })
    except:
        raise Http404()
Example #11
0
def form_view(request) -> render:
    if request.method == "POST":
        form = SignupForm(request.POST)
        if form.is_valid():
            if canBeUsed(form.cleaned_data['member1'], reservedWords):
                try:
                    isHuman = True
                    if form.cleaned_data['Account_type'] == "Bot":
                        isHuman = False
                    team_data_json = {
                        "_id":
                        form.cleaned_data['team_name'],
                        "team_name":
                        form.cleaned_data['team_name'],
                        "team_members": [
                            form.cleaned_data['member1'],
                            form.cleaned_data['member2'],
                            form.cleaned_data['member3'],
                            form.cleaned_data['member4'],
                            form.cleaned_data['member5'],
                            form.cleaned_data['member6'],
                            form.cleaned_data['member7'],
                            form.cleaned_data['member8'],
                            form.cleaned_data['member9'],
                            form.cleaned_data['member10'],
                            form.cleaned_data['member11']
                        ],
                        "games_played":
                        0,
                        "games_won":
                        0,
                        "games_lost":
                        0,
                        "tests_tied":
                        0,
                        "team_key":
                        make_password(form.cleaned_data['password']),
                        "online":
                        True,
                        "hasSuperOver":
                        False,
                        "disabled":
                        False,
                        "tosViolation":
                        False,
                        "isModerator":
                        False,
                        "isHuman":
                        isHuman
                    }
                    database = mongo_client.getConnection()
                    if not mongo_client.ifCollectionExists(
                            database, "accounts"):
                        database.create_collection("accounts")
                    accounts = database.get_collection("accounts")
                    accounts.insert_one(team_data_json)
                    request.session['team'] = form.cleaned_data['team_name']
                    return HttpResponseRedirect('/profile/')
                except:
                    return HttpResponseRedirect('/signup/')
            else:
                return HttpResponseRedirect('/signup/')
        else:
            return HttpResponseRedirect('/signup/')
    else:
        form = SignupForm()
        return render(request, 'templates/register.html', {
            "form": form,
            "stylesheet": choose.getTheme()
        })
Example #12
0
def form_view(request):
    if request.method == "POST":
        form = LoginForm(request.POST)
        if form.is_valid():
            try:
                user_team_name = form.cleaned_data['team_name']
                user_password = form.cleaned_data['password']
                database = mongo_client.getConnection()
                if not mongo_client.ifCollectionExists(database, "accounts"):
                    database.create_collection("accounts")
                accounts = database.get_collection("accounts")
                param = dict(_id=user_team_name)
                team_data_json = accounts.find_one(param)
                if check_password(user_password, team_data_json['team_key']):
                    if team_data_json['disabled']:
                        # This team is closed.
                        if team_data_json['tosViolation']:
                            text = "Your team was closed by the moderators. "
                            # Closed by moderators
                            return render(
                                request, 
                                'templates/closed.html', 
                                {
                                    "appbar": 'templates/appbar.html',
                                    "form": None,
                                    "info": text,
                                    "settingsicon": settings_icon,
                                    "signin": "Sign In",
                                    "onsubmit": "displaynone",
                                    "warningicon": mark_icon,
                                    "stylesheet": choose.getTheme()
                                }
                            )
                        else:
                            # Closed by team
                            text = "If you closed your team, but have since "
                            text += "changed your mind, you get one chance "
                            text += "of getting your team back.\n\n"
                            text += "This will work only once\n\n"
                            text += "If you close your team a second time, "
                            text += "there will be no way of recovering it."
                            text += "\n\nTo recover your team, "
                            text += "enter your team name and password "
                            text += "in the form below and click on "
                            text += "'REOPEN TEAM'."
                            return render(
                                request, 
                                'templates/closed.html', 
                                {
                                    "appbar": 'templates/appbar.html',
                                    "form": form,
                                    "info": text,
                                    "settingsicon": settings_icon,
                                    "signin": "Sign In",
                                    "onsubmit": "displayblock",
                                    "warningicon": mark_icon,
                                    "stylesheet": choose.getTheme()
                                }
                            )
                    else:
                        # Login
                        accounts.update_one({"_id": user_team_name}, { "$set": {"online": True}})
                        request.session['team'] = form.cleaned_data['team_name']
                        return HttpResponseRedirect('/')
                else:
                    return HttpResponseRedirect('/login/')
            except:
                return HttpResponseRedirect('/login/')
        else:
            return HttpResponseRedirect('/login/')
    else:
        form = LoginForm()
        return render(request, 'templates/login.html', {"form": form, "stylesheet": choose.getTheme()})