def create_new_character(eve_id: int, char_name: str) -> Character:
    char = Character()
    char.id = eve_id
    char.eve_name = char_name
    char.newbro = True
    db.session.add(char)
    db.session.commit()
    return char
Exemple #2
0
def account_self_edit():
    acc_id = current_user.id

    char_name = request.form['default_char_name']
    char_name = char_name.strip()
    if char_name == "":
        char_name = None

    acc = db.session.query(Account).filter(Account.id == acc_id).first()
    if acc is None:
        return flask.abort(400)

    if char_name is not None:
        char_info = outgate.character.get_info_by_name(char_name)

        if char_info is None:
            flash("Character with name {char_name} could not be found!")
        else:
            char_id = char_info.id
            # 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:
                # lets make sure we have the correct name (case)
                char_info: APICacheCharacterInfo = outgate.character.get_info(
                    char_id)
                character = Character()
                character.eve_name = char_info.characterName
                character.id = char_id

            # check if character is linked to this account
            link = db.session.query(linked_chars) \
                .filter((linked_chars.c.id == acc_id) & (linked_chars.c.char_id == char_id)).first()
            if link is None:
                acc.characters.append(character)

            db.session.flush()
            if acc.current_char != char_id:
                # remove all the access tokens
                if acc.ssoToken is not None:
                    db.session.delete(acc.ssoToken)
                acc.current_char = char_id

    db.session.commit()
    return redirect(url_for('.account_self'), code=303)
 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
     char_name = char_info.characterName
     character: Character = db.session.query(Character).get(char_id)
     if character is None:
         character = Character()
         character.eve_name = char_name
         character.id = char_id
     print("Added "+character.__repr__())
     list_eveids.append(char_id)
     acc.characters.append(character)
 
 db.session.commit()
 
 is_valid = False
 char_id = None
 while not is_valid:
     char_id = int(input("Enter charid to set as active char out of "+", ".join([str(i) for i in list_eveids])+":"))
 
     for posid in list_eveids:
         if posid == char_id:
             is_valid = True
Exemple #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)
Exemple #5
0
def account_edit():
    acc_id = int(request.form['account_id'])
    acc_name = request.form['account_name']

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

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

    char_name = request.form['default_char_name']
    char_name = char_name.strip()
    if char_name == "":
        char_name = None

    acc = db.session.query(Account).filter(Account.id == acc_id).first()
    if acc is None:
        return flask.abort(400)

    if acc.username != acc_name:
        acc.username = acc_name

    # if there are roles, add new ones, remove the ones that aren't there
    if len(acc_roles) > 0:
        roles_new = {}
        for r in acc_roles:
            roles_new[r] = True

        # db_roles = session.query(Role).filter(or_(Role.name == name for name in acc_roles)).all()
        roles_to_remove = []
        for role in acc.roles:
            if role.name in roles_new:
                del roles_new[
                    role.name]  # remove because it is already in the db
            else:
                # remove the roles because it not submitted anymore
                # only remove admin if current user is an admin
                if role.name == StaticRoles.ADMIN and not perm_manager.get_permission(
                        StaticPermissions.ADMIN).can():
                    continue
                roles_to_remove.append(role)  # mark for removal

        for role in roles_to_remove:
            acc.roles.remove(role)

        # if it is not an admin remove admin role from new roles
        if not perm_manager.get_permission('admin').can():
            if 'admin' in roles_new:
                del roles_new['admin']

        # add remaining roles
        if len(roles_new) > 0:
            new_db_roles = db.session.query(Role).filter(
                or_(Role.name == name for name in roles_new))
            for role in new_db_roles:
                acc.roles.append(role)
        if len(roles_new) > 0 or len(roles_to_remove) > 0:
            send_roles_changed(account_edit, acc.id, current_user.id,
                               [x for x in roles_new],
                               [x.name for x in roles_to_remove], note)
    else:
        # make sure all roles are removed
        roles_to_remove = []
        for role in acc.roles:
            # only remove admin if current user is an admin
            if role.name == StaticRoles.ADMIN and not perm_manager.get_permission(
                    StaticPermissions.ADMIN).can():
                continue
            roles_to_remove.append(role)

        if len(roles_to_remove) > 0:
            for role in roles_to_remove:
                acc.roles.remove(role)
            db.session.flush()
            send_roles_changed(account_edit, acc.id, current_user.id, [],
                               [x.name for x in roles_to_remove], note)

    if char_name is not None:
        char_info = outgate.character.get_info_by_name(char_name)
        if char_info is None:
            flash(f"Character with name {char_name} could not be found!")
        else:
            char_id = char_info.id
            # 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:
                # lets make sure we have the correct name (case)
                char_info: APICacheCharacterInfo = outgate.character.get_info(
                    char_id)
                character = Character()
                character.eve_name = char_info.characterName
                character.id = char_id

            # check if character is linked to this account
            link = db.session.query(linked_chars) \
                .filter((linked_chars.c.id == acc_id) & (linked_chars.c.char_id == char_id)).first()
            if link is None:
                acc.characters.append(character)

            db.session.flush()
            acc.current_char = char_id

    db.session.commit()
    return redirect(url_for('.accounts'), code=303)