Пример #1
0
def update(request):
    if request.method == "POST":
        form = EditprofileForm(request.POST)
        if form.is_valid():
            team_data_json = {
                        "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']
                        ],
                        "team_key": make_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")
            accounts.update_one({"_id": request.session['team']}, { "$set": {"team_members": team_data_json["team_members"]}})
            accounts.update_one({"_id": request.session['team']}, { "$set": {"team_key": team_data_json["team_key"]}})
            return HttpResponseRedirect('/')
Пример #2
0
def generate_game(team1, team2, isTest, overs, wickets, days):
    followon = 0
    if isTest:
        overs = math.inf
        if days == 1:
            followon = 75
        elif days == 2:
            followon = 100
        elif days == 3 or days == 4:
            followon = 150
        elif days > 4:
            followon = 200
    else:
        days = 0
    game_data_json = {
        "_id": returnGameId(),
        "team1": team1['team_name'],
        "team2": team2['team_name'],
        "isTest": isTest,
        "overs": overs,
        "wickets": wickets,
        "followon": followon,
        "toss": None,
        "toss_decision": None,
        "completed": False,
        "innings": [],
        "margin": "Game is yet to start.",
        "winner": None,
    }
    database = mongo_client.getConnection()
    if not mongo_client.ifCollectionExists(database, "games"):
        database.create_collection("games")
    games = database.get_collection("games")
    games.insert_one(game_data_json)
    return game_data_json
def logout(request):
    database = mongo_client.getConnection()
    if not mongo_client.ifCollectionExists(database, "accounts"):
        database.create_collection("accounts")
    accounts = database.get_collection("accounts")
    accounts.update_one({"_id": request.session['team']},
                        {"$set": {
                            "online": False
                        }})
    if 'team' in request.session:
        del request.session['team']
    return HttpResponseRedirect('/')
def getTeam(teamname):
    if teamname == "Anonymous":
        team_data_json = Anonymous.Anonymous
    elif teamname == "Computer":
        team_data_json = Computer.Anonymous
    else:
        user_team_name = teamname
        database = mongo_client.getConnection()
        accounts = database.get_collection("accounts")
        param = dict(_id=user_team_name)
        team_data_json = accounts.find_one(param)
    return team_data_json
Пример #5
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/')
Пример #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
            })
Пример #7
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()
        })
Пример #8
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()})