예제 #1
0
파일: account.py 프로젝트: J4LP/newauth
 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'))
예제 #2
0
파일: account.py 프로젝트: J4LP/newauth
 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'))
예제 #3
0
파일: account.py 프로젝트: J4LP/newauth
 def update_api(self):
     try:
         current_user.update_keys()
         current_user.update_status()
         db.session.add(current_user)
         db.session.commit()
     except Exception as e:
         current_app.logger.exception(e)
         flash('Error updating your account.', 'danger')
     else:
         flash('Account updated with success!', 'success')
     return redirect(url_for('AccountView:profile'))
예제 #4
0
파일: account.py 프로젝트: J4LP/newauth
 def delete_api(self, key_id):
     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:
         for character in api_key.characters.all():
             db.session.delete(character)
         db.session.commit()
         db.session.delete(api_key)
         db.session.commit()
         current_user.update_keys()
         current_user.update_status()
         flash('API Key deleted.', 'success')
     return redirect(url_for('AccountView:profile'))