Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent duplicate guest email signup #329

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
26 changes: 26 additions & 0 deletions py/tests/test_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,32 @@ async def test_guest_signup_email(cli, url, factory: Factory, db_conn):
}


@if_online
pro-Nate marked this conversation as resolved.
Show resolved Hide resolved
async def test_guest_signup_email_existing(cli, url, factory: Factory, db_conn):
await factory.create_company()
assert 0 == await db_conn.fetchval('SELECT COUNT(*) FROM users')

guest_1 = {
'email': 'testing@gmail.com',
'first_name': 'Tes',
'last_name': 'Ting',
'grecaptcha_token': '__ok__',
}
r = await cli.json_post(url('signup-guest', site='email'), data=guest_1)
assert r.status == 200, await r.text()

guest_2 = {
'email': 'testing@gmail.com',
'first_name': 'TesT',
'last_name': 'hot',
'grecaptcha_token': '__ok__',
}
r = await cli.json_post(url('signup-guest', site='email'), data=guest_2)
assert r.status == 470, await r.text()
assert {'status': 'existing user'} == await r.json()
assert 1 == await db_conn.fetchval('SELECT COUNT(*) FROM users')


async def test_guest_signup_google(cli, url, factory: Factory, db_conn, mocker):
await factory.create_company()
data = {'id_token': 'good.test.token'}
Expand Down
7 changes: 6 additions & 1 deletion py/web/views/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,8 +239,13 @@ async def guest_signup(request):
await check_grecaptcha(m, request)

details = await siw_method(m, app=request.app)

user_email = details['email'].lower()

conn = request['conn']
existing_user = await conn.fetchrow('SELECT * FROM users WHERE email=$1', user_email)
pro-Nate marked this conversation as resolved.
Show resolved Hide resolved
if existing_user:
raise JsonErrors.HTTP470(status='existing user')

user_id, status = await request['conn'].fetchrow_b(
pro-Nate marked this conversation as resolved.
Show resolved Hide resolved
CREATE_USER_SQL,
values=Values(
Expand Down