Skip to content

Commit

Permalink
retreive gip3days flag on login itcgames/celiapp#179
Browse files Browse the repository at this point in the history
  • Loading branch information
kenpower committed Jun 25, 2021
1 parent 394b2b7 commit 97fa1b5
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 5 deletions.
4 changes: 3 additions & 1 deletion api/handlers/login.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ def post(self):
}, {
'passwordHash': 1,
'gamify': 1,
'usingGIP': 1
'usingGIP': 1,
'gip3PerWeek': 1
})

if user is None:
Expand All @@ -82,5 +83,6 @@ def post(self):
self.response['expiresIn'] = token['expiresIn']
self.response['gamify'] = user['gamify']
self.response['usingGIP'] = user.get('usingGIP', False)
self.response['gip3PerWeek'] = user.get('gip3PerWeek', False)

self.write_json()
11 changes: 9 additions & 2 deletions api/handlers/registration.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,20 +49,24 @@ def post(self):

gamify = None
usingGIP = False
gip3PerWeek = False

if self.whitelist:
info('Attempting to register \'' + email + '\'...')
user_2 = yield self.db.whitelist.find_one({
'email': email
}, {
'gamify': 1,
'usingGIP': 1
'usingGIP': 1,
'gip3PerWeek': 1
})
if user_2:
if 'gamify' in user_2:
gamify = user_2['gamify']
if 'usingGIP' in user_2:
usingGIP = user_2['usingGIP']
if 'gip3PerWeek' in user_2:
gip3PerWeek = user_2['gip3PerWeek']
else:
self.send_error(403, message='The email address is not on the whitelist!')
return
Expand All @@ -74,12 +78,15 @@ def post(self):
'passwordHash': password_hash,
'displayName': display_name,
'gamify': gamify,
'usingGIP': usingGIP
'usingGIP': usingGIP,
'gip3PerWeek': gip3PerWeek
})

self.set_status(200)
self.response['email'] = email
self.response['displayName'] = display_name
self.response['gamify'] = gamify
self.response['usingGIP'] = usingGIP
self.response['gip3PerWeek'] = gip3PerWeek

self.write_json()
70 changes: 68 additions & 2 deletions test/usingGIP.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,24 @@ def seUpDB(self):
}, {
'email': self.legacyEmail.lower(),
'gamify': True,
}])
}, {
'email': self.usingGipEveryDayEmail.lower(),
'usingGIP': True,
'gip3PerWeek': False
}, {
'email': self.usingGip3DaysEmail.lower(),
'usingGIP': True,
'gip3PerWeek': True
}
])


def setUp(self):
super().setUp()

self.usingGipEmail = 'usingGipEmail@test.com'
self.usingGipEveryDayEmail = 'usingGipEveryDayEmail@test.com'
self.usingGip3DaysEmail = 'usingGip3DaysEmail@test.com'
self.notUsingGipEmail = 'notUsingGipEmail@test.com'
self.legacyEmail = 'legacyEmail@test.com'
self.password = 'testPassword'
Expand Down Expand Up @@ -123,4 +134,59 @@ def test_login_pre_GIP_whitelist(self):

body = json_decode(response.body)
print(body)
self.assertFalse(body['usingGIP'])
self.assertFalse(body['usingGIP'])

def test_login_GIP_EveryDay(self):
register_body = {
'email': self.usingGipEveryDayEmail,
'password': self.password,
'displayName': 'testDisplayName'
}

response = self.fetch('/registration', method='POST', body=dumps(register_body))

body = json_decode(response.body)
print("test_login_GIP_EveryDay")
print(body)
self.assertTrue(body['usingGIP'])
self.assertFalse(body['gip3PerWeek'])

login_body = {
'email': self.usingGipEveryDayEmail,
'password': self.password,
}

response = self.fetch('/login', method='POST', body=dumps(login_body))
self.assertEqual(200, response.code)

body = json_decode(response.body)
self.assertTrue(body['usingGIP'])
self.assertFalse(body['gip3PerWeek'])

def test_login_GIP_3_Days(self):
register_body = {
'email': self.usingGip3DaysEmail,
'password': self.password,
'displayName': 'testDisplayName'
}

response = self.fetch('/registration', method='POST', body=dumps(register_body))

body = json_decode(response.body)
print("test_login_GIP_EveryDay")
print(body)
self.assertTrue(body['usingGIP'])
self.assertTrue(body['gip3PerWeek'])

login_body = {
'email': self.usingGip3DaysEmail,
'password': self.password,
}

response = self.fetch('/login', method='POST', body=dumps(login_body))
self.assertEqual(200, response.code)

body = json_decode(response.body)
self.assertTrue(body['usingGIP'])
self.assertTrue(body['gip3PerWeek'])

0 comments on commit 97fa1b5

Please sign in to comment.