Пример #1
0
 def get(self):
     rnd = self.request.get('round')
     _id = self.request.get('id')
     name = ''
     ret = '[]'
     if rnd in ('speed', 'accuracy'):
         ind = Individual.query(Individual.assigned_id == _id,
                                Individual.year == YEAR)
         if ind.count() > 0:
             ind = ind.fetch()[0]
             name = ind.name + '|' + Team.get_by_id(ind.team).name
             if rnd == 'speed':
                 ret = ind.speed_scores
             else:
                 ret = ind.accuracy_scores
     else:
         team = Team.query(Team.assigned_id == _id)
         if team.count() > 0:
             team = team.fetch()[0]
             name = team.name
             if rnd == 'team':
                 ret = team.team_scores
             else:
                 if team.guts_scores is None:
                     ret = []
                 else:
                     ret = team.guts_scores
     self.response.headers['Content-Type'] = 'application/json'
     self.response.write(json.dumps({'scores': ret, 'name': name}))
Пример #2
0
    def get(self):
        rnd = self.request.get('round')
        _id = self.request.get('id')
        name = ''
        ret = '[]'
        if rnd in ('speed', 'accuracy'):
            ind = Individual.query(Individual.assigned_id == _id, Individual.year == YEAR)
            if ind.count() > 0:
                ind = ind.fetch()[0]
                name = ind.name + '|' + Team.get_by_id(ind.team).name
                if rnd == 'speed':
                    ret = ind.speed_scores
                else:
                    ret = ind.accuracy_scores
        else:
            team = Team.query(Team.assigned_id == _id)
            if team.count() > 0:
                team = team.fetch()[0]
                name = team.name
                if rnd == 'team':
                    ret = team.team_scores
                else:
		    if team.guts_scores is None:
                        ret = []
                    else:
                        ret = team.guts_scores
        self.response.headers['Content-Type'] = 'application/json'
        self.response.write(json.dumps({
            'scores': ret,
            'name': name
        }))
Пример #3
0
    def get(self):

        # Create and insert a record
        # for this registration.
        record = Team(user=self.auth.get_user_by_session()['user_id'],
                      paid=False,
                      year=YEAR)
        record.put()

        # Inform the client of success.
        self.response.headers['Content-Type'] = 'application/json'
        self.response.write(json.dumps({'id': record.key.id()}))
Пример #4
0
    def get(self):
        ids = json.loads(self.request.get('ids'))
        record = Team(user=-1,
                      paid=False,
                      name="Individual Team",
                      year=get_year())
        record.put()
        for i in ids:
            indiv = Individual.get_by_id(i)
            indiv.team = record.key.id()
            indiv.put()

        self.response.headers['Content-Type'] = 'application/json'
        self.response.write(json.dumps({"success": True}))
Пример #5
0
    def post(self):
        user_email = self.request.get('user_email')

        user_query = LegacyUser.query(LegacyUser.email == user_email)
        user = user_query.get()
        user_id = None

        if user is None:
            self.response.headers['Content-Type'] = 'application/json'
            self.response.write(json.dumps({
                'success': False
            }))
            return
        else:
            user_id = user.key.id()

        team_name = self.request.get('team_name')
        members = json.loads(self.request.get('members'))

        team = Team(
            name = team_name,
            user = user_id,
            guts_scores = self.request.get('guts_scores'),
            team_scores = self.request.get('team_scores'),
            paid = False,
            year = 2013
        )
        team.put()

        team_id = team.key.id()

        for member in members:
            individual = Individual(
                name = member['name'],
                team = team_id,
                user = user_id,
                paid = True,
                year = 2013,

                speed_scores = member['speed_scores'],
                accuracy_scores = member['accuracy_scores']
            )

            individual.put()

        self.response.headers['Content-Type'] = 'application/json'
        self.response.write(json.dumps({
            'success': True
        }))
