async def on_recover(request, verification_session): """ Changes and recovers an account's password. """ await account_recovery(request, verification_session) return json('Account recovered successfully', verification_session.account.json())
async def resend_verification_request(request): """ Resends verification code if somehow lost. """ verification_session = await VerificationSession().decode(request) await verification_session.text_code() return json('Verification code resend successful', verification_session.json())
async def on_request_captcha(request): """ Requests captcha session for client. """ captcha_session = await request_captcha(request) response = json('Captcha request successful!', captcha_session.json()) await captcha_session.encode(response) return response
async def on_create_admin(request, authentication_session): """ Creates 'Admin' and 'Mod' roles to be used for testing role based authorization. """ client = authentication_session.account await Role().create(account=client, name='Admin') await Role().create(account=client, name='Mod') return json('Roles added to your account!', client.json())
async def on_logout(request): """ User logout, invalidates client authentication session. """ authentication_session = await logout(request) response = json('Logout successful!', authentication_session.account.json()) return response
async def on_login(request): """ User login, creates and encodes authentication session. """ authentication_session = await login(request) response = json('Login successful!', authentication_session.account.json()) await authentication_session.encode(response) return response
async def on_recover_request(request): """ Requests a recovery session to allow user to reset password with a code. """ verification_session = await request_account_recovery(request) await verification_session.text_code() response = json('Recovery request successful', verification_session.json()) await verification_session.encode(response) return response
async def on_register_verification(request): """ Registration test with all built-in requirements. """ verification_session = await register(request) await verification_session.text_code() response = json('Registration successful', verification_session.account.json()) await verification_session.encode(response) return response
async def on_create_admin_perm(request, authentication_session): """ Creates 'admin:update' and 'admin:add' permissions to be used for testing wildcard based authorization. """ client = authentication_session.account await Permission().create(account=client, wildcard='admin:update', decription="") await Permission().create(account=client, wildcard='admin:add') return json('Permissions added to your account!', client.json())
async def new_verification_request(request): """ Creates new verification code. """ verification_session = await request_verification(request) await verification_session.text_code() response = json('Verification request successful', verification_session.json()) await verification_session.encode(response) return response
async def on_verify(request, verification_session): """ Attempt to verify account and allow access if unverified. """ await verify_account(verification_session) return json('Verification successful!', verification_session.json())
async def on_register(request): """ Registration test without verification or captcha requirements. """ account = await register(request, verified=True) return json('Registration Successful!', account.json())
async def on_error(request, exception): return json('An error has occurred!', { 'error': type(exception).__name__, 'summary': str(exception) }, status_code=exception.status_code)