def api(self): registration_type = request.args.get('type') if not registration_type or registration_type not in current_app.config['EVE']['requirements']: flash('Invalid registration type.', 'danger') return redirect(url_for('RegisterView:index')) form = APIKeyForm() if form.validate_on_submit(): api_key = APIKey(key_id=form.key_id.data, vcode=form.vcode.data) try: api_key.update_api_key() except AuthenticationException: flash('Could not authenticate with this API Key', 'danger') return redirect(url_for('RegisterView:api', type=registration_type)) except Exception as e: flash('Error updating API Key: {}'.format(e.message), 'danger') return redirect(url_for('RegisterView:api', type=registration_type)) else: if api_key.mask != current_app.config['EVE']['requirements'][registration_type]['mask']: flash('Wrong mask for API Key, needed {}, got {}'.format(current_app.config['EVE']['requirements'][registration_type]['mask'], api_key.mask), 'danger') return redirect(url_for('RegisterView:api', type=registration_type)) if current_app.config['EVE']['requirements'][registration_type]['expires'] and not api_key.mask: flash('API Key should not have an expiration set. Please create another API Key.', 'danger') return redirect(url_for('RegisterView:api', type=registration_type)) flash('API Key accepted.', 'success') session['key_id'] = api_key.key_id session['vcode'] = api_key.vcode session['registration_type'] = registration_type return redirect(url_for('RegisterView:characters')) return render_template('register/api.html', form=form, registration_type=registration_type)