Пример #6
0
    def get(self):

        # Create and insert a record
        # for this registration.
        record = Team(
            user = self.auth.get_user_by_session()['user_id'],
            paid = False,
            year = YEAR
        )
        record.put()

        # Inform the client of success.
        self.response.headers['Content-Type'] = 'application/json'
        self.response.write(json.dumps({
            'id': record.key.id()
        }))
Пример #7
0
    def get(self):
        ids = json.loads(self.request.get('ids'))
        record = Team(
            user = -1,
            paid = False,
            name = "Individual Team",
            year = get_year()
        )
        record.put()
        for i in ids:
            indiv = Individual.get_by_id(i)
            indiv.team = record.key.id()
            indiv.put()

        self.response.headers['Content-Type'] = 'application/json'
        self.response.write(json.dumps({"success": True}))
Пример #8
0
    def get(self):
        teams = {}
        individuals = []

        # Create and insert a record
        # for this registration.
        user = self.auth.get_user_by_session()['user_id']
        query = Individual.query(Individual.user == user)

        for member in query:
            if member.team != -1:
                if member.team in teams:
                    teams[member.team]['members'].append(
                        member.serialize_full())
                else:
                    teams[member.team] = {'members': [member.serialize_full()]}
            else:
                individuals.append(member.serialize_full())

        for team_id in teams:
            record = Team.get_by_id(team_id)
            teams[team_id]['name'] = record.name
            teams[team_id]['id'] = int(team_id)
            teams[team_id]['paid'] = record.paid
            teams[team_id]['year'] = record.year
            teams[team_id]['guts_scores'] = parse_or_none(record.guts_scores)
            teams[team_id]['team_scores'] = parse_or_none(record.team_scores)

        # Inform the client of success.
        self.response.headers['Content-Type'] = 'application/json'
        self.response.write(
            json.dumps({
                'teams': teams,
                'individuals': individuals
            }))
Пример #9
0
    def get(self):
        team = Team.get_by_id(int(self.request.get('id')))
        team.name = self.request.get('name')
        team.put()

        self.response.headers['Content-Type'] = 'application/json'
        self.response.write(json.dumps({'success': True}))
Пример #10
0
    def get(self):
        team = Team.get_by_id(int(self.request.get('id')))
        team.name = self.request.get('name')
        team.put()

        self.response.headers['Content-Type'] = 'application/json'
        self.response.write(json.dumps({'success': True}))
Пример #11
0
    def get(self):
        teams = Team.query(Team.year == get_year()).fetch()
        individuals = Individual.query(Individual.year == get_year()).fetch()
        teamsDict = {}

        for team in teams:
            if team.assigned_id is not None and len(team.assigned_id) > 0:
                teamsDict[team.key.id()] = {
                    'id': team.assigned_id,
                    'name': team.name,
                    'team_scores': parse_or_none(team.team_scores),
                    'guts_scores': parse_or_none(team.guts_scores),
                    'members': []
                }

        for individual in individuals:
            if individual.team > 0 and individual.team in teamsDict:
                teamsDict[individual.team]["members"].append({
                    'name':
                    individual.name,
                    'id':
                    individual.assigned_id,
                    'speed_scores':
                    json.loads(individual.speed_scores if (
                        individual.speed_scores is not None) else 'null'),
                    'accuracy_scores':
                    json.loads(individual.accuracy_scores if (
                        individual.accuracy_scores is not None) else 'null')
                })

        self.response.headers['Content-Type'] = 'application/json'
        self.response.write(json.dumps(teamsDict))
Пример #12
0
    def get(self):
        teams = Team.query(Team.year == get_year()).fetch()
        individuals = Individual.query(Individual.year == get_year()).fetch()
        teamsDict = {}

        for team in teams:
            if team.assigned_id is not None and len(team.assigned_id) > 0:
                teamsDict[team.key.id()] = {
                    'id': team.assigned_id,
                    'name': team.name,
                    'team_scores': parse_or_none(team.team_scores),
                    'guts_scores': parse_or_none(team.guts_scores),
                    'members': []
                }

        for individual in individuals:
            if individual.team > 0 and individual.team in teamsDict:
                teamsDict[individual.team]["members"].append({
                    'name': individual.name,
                    'id': individual.assigned_id,
                    'speed_scores': json.loads(individual.speed_scores if (individual.speed_scores is not None) else 'null'),
                    'accuracy_scores': json.loads(individual.accuracy_scores if (individual.accuracy_scores is not None) else 'null')
                })

        self.response.headers['Content-Type'] = 'application/json'
        self.response.write(json.dumps(teamsDict))
