def new_api(self): form = APIKeyForm() if form.validate_on_submit(): api_key = APIKey() form.populate_obj(api_key) try: api_key.update_api_key() except AuthenticationException: flash('Could not authenticate with this API Key', 'danger') return redirect(url_for('AccountView:profile')) except Exception as e: flash('Error updating API Key: {}'.format(e.message), 'danger') return redirect(url_for('AccountView:profile')) else: current_user.api_keys.append(api_key) db.session.add(current_user) try: db.session.commit() except Exception as e: flash('We could not save your API Key in the database.', 'danger') return redirect(url_for('AccountView:profile')) else: current_user.update_keys() current_user.update_status() db.session.commit() flash('API Key added with success.', 'success') else: flash_errors(form) return redirect(url_for('AccountView:profile'))
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)
def password(self): character_id = session['character'] key_id = session['key_id'] vcode = session['vcode'] api_key = APIKey(key_id=key_id, vcode=vcode) api_key.update_api_key() for character in api_key.get_characters(): if character.id == character_id: break else: flash('Character #{} not found in API Key #{}, aborting.'.format(character_id, key_id), 'danger') return redirect(url_for('RegisterView:index')) form = RegisterForm() form.user_id.data = slugify(character.name, to_lower=True, separator='_') if form.validate_on_submit(): user = User( user_id=form.user_id.data, name=character.name, email=form.email.data, main_character_id=character.id ) user.update_password(form.password.data) user.api_keys.append(api_key) for character in api_key.get_characters(): user.characters.append(character) db.session.add(user) try: db.session.commit() except Exception as e: db.session.rollback() current_app.logger.exception(e) flash("Could not save user to database.", "danger") else: User.password_updated.send(user, form.password.data) session.clear() flash("Account created! Login now with {} and get started!".format(user.user_id), 'success') return redirect(url_for('AccountView:login')) return render_template('register/password.html', form=form, character=character)