Exemple #1
0
 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'))
Exemple #2
0
 def edit_api(self, key_id):
     form = APIKeyForm()
     if form.validate_on_submit():
         api_key = current_user.api_keys.filter_by(key_id=key_id).first()
         if not api_key:
             flash('We could not find the API Key #{} in your account.'.format(key_id), 'danger')
         else:
             api_key.key_id = form.key_id.data
             api_key.vcode = form.vcode.data
             try:
                 api_key.update_api_key()
             except AuthenticationException:
                 flash('Could not authenticate with this API Key', 'error')
                 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:
                 db.session.add(api_key)
                 db.session.commit()
                 current_user.update_keys()
                 current_user.update_status()
                 flash('API Key updated.', 'success')
     else:
         flash_errors(form)
     return redirect(url_for('AccountView:profile'))
Exemple #3
0
 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)