Пример #13
0
    def get(self):
        teams = {}
        individuals = []

        # Create and insert a record
        # for this registration.
        user = self.auth.get_user_by_session()['user_id']
        query = Individual.query(Individual.user == user)

        for member in query:
            if member.team != -1:
                if member.team in teams:
                    teams[member.team]['members'].append(member.serialize_full())
                else:
                    teams[member.team] = {
                       'members': [member.serialize_full()]
                    }
            else:
                individuals.append(member.serialize_full())

        for team_id in teams:
            record = Team.get_by_id(team_id)
            teams[team_id]['name'] = record.name
            teams[team_id]['id'] = int(team_id)
            teams[team_id]['paid'] = record.paid
            teams[team_id]['year'] = record.year
            teams[team_id]['guts_scores'] = parse_or_none(record.guts_scores)
            teams[team_id]['team_scores'] = parse_or_none(record.team_scores)

        # Inform the client of success.
        self.response.headers['Content-Type'] = 'application/json'
        self.response.write(json.dumps({
            'teams': teams,
            'individuals': individuals
        }))
Пример #14
0
    def get(self):
        old_id = int(self.request.get('primary_id'))
        new_id = self.request.get('assigned_id')
        team = Team.get_by_id(old_id)
        team.assigned_id = new_id
        team.put()

        self.response.headers['Content-Type'] = 'application/json'
        self.response.write(json.dumps({'success': True}))
Пример #15
0
 def get(self):
     teams = Team.query(Team.year == get_year()).fetch()
     ret = []
     for team in teams:
         if team.name is not None and team.assigned_id is not None and len(
                 team.assigned_id) > 0:
             ret.append({'name': team.name, 'scores': team.guts_scores})
     self.response.headers['Content-Type'] = 'application/json'
     self.response.write(json.dumps({'teams': ret}))
Пример #16
0
    def get(self):
        old_id = int(self.request.get('primary_id'))
        new_id = self.request.get('assigned_id')
        team = Team.get_by_id(old_id)
        team.assigned_id = new_id
        team.put()

        self.response.headers['Content-Type'] = 'application/json'
        self.response.write(json.dumps({'success': True}))
Пример #17
0
    def post(self):
        email = self.request.get('email')
        password = self.request.get('password')

        success = True
        problem = ""
        query = LegacyUser.query(LegacyUser.email == email)

        if query.count() == 0:
            try:
                u = self.auth.get_user_by_password(email, password, remember=True, save_session=True)
                print u
            except (InvalidAuthIdError, InvalidPasswordError) as e:
                success = False
                problem = str(type(e))
        else:
            user = query.get()
            salt = user.salt
            _hash = user.hash
            hashfun = hashlib.sha512()
            hashfun.update(salt)
            hashfun.update(password.encode())
            hashval = hashfun.hexdigest()
            if hashval == _hash:
                success = True
                user_data = self.user_model.create_user(email,
                    password_raw=password, institution=user.institution)
                if not user_data[0]:
                    success = False
                else:
                    # Re-attribute any teams belonging to the legacy user
                    # to the new user.
                    query = Team.query(Team.user == user.key.id())
                    for team in query:
                        print 'Reattributing ' + team.name
                        team.user = user_data[1].key.id()
                        team.put()

                    query = Individual.query(Individual.user == user.key.id())
                    for individual in query:
                        print 'Reattributing ' + individual.name
                        individual.user = user_data[1].key.id()
                        individual.put()

                    self.auth.set_session(self.auth.store.user_to_dict(user_data[1]), remember=True)
                user.key.delete()
            else:
                success = False
                problem = 'InvalidPasswordError'

        self.response.headers['Content-Type'] = 'application/json'
        self.response.write(json.dumps({
            'success': success,
            'problem': problem
        }))
