Esempio n. 1
0
    def post(self):

        name, pass1, pass2, email = self.getThese("register-name",
                                                  "register-pass1",
                                                  "register-pass2",
                                                  "register-email")

        error_messages = validate_register(name, pass1, pass2, email)

        new_id = None

        if len(error_messages) == 0:
            user = SiteUser(username=name.lower(),
                            password=security.make_pw_hash(
                                name, pass1, security.make_salt()),
                            email=email)
            user.put()
            new_id = user.key()

            # Log the user in when they register.
            self.response.headers.add_header(
                'Set-Cookie',
                str('user_name=%s' % security.make_cookie_data(name.lower())))

            # Redirect to the welcome page
            self.redirect("/welcome?action=register")

        self.render("register.html",
                    new_id=new_id,
                    error_messages=error_messages,
                    form_user_name=name,
                    form_email=email)
Esempio n. 2
0
    def post(self):

        name, pass1, pass2, email = self.getThese("register-name", "register-pass1", "register-pass2", "register-email")

        error_messages = validate_register(name, pass1, pass2, email)

        new_id = None

        if len(error_messages) == 0:
            user = SiteUser(
                username=name.lower(), password=security.make_pw_hash(name, pass1, security.make_salt()), email=email
            )
            user.put()
            new_id = user.key()

            # Log the user in when they register.
            self.response.headers.add_header(
                "Set-Cookie", str("user_name=%s" % security.make_cookie_data(name.lower()))
            )

            # Redirect to the welcome page
            self.redirect("/welcome?action=register")

        self.render(
            "register.html", new_id=new_id, error_messages=error_messages, form_user_name=name, form_email=email
        )
Esempio n. 3
0
def get_rankings():
    rankings = []

    players = SiteUser.all()
    for player in players:

        wins = 0
        losses = 0
        for x in player.games:
            if x.game.game_state == 'complete':
                if x.is_winner:
                    wins += 1
                else:
                    losses += 1

        win_average = wins / (wins + losses) if (wins + losses) != 0 else 0

        rankings.append((player.username, wins, losses, win_average))

    # Sort by wins. If equal, breka ties with win frequency.
    # Sort by losses if both are equal (people with more
    # experience are ranked higher)
    rankings.sort(key=lambda tuple: (tuple[1], tuple[3], tuple[2]),
                  reverse=True)

    return rankings
Esempio n. 4
0
def get_rankings():
    rankings = []

    players = SiteUser.all()
    for player in players:

        wins = 0
        losses = 0
        for x in player.games:
            if x.game.game_state == 'complete':
                if x.is_winner:
                    wins += 1
                else:
                    losses += 1

        win_average = wins / (wins + losses) if (wins + losses) != 0 else 0

        rankings.append((player.username, wins, losses, win_average))

    # Sort by wins. If equal, breka ties with win frequency.
    # Sort by losses if both are equal (people with more
    # experience are ranked higher)
    rankings.sort(
        key=lambda tuple: (tuple[1], tuple[3], tuple[2]), reverse=True)

    return rankings
Esempio n. 5
0
    def get(self):
        """Send a reminder email to each User with an email about games.
        Called every hour using a cron job"""

        app_id = app_identity.get_application_id()
        users = SiteUser.all()

        num_created = 1

        for user in users:
            if user.email is not None and user.email != "":
                for usergame in user.games:

                    should_send_email = False

                    subject = ""
                    body = ""

                    username = user.username
                    gamename = usergame.game.game_name

                    if usergame.game.game_state == "created":
                        should_send_email = True
                        subject = ("Reminder: You haven't started playing" +
                                   " your snakes and ladders game! " +
                                   str(num_created))
                        body = ("Hi there " + username + ". Please view your" +
                                " game " + gamename + " and get some people " +
                                "playing.")

                    elif (usergame.game.game_state == "playing" and
                          (usergame.player_num ==
                           usergame.game.current_player_num)):
                        should_send_email = True
                        subject = ("Reminder: Keep playing snakes and" +
                                   " ladders! You have an unfinished game. " +
                                   str(num_created))
                        body = ("Hi there " + username + ". Please view your" +
                                " game " + gamename + " and play your turn.")

                    if should_send_email:
                        num_created += 1
                        # This will send test emails:
                        # from, to, subject, body
                        mail.send_mail(
                            'noreply@{}.appspotmail.com'.format(app_id),
                            user.email,
                            subject,
                            body)

        self.response.set_status(204)
Esempio n. 6
0
    def get(self):
        """Send a reminder email to each User with an email about games.
        Called every hour using a cron job"""

        app_id = app_identity.get_application_id()
        users = SiteUser.all()

        num_created = 1

        for user in users:
            if user.email is not None and user.email != "":
                for usergame in user.games:

                    should_send_email = False

                    subject = ""
                    body = ""

                    username = user.username
                    gamename = usergame.game.game_name

                    if usergame.game.game_state == "created":
                        should_send_email = True
                        subject = ("Reminder: You haven't started playing" +
                                   " your snakes and ladders game! " +
                                   str(num_created))
                        body = ("Hi there " + username + ". Please view your" +
                                " game " + gamename + " and get some people " +
                                "playing.")

                    elif (usergame.game.game_state == "playing"
                          and (usergame.player_num
                               == usergame.game.current_player_num)):
                        should_send_email = True
                        subject = ("Reminder: Keep playing snakes and" +
                                   " ladders! You have an unfinished game. " +
                                   str(num_created))
                        body = ("Hi there " + username + ". Please view your" +
                                " game " + gamename + " and play your turn.")

                    if should_send_email:
                        num_created += 1
                        # This will send test emails:
                        # from, to, subject, body
                        mail.send_mail(
                            'noreply@{}.appspotmail.com'.format(app_id),
                            user.email, subject, body)

        self.response.set_status(204)
Esempio n. 7
0
    def post(self):
        delete_users, delete_posts = self.getThese("delete_users",
                                                   "delete_posts")

        if delete_users is not None:
            users = SiteUser.all()
            for user in users:
                user.delete()

        if delete_posts is not None:
            posts = BlogPost.all()
            print "Post is", posts
            for one_post in posts:
                one_post.delete()

        self.render("admin.html", True)
Esempio n. 8
0
    def post(self):
        delete_users, delete_posts = self.getThese(
            "delete_users",
            "delete_posts")

        if delete_users is not None:
            users = SiteUser.all()
            for user in users:
                user.delete()

        if delete_posts is not None:
            posts = BlogPost.all()
            print "Post is", posts
            for one_post in posts:
                one_post.delete()

        self.render("admin.html", True)