示例#1
0
 def get_login_token(self):
     if self.login_token is None:
         self.login_token = get_random_token(16)
     return self.login_token
# inject the lib folder before everything else
from typing import Optional

from waitlist.base import db
from waitlist.permissions.manager import StaticRoles
from waitlist.storage.database import Account, Character, Role, APICacheCharacterInfo
from waitlist.utility.utils import get_random_token
import waitlist.utility.outgate as outgate
if __name__ == '__main__':
    name = input("Login Name:")
    print("Creating Account")
    acc = Account()
    acc.username = name
    acc.login_token = get_random_token(16)
    print("Account created")
    admin_role = db.session.query(Role).filter(Role.name == StaticRoles.ADMIN).first()
    acc.roles.append(admin_role)
    db.session.add(acc)
    print(acc.login_token)
    
    char_name = "--"
    list_eveids = []
    while char_name:
        char_name = input("Enter Character to associate with this account:")
        char_name = char_name.strip()
        if not char_name:
            break
        
        char_info: Optional[APICacheCharacterInfo] = outgate.character.get_info_by_name(char_name)
        char_id = char_info.id
        # assign this too because his name could have had wrong case
示例#3
0
def accounts():
    if request.method == "POST":
        acc_name = request.form['account_name']

        acc_roles = request.form.getlist('account_roles')

        char_name = request.form['default_char_name']
        char_name = char_name.strip()

        note = request.form['change_note'].strip()
        try:
            char_info = outgate.character.get_info_by_name(char_name)
            if char_info is None:
                flash(
                    gettext("A Character named %(char_name)s does not exist!",
                            char_name=char_name), 'warning')
            else:
                char_id = char_info.id
                acc = Account()
                acc.username = acc_name

                acc.login_token = get_random_token(16)

                if len(acc_roles) > 0:
                    db_roles = db.session.query(Role).filter(
                        or_(Role.name == name for name in acc_roles)).all()
                    for role in db_roles:
                        acc.roles.append(role)

                db.session.add(acc)

                # find out if there is a character like that in the database
                # or create it
                character = get_character_by_id(char_id)

                acc.characters.append(character)

                db.session.flush()

                acc.current_char = char_id

                db.session.commit()
                send_account_created(accounts, acc.id, current_user.id,
                                     acc_roles, note)
                send_alt_link_added(accounts, current_user.id, acc.id,
                                    character.id)
        except ApiException as e:
            flash(
                gettext("Could not execute action, ApiException %(ex)s", ex=e),
                'danger')

    clean_alt_list()
    roles = db.session.query(Role).order_by(Role.name).all()
    accs = db.session.query(Account).order_by(asc(Account.disabled)).order_by(
        Account.username).all()
    mails = {
        'resident': [sget_resident_mail(),
                     sget_resident_topic()],
        'tbadge': [sget_tbadge_mail(), sget_tbadge_topic()],
        'other': [sget_other_mail(), sget_other_topic()]
    }

    return render_template("settings/accounts.html",
                           roles=roles,
                           accounts=accs,
                           mails=mails)
示例#4
0
def accounts():
    if request.method == "POST":
        acc_name = request.form['account_name']

        acc_roles = request.form.getlist('account_roles')

        char_name = request.form['default_char_name']
        char_name = char_name.strip()

        note = request.form['change_note'].strip()

        char_info = outgate.character.get_info_by_name(char_name)
        if char_info is None:
            flash(f"A Character named {char_name} does not exist!")
        else:
            char_id = char_info.id
            acc = Account()
            acc.username = acc_name

            acc.login_token = get_random_token(16)

            if len(acc_roles) > 0:
                db_roles = db.session.query(Role).filter(
                    or_(Role.name == name for name in acc_roles)).all()
                for role in db_roles:
                    acc.roles.append(role)

            db.session.add(acc)

            # find out if there is a character like that in the database
            character = db.session.query(Character).filter(
                Character.id == char_id).first()

            if character is None:
                char_info: APICacheCharacterInfo = outgate.character.get_info(
                    char_id)
                character = Character()
                character.eve_name = char_info.characterName
                character.id = char_id

            acc.characters.append(character)

            db.session.flush()

            acc.current_char = char_id

            db.session.commit()
            send_account_created(accounts, acc.id, current_user.id, acc_roles,
                                 'Creating account. ' + note)

    roles = db.session.query(Role).order_by(Role.name).all()
    accs = db.session.query(Account).order_by(asc(Account.disabled)).order_by(
        Account.username).all()
    mails = {
        'resident': [sget_resident_mail(),
                     sget_resident_topic()],
        'tbadge': [sget_tbadge_mail(), sget_tbadge_topic()],
        'other': [sget_other_mail(), sget_other_topic()]
    }

    return render_template("settings/accounts.html",
                           roles=roles,
                           accounts=accs,
                           mails=mails)