Пример #18
0
    def get(self):
        users = self.user_model.query(self.user_model.team_updated >= (
            datetime.datetime.today() - datetime.timedelta(hours=1))).fetch()
        for user in users:
            teams = {}
            individuals = []

            query = Individual.query(Individual.user == user.key.id(),
                                     Individual.year == YEAR)

            for member in query:
                if member.team != -1:
                    if member.team in teams:
                        teams[member.team]['members'].append(
                            member.serialize())
                    else:
                        teams[member.team] = {'members': [member.serialize()]}
                else:
                    individuals.append(member.serialize())

            for team_id in teams:
                record = Team.get_by_id(team_id)
                teams[team_id]['name'] = record.name
            values = teams.values()
            body = ""
            for team in values:
                body += """
%s

%s
%s
%s
%s
                """ % (team['name'], team['members'][0], team['members'][1],
                       team['members'][2], team['members'][3])
            if len(individuals) > 0:
                body += """
Individuals

"""
                for individual in individuals:
                    body += individual + '\n'
            mail.send_mail(
                sender=
                'Exeter Math Club Competition <*****@*****.**>',
                to=user.auth_ids[0],
                subject='EMCC Team Information Change',
                body="""Hi,

This email is to confirm that you have made changes to your registered teams and the list of teams and individuals registered is now:
%s

Best,
Exeter Math Club Competition""" % (body, ))
Пример #19
0
    def post(self):
        user_email = self.request.get('user_email')

        user_query = LegacyUser.query(LegacyUser.email == user_email)
        user = user_query.get()
        user_id = None

        if user is None:
            self.response.headers['Content-Type'] = 'application/json'
            self.response.write(json.dumps({'success': False}))
            return
        else:
            user_id = user.key.id()

        team_name = self.request.get('team_name')
        members = json.loads(self.request.get('members'))

        team = Team(name=team_name,
                    user=user_id,
                    guts_scores=self.request.get('guts_scores'),
                    team_scores=self.request.get('team_scores'),
                    paid=False,
                    year=2013)
        team.put()

        team_id = team.key.id()

        for member in members:
            individual = Individual(name=member['name'],
                                    team=team_id,
                                    user=user_id,
                                    paid=True,
                                    year=2013,
                                    speed_scores=member['speed_scores'],
                                    accuracy_scores=member['accuracy_scores'])

            individual.put()

        self.response.headers['Content-Type'] = 'application/json'
        self.response.write(json.dumps({'success': True}))
Пример #20
0
 def get(self):
     teams = Team.query(Team.year == get_year()).fetch()
     ret = []
     for team in teams:
         if team.name is not None and team.assigned_id is not None and len(team.assigned_id) > 0:
             ret.append({
                 'name': team.name,
                 'scores': team.guts_scores
                 })
     self.response.headers['Content-Type'] = 'application/json'
     self.response.write(json.dumps({
         'teams': ret
     }))
