Skip to content

Commit

Permalink
Fixing account creation verification to check emails against IA
Browse files Browse the repository at this point in the history
  • Loading branch information
mekarpeles authored and root committed Aug 3, 2017
1 parent 5d39e4f commit 866cfca
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
4 changes: 3 additions & 1 deletion openlibrary/accounts/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,8 @@ def link(self, itemname):
"""Careful, this will save any other changes to the ol user object as
well
"""
itemname = itemname if itemname.startswith('@') else '@%s' % itemnamek

_ol_account = web.ctx.site.store.get(self._key)
_ol_account['internetarchive_itemname'] = itemname
web.ctx.site.store[self._key] = _ol_account
Expand Down Expand Up @@ -665,7 +667,7 @@ def audit_accounts(email, password, require_link=False, test=False):
return {'error': 'account_blocked'}

if require_link:
ol_account = OpenLibraryAccount.get(link=ia_account.itemname, test=test)
ol_account = OpenLibraryAccount.get(link=ia_account.itemname, test=test)
if ol_account and not ol_account.itemname:
return {'error': 'accounts_not_connected'}

Expand Down
6 changes: 2 additions & 4 deletions openlibrary/plugins/upstream/account.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

from openlibrary import accounts
from openlibrary.accounts import (
audit_accounts,
audit_accounts,
Account, OpenLibraryAccount, InternetArchiveAccount,
valid_email
)
Expand Down Expand Up @@ -232,11 +232,9 @@ def POST(self):
f.note = utils.get_error("account_create_tos_not_selected")
return render['account/create'](f)


ia_account = InternetArchiveAccount.get(email=i.email)
ol_account = OpenLibraryAccount.get(email=i.email)
# Require email to not already be used in IA or OL
if ia_account or ol_account:
if ia_account:
f.note = LOGIN_ERRORS['email_registered']
return render['account/create'](f)

Expand Down
7 changes: 6 additions & 1 deletion openlibrary/plugins/upstream/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,16 @@
from openlibrary.i18n import lgettext as _
from openlibrary.utils.form import Form, Textbox, Password, Hidden, Validator, RegexpValidator
from openlibrary import accounts
from openlibrary.accounts import InternetArchiveAccount
from . import spamcheck

def find_account(username=None, lusername=None, email=None):
return accounts.find(username=username, lusername=lusername, email=email)

def find_ia_account(email=None):
ia_account = InternetArchiveAccount.get(email=email)
return ia_account

Login = Form(
Textbox('username', description=_('Username'), klass='required'),
Password('password', description=_('Password'), klass='required'),
Expand All @@ -18,7 +23,7 @@ def find_account(username=None, lusername=None, email=None):
forms.login = Login

email_already_used = Validator(_("No user registered with this email address"), lambda email: find_account(email=email) is not None)
email_not_already_used = Validator(_("Email already registered"), lambda email: find_account(email=email) is None)
email_not_already_used = Validator(_("Email already registered"), lambda email: not find_ia_account(email=email))
email_not_disposable = Validator(_("Disposable email not permitted"), lambda email: not email.lower().endswith('dispostable.com'))
email_domain_not_blocked = Validator(_("Your email provider is not recognized."), lambda email: not spamcheck.is_spam_email(email))
username_validator = Validator(_("Username already used"), lambda username: not find_account(lusername=username.lower()))
Expand Down

0 comments on commit 866cfca

Please sign in to comment.