def POST(self): i = web.input('email', 'password', 'username', agreement="no") i.displayname = i.get('displayname') or i.username f = self.get_form() if not f.validates(i): return render['account/create'](f) if i.agreement != "yes": f.note = utils.get_error("account_create_tos_not_selected") return render['account/create'](f) ia_account = InternetArchiveAccount.get(email=i.email) # Require email to not already be used in IA or OL if ia_account: f.note = LOGIN_ERRORS['email_registered'] return render['account/create'](f) try: # Create ia_account: require they activate via IA email # and then login to OL. Logging in after activation with # IA credentials will auto create and link OL account. ia_account = InternetArchiveAccount.create( screenname=i.username, email=i.email, password=i.password, verified=False, retries=USERNAME_RETRIES) except ValueError as e: f.note = LOGIN_ERRORS['max_retries_exceeded'] return render['account/create'](f) return render['account/verify'](username=i.username, email=i.email)
def GET(self): i = web.input(username='', email='', key='') if i.key != lending.config_internal_tests_api_key: return delegate.RawText(simplejson.dumps({ 'error': 'Authentication failed for private API' }), content_type="application/json") try: if i.username: ol_account = OpenLibraryAccount.get(username=i.username) elif i.email: ol_account = OpenLibraryAccount.get(email=i.email) except Exception as e: return delegate.RawText(simplejson.dumps({ 'error': 'bad-account' }), content_type="application/json") if ol_account: ol_account.enc_password = '******' if ol_account.itemname: return delegate.RawText(simplejson.dumps({ 'status': 'link-exists', 'username': ol_account.username, 'itemname': ol_account.itemname, 'email': ol_account.email.lower() }), content_type="application/json") if not ol_account.itemname: ia_account = InternetArchiveAccount.get(email=ol_account.email.lower()) if ia_account: ol_account.link(ia_account.itemname) return delegate.RawText(simplejson.dumps({ 'username': ol_account.username, 'status': 'link-found', 'itemname': ia_account.itemname, 'ol-itemname': ol_account.itemname, 'email': ol_account.email.lower(), 'ia': ia_account }), content_type="application/json") password = OpenLibraryAccount.generate_random_password(16) ia_account = InternetArchiveAccount.create( ol_account.username or ol_account.displayname, ol_account.email, password, verified=True, retries=USERNAME_RETRIES) return delegate.RawText(simplejson.dumps({ 'username': ol_account.username, 'email': ol_account.email, 'itemname': ia_account.itemname, 'password': password, 'status': 'link-created' }), content_type="application/json")
def POST(self): f = self.get_form() # type: forms.RegisterForm if f.validates(web.input()): try: # Create ia_account: require they activate via IA email # and then login to OL. Logging in after activation with # IA credentials will auto create and link OL account. notifications = ['announce-general' ] if f.ia_newsletter.checked else [] InternetArchiveAccount.create(screenname=f.username.value, email=f.email.value, password=f.password.value, notifications=notifications, verified=False, retries=USERNAME_RETRIES) return render['account/verify'](username=f.username.value, email=f.email.value) except ValueError: f.note = LOGIN_ERRORS['max_retries_exceeded'] return render['account/create'](f)
def POST(self): i = web.input('email', 'password', 'username', agreement="no") i.displayname = i.get('displayname') or i.username f = self.get_form() if f.validates(i): if i.agreement == "yes": ia_account = InternetArchiveAccount.get(email=i.email) # Require email to not already be used in IA or OL if not ia_account: # Account doesn't already exist, proceed try: # Create ia_account: require they activate via IA email # and then login to OL. Logging in after activation with # IA credentials will auto create and link OL account. ia_account = InternetArchiveAccount.create( screenname=i.username, email=i.email, password=i.password, verified=False, retries=USERNAME_RETRIES) page = render['account/verify'](username=i.username, email=i.email) page.v2 = True return page except ValueError as e: f.note = LOGIN_ERRORS['max_retries_exceeded'] else: # Account with this email already exists f.note = LOGIN_ERRORS['email_registered'] else: # User did not click terms of service f.note = utils.get_error("account_create_tos_not_selected") page = render['account/create'](f) page.v2 = True return page
def GET(self): i = web.input(username='', email='', key='') if i.key != lending.config_internal_tests_api_key: return delegate.RawText(simplejson.dumps( {'error': 'Authentication failed for private API'}), content_type="application/json") try: if i.username: ol_account = OpenLibraryAccount.get(username=i.username) elif i.email: ol_account = OpenLibraryAccount.get(email=i.email) except Exception as e: return delegate.RawText(simplejson.dumps({'error': 'bad-account'}), content_type="application/json") if ol_account: ol_account.enc_password = '******' if ol_account.itemname: return delegate.RawText(simplejson.dumps({ 'status': 'link-exists', 'username': ol_account.username, 'itemname': ol_account.itemname, 'email': ol_account.email.lower() }), content_type="application/json") if not ol_account.itemname: ia_account = InternetArchiveAccount.get( email=ol_account.email.lower()) if ia_account: ol_account.link(ia_account.itemname) return delegate.RawText(simplejson.dumps({ 'username': ol_account.username, 'status': 'link-found', 'itemname': ia_account.itemname, 'ol-itemname': ol_account.itemname, 'email': ol_account.email.lower(), 'ia': ia_account }), content_type="application/json") password = OpenLibraryAccount.generate_random_password(16) ia_account = InternetArchiveAccount.create( ol_account.username or ol_account.displayname, ol_account.email, password, verified=True, retries=USERNAME_RETRIES) return delegate.RawText(simplejson.dumps({ 'username': ol_account.username, 'email': ol_account.email, 'itemname': ia_account.itemname, 'password': password, 'status': 'link-created' }), content_type="application/json")
def find_ia_account(email=None): ia_account = InternetArchiveAccount.get(email=email) return ia_account