Пример #21
0
    def get(self):
        users = self.user_model.query(self.user_model.team_updated >= (datetime.datetime.today() - datetime.timedelta(hours=1))).fetch()
        for user in users:
            teams = {}
            individuals = []

            query = Individual.query(Individual.user == user.key.id(), Individual.year == YEAR)

            for member in query:
                if member.team != -1:
                    if member.team in teams:
                        teams[member.team]['members'].append(member.serialize())
                    else:
                        teams[member.team] = {
                            'members': [member.serialize()]
                        }
                else:
                    individuals.append(member.serialize())

            for team_id in teams:
                record = Team.get_by_id(team_id)
                teams[team_id]['name'] = record.name
            values = teams.values()
            body = ""
            for team in values:
                body += """
%s

%s
%s
%s
%s
                """ % (team['name'], team['members'][0], team['members'][1], team['members'][2], team['members'][3])
            if len(individuals) > 0:
                body += """
Individuals

"""
                for individual in individuals:
                    body += individual + '\n'
            mail.send_mail(sender='Exeter Math Club Competition <*****@*****.**>',
                    to=user.auth_ids[0],
                    subject='EMCC Team Information Change',
                    body="""Hi,

This email is to confirm that you have made changes to your registered teams and the list of teams and individuals registered is now:
%s

Best,
Exeter Math Club Competition""" % (body,))
Пример #22
0
 def post(self):
     password = self.request.get('password')
     problem = ''
     success = True
     if password != 'adidasTwilight':
         success = False
         problem = 'password'
     else:
         rnd = self.request.get('round')
         _id = self.request.get('id')
         score = self.request.get('score')
         if rnd in ('speed', 'accuracy'):
             ind = Individual.query(Individual.assigned_id == _id,
                                    Individual.year == YEAR)
             if ind.count() != 0:
                 ind = ind.fetch()[0]
                 if rnd == 'speed':
                     ind.speed_scores = score
                 else:
                     ind.accuracy_scores = score
                 ind.put()
             else:
                 success = False
                 problem = 'id'
         else:
             team = Team.query(Team.assigned_id == _id)
             if team.count() != 0:
                 team = team.fetch()[0]
                 if rnd == 'team':
                     team.team_scores = score
                 else:
                     guts_round = int(self.request.get('guts_round'))
                     if team.guts_scores is None:
                         team.guts_scores = '[]'
                     loaded = json.loads(team.guts_scores)
                     loaded[guts_round * 3 - 3:guts_round *
                            3] = json.loads(score)
                     team.guts_scores = json.dumps(loaded)
                 team.put()
             else:
                 success = False
                 problem = 'id'
     self.response.headers['Content-Type'] = 'application/json'
     self.response.write(
         json.dumps({
             'success': success,
             'problem': problem
         }))
Пример #23
0
    def get(self):
        teams = Team.query(Team.year == get_year() - 1)

        teams_dict = {}

        for team in teams:
            team.year = get_year()
            individuals = Individual.query(Individual.team == team.key.id())
            for individual in individuals:
                individual.year = team.year
                individual.put()
            teams_dict[team.key.id()] = team.year
            team.put()

        self.response.headers['Content-Type'] = 'application/json'
        self.response.write(json.dumps({'teams': teams_dict}))
Пример #24
0
 def post(self):
     password = self.request.get('password')
     problem = ''
     success = True
     if password != 'adidasTwilight':
         success = False
         problem = 'password'
     else:
         rnd = self.request.get('round')
         _id = self.request.get('id')
         score = self.request.get('score')
         if rnd in ('speed', 'accuracy'):
             ind = Individual.query(Individual.assigned_id == _id, Individual.year == YEAR)
             if ind.count() != 0:
                 ind = ind.fetch()[0]
                 if rnd == 'speed':
                     ind.speed_scores = score
                 else:
                     ind.accuracy_scores = score
                 ind.put()
             else:
                 success = False
                 problem = 'id'
         else:
             team = Team.query(Team.assigned_id == _id)
             if team.count() != 0:
                 team = team.fetch()[0]
                 if rnd == 'team':
                     team.team_scores = score
                 else:
                     guts_round = int(self.request.get('guts_round'))
                     if team.guts_scores is None:
                         team.guts_scores = '[]'
                     loaded = json.loads(team.guts_scores)
                     loaded[guts_round*3-3:guts_round*3] = json.loads(score)
                     team.guts_scores = json.dumps(loaded)
                 team.put()
             else:
                 success = False
                 problem = 'id'
     self.response.headers['Content-Type'] = 'application/json'
     self.response.write(json.dumps({
         'success': success,
         'problem': problem
     }))
Пример #25
0
    def get(self):
        teams = Team.query(Team.year == get_year() - 1)

        teams_dict = {}

        for team in teams:
            team.year = get_year()
            individuals = Individual.query(Individual.team == team.key.id())
            for individual in individuals:
                individual.year = team.year
                individual.put()
            teams_dict[team.key.id()] = team.year
            team.put()

        self.response.headers['Content-Type'] = 'application/json'
        self.response.write(json.dumps({
            'teams': teams_dict
        }))
Пример #26
0
    def get(self):
        teams = {}
        individuals = []

        # Query all users registered this year.
        query = Individual.query(Individual.year == YEAR)

        for member in query:
            if member.team != -1:
                if member.team in teams:
                    teams[member.team]['members'].append(member.serialize())
                else:
                    teams[member.team] = {
                        'members': [member.serialize()]
                    }
            else:
                individuals.append(member.serialize())

        for team_id in teams:
            record = Team.get_by_id(team_id)
            teams[team_id]['name'] = record.name
            teams[team_id]['id'] = int(team_id)
            teams[team_id]['assigned_id'] = record.assigned_id
            teams[team_id]['paid'] = record.paid
            teams[team_id]['user'] = record.user

        users_query = User.query()

        users = {}

        for user in users_query:
            users[user.key.id()] = user.auth_ids[0]

        # Inform the client of success.
        self.response.headers['Content-Type'] = 'application/json'
        self.response.write(json.dumps({
            'teams': teams,
            'individuals': individuals,
            'users': users
        }))
Пример #27
0
    def post(self):

        # Create and insert a record
        # for this registration.
        user_id = int(self.auth.get_user_by_session()['user_id'])
        query = Individual.query(Individual.user == user_id, Individual.year == YEAR)

        for member in query:
            member.key.delete()

        individuals = json.loads(self.request.get('individuals'))

        for individual in individuals:
            record = Individual(
                    name = individual['name'],
                    team = individual['team'],
                    user = user_id,
                    paid = (individual['paid'] if 'paid' in individual else False),
                    year = YEAR
            )
            record.put()

        teams = json.loads(self.request.get('teams'))

        for team in teams:
            print team
            record = Team.get_by_id(team['id'])
            record.name = team['name']
            record.put()

        user = self.user_model.get_by_id(user_id)
        user.refresh()
        user.put()

        # Inform the client of success.
        self.response.headers['Content-Type'] = 'application/json'
        self.response.write(json.dumps({
            'success': True
        }))
Пример #28
0
    def get(self):
        teams = {}
        individuals = []

        # Query all users registered this year.
        query = Individual.query(Individual.year == YEAR)

        for member in query:
            if member.team != -1:
                if member.team in teams:
                    teams[member.team]['members'].append(member.serialize())
                else:
                    teams[member.team] = {'members': [member.serialize()]}
            else:
                individuals.append(member.serialize())

        for team_id in teams:
            record = Team.get_by_id(team_id)
            teams[team_id]['name'] = record.name
            teams[team_id]['id'] = int(team_id)
            teams[team_id]['assigned_id'] = record.assigned_id
            teams[team_id]['paid'] = record.paid
            teams[team_id]['user'] = record.user

        users_query = User.query()

        users = {}

        for user in users_query:
            users[user.key.id()] = user.auth_ids[0]

        # Inform the client of success.
        self.response.headers['Content-Type'] = 'application/json'
        self.response.write(
            json.dumps({
                'teams': teams,
                'individuals': individuals,
                'users': users
            }))
Пример #29
0
    def post(self):

        # Create and insert a record
        # for this registration.
        user_id = int(self.auth.get_user_by_session()['user_id'])
        query = Individual.query(Individual.user == user_id,
                                 Individual.year == YEAR)

        for member in query:
            member.key.delete()

        individuals = json.loads(self.request.get('individuals'))

        for individual in individuals:
            record = Individual(
                name=individual['name'],
                team=individual['team'],
                user=user_id,
                paid=(individual['paid'] if 'paid' in individual else False),
                year=YEAR)
            record.put()

        teams = json.loads(self.request.get('teams'))

        for team in teams:
            print team
            record = Team.get_by_id(team['id'])
            record.name = team['name']
            record.put()

        user = self.user_model.get_by_id(user_id)
        user.refresh()
        user.put()

        # Inform the client of success.
        self.response.headers['Content-Type'] = 'application/json'
        self.response.write(json.dumps({'success': True}))
Пример #30
0
    def get(self):
        teams = {}
        individuals = []

        # Create and insert a record
        # for this registration.
        user_dict = self.auth.get_user_by_session()
        if user_dict:
            user = user_dict['user_id']
            query = Individual.query(Individual.user == user,
                                     Individual.year == YEAR)

            for member in query:
                if member.team != -1:
                    if member.team in teams:
                        teams[member.team]['members'].append(
                            member.serialize())
                    else:
                        teams[member.team] = {'members': [member.serialize()]}
                else:
                    individuals.append(member.serialize())

            for team_id in teams:
                record = Team.get_by_id(team_id)
                teams[team_id]['name'] = record.name
                teams[team_id]['id'] = int(team_id)
                teams[team_id]['paid'] = record.paid

            # Inform the client of success.
            self.response.headers['Content-Type'] = 'application/json'
            self.response.write(
                json.dumps({
                    'teams': teams,
                    'individuals': individuals
                }))
        else:
            self.abort(403)
Пример #31
0
    def get(self):
        teams = {}
        individuals = []

        # Create and insert a record
        # for this registration.
        user_dict = self.auth.get_user_by_session()
        if user_dict:
            user = user_dict['user_id']
            query = Individual.query(Individual.user == user, Individual.year == YEAR)

            for member in query:
                if member.team != -1:
                    if member.team in teams:
                        teams[member.team]['members'].append(member.serialize())
                    else:
                        teams[member.team] = {
                            'members': [member.serialize()]
                        }
                else:
                    individuals.append(member.serialize())

            for team_id in teams:
                record = Team.get_by_id(team_id)
                teams[team_id]['name'] = record.name
                teams[team_id]['id'] = int(team_id)
                teams[team_id]['paid'] = record.paid

            # Inform the client of success.
            self.response.headers['Content-Type'] = 'application/json'
            self.response.write(json.dumps({
                'teams': teams,
                'individuals': individuals
            }))
        else:
            self.abort(403)
Пример #32
0
    def post(self):
        email = self.request.get('email')
        password = self.request.get('password')

        success = True
        problem = ""
        query = LegacyUser.query(LegacyUser.email == email)

        if query.count() == 0:
            try:
                u = self.auth.get_user_by_password(email,
                                                   password,
                                                   remember=True,
                                                   save_session=True)
                print u
            except (InvalidAuthIdError, InvalidPasswordError) as e:
                success = False
                problem = str(type(e))
        else:
            user = query.get()
            salt = user.salt
            _hash = user.hash
            hashfun = hashlib.sha512()
            hashfun.update(salt)
            hashfun.update(password.encode())
            hashval = hashfun.hexdigest()
            if hashval == _hash:
                success = True
                user_data = self.user_model.create_user(
                    email, password_raw=password, institution=user.institution)
                if not user_data[0]:
                    success = False
                else:
                    # Re-attribute any teams belonging to the legacy user
                    # to the new user.
                    query = Team.query(Team.user == user.key.id())
                    for team in query:
                        print 'Reattributing ' + team.name
                        team.user = user_data[1].key.id()
                        team.put()

                    query = Individual.query(Individual.user == user.key.id())
                    for individual in query:
                        print 'Reattributing ' + individual.name
                        individual.user = user_data[1].key.id()
                        individual.put()

                    self.auth.set_session(self.auth.store.user_to_dict(
                        user_data[1]),
                                          remember=True)
                user.key.delete()
            else:
                success = False
                problem = 'InvalidPasswordError'

        self.response.headers['Content-Type'] = 'application/json'
        self.response.write(
            json.dumps({
                'success': success,
                'problem': problem
            }))