Example #1
0
def make_friend_request(user_id):
    current_user_id = current_user.get_id()
    # current_user_id = 3
    invite = Invite(inviter_id=current_user_id,
                    invitee_id=user_id,
                    type='friend')
    db.session.add(invite)
    db.session.commit()
    return invite.to_dict()
Example #2
0
def make_group_invite(username, group_id):
    current_user_id = current_user.get_id()
    user = User.query.filter(User.username == username).first()
    # current_user_id = 1
    invite = Invite(inviter_id=current_user_id,
                    invitee_id=user.id,
                    group_id=group_id,
                    type='group')
    db.session.add(invite)
    db.session.commit()
    return invite.to_dict()
def index():
    user_form = UserForm()

    if user_form.validate_on_submit():
        partial_user = User(email=user_form.email.data,
                            full_name=user_form.full_name.data,
                            user_type=user_form.user_type.data,
                            join_date=user_form.join_date.data,
                            next_police_check=user_form.next_police_check.data,
                            time_pref=user_form.time_pref.data,
                            day_pref=day_pref_to_binary(user_form.day_prefs.data))

        db.session.add(partial_user)
        db.session.commit()

        key = generate_invite_key()
        new_invite = Invite(user_id=partial_user.id, key=key)

        db.session.add(new_invite)
        db.session.commit()

        flash('Invitation created. The user can register at: ' + address + '/register/' + key, 'success')
        return redirect(url_for('invite.index'))

    data = {
        'editing': False,
        'title': 'Invite User',
        'form': user_form
    }

    return render_template('user/invite.html', **data)
Example #4
0
def share(id: int):
    """Share a character."""
    character = get_character(id, check_author=True)
    logger.debug("Finding previous invite")
    invite = Invite.query_for(character).first()
    logger.debug(f"Invites found {invite}")
    if not invite:
        logger.debug(f"Creating an invite for character {character.id}")
        invite = Invite(character)
        invite.owner_id = character.user_id
        session.add(invite)
        session.commit()

    share_url = url_for('character.shared', code=invite.id, _external=True)

    form = None

    html_response = render_template('character/api_share.html.jinja',
                                    form=form,
                                    url=share_url,
                                    code=invite.id)

    return jsonify({'url': share_url, 'html': html_response})
Example #5
0
def store_email_address(email, first_name, last_name, organization,
                        class_group):
    if '@' in email:
        invite = Invite.query.filter(
            Invite.email == email,
            Invite.organization == organization).first()
        if invite:
            invite.class_group = class_group
        else:
            invite = Invite(email=email,
                            first_name=first_name,
                            last_name=last_name,
                            organization=organization,
                            class_group=class_group)
            db.session.add(invite)
            return True
    return False
Example #6
0
def view(id, character, editable):
    subskillform = SubskillForm(prefix="subskillform")
    if editable and subskillform.data and subskillform.validate_on_submit():
        character.add_subskill(subskillform.name.data,
                               subskillform.parent.data)
        logentry = LogEntry(
            character,
            f"add subskill {subskillform.name.data} under {subskillform.parent.data}",
            user_id=current_user.id)
        session.add(logentry)

        character.store_data()
        session.commit()
        return redirect(url_for('character.view', id=id))

    skillform = SkillForm(prefix="skillform")
    if editable and skillform.data and skillform.validate_on_submit():
        skills = character.skills()
        for skill in skills:
            if skillform.name.data == skill['name']:
                flash("Skill already exists")
                return redirect(url_for('character.view', id=id))

        character.add_skill(skillform.name.data)
        character.store_data()
        logentry = LogEntry(character,
                            f"add skill {subskillform.name.data}",
                            user_id=current_user.id)
        session.add(logentry)

        session.commit()
        return redirect(url_for('character.view', id=id))

    typeheader = "1920s Era Investigator"
    if character.game and character.game[1] == "Modern":
        typeheader = "Modern Era"

    shared = Invite.query_for(character).count()

    return render_template('character/coc7e/sheet.html.jinja',
                           shared=shared,
                           character=character,
                           typeheader=typeheader,
                           editable=editable,
                           skillform=skillform,
                           subskillform=subskillform)
Example #7
0
def trigger_action(jds):
    action = json.loads(jds)
    try:
        if action['action'] == 'resend-contact-invite':
            invite_id = action['id']
            invite = Invite.query.get(invite_id)
            invite.contactmoment_sent = False
            db.session.commit()
            return jsonify({
                'status': True,
                'msg': 'Uitnodiging is verstuurd.'
            })
    except Exception as e:
        log.error(f'Could not do action : {e}')
        return jsonify({
            'status': False,
            'msg': f'Kan uitnodiging niet sturen.<br>{e}'
        })
    try:
        if action['action'] == 'add-invite':
            first_name = action['first_name']
            last_name = action['last_name']
            email = action['email']
            organization = action['organization']
            invite = Invite.query.filter(
                Invite.email == email,
                Invite.organization == organization).first()
            if invite:
                return jsonify({
                    'status': False,
                    'msg': 'E-mailadres bestaat al'
                })
            invite = Invite(first_name=first_name,
                            last_name=last_name,
                            email=email,
                            organization=organization)
            db.session.add(invite)
            db.session.commit()
            update_email_tokens()
            return jsonify({
                'status':
                True,
                'msg':
                'E-mailadres is toegevoegd.<br>Uitnodiging wordt verstuurd.'
            })
    except Exception as e:
        log.error(f'Could not do action : {e}')
        return jsonify({
            'status': False,
            'msg': f'Kan e-mailadres niet toevoegen.<br>{e}'
        })
    try:
        if action['action'] == 'update-invite':
            first_name = action['first_name']
            last_name = action['last_name']
            email = action['email']
            organization = action['organization']
            invite_id = action['id']
            invite = Invite.query.get(invite_id)
            if not invite:
                return jsonify({
                    'status': False,
                    'msg': 'E-mailadres niet gevonden'
                })
            invite.first_name = first_name
            invite.last_name = last_name
            db.session.commit()
            return jsonify({
                'status': True,
                'msg': 'E-mailadres is aangepast.'
            })
    except Exception as e:
        log.error(f'Could not do action : {e}')
        return jsonify({
            'status': False,
            'msg': f'Kan e-mailadres niet aanapssen.<br>{e}'
        })
    try:
        if action['action'] == 'remove-subscription':
            response_id = action['id']
            response = ContactResponse.query.get(response_id)
            db.session.delete(response)
            db.session.commit()
            return jsonify({'status': True, 'msg': 'Afspraak is verwijderd.'})
    except Exception as e:
        log.error(f'Could not do action : {e}')
        return jsonify({
            'status': False,
            'msg': f'Kan afspraak niet verwijderen.<br>{e}'
        })
    try:
        if action['action'] == 'remove-invite':
            invite_id = action['id']
            invite = Invite.query.get(invite_id)
            db.session.delete(invite)
            db.session.commit()
            return jsonify({
                'status': True,
                'msg': 'E-mailadres is verwijderd.'
            })
    except Exception as e:
        log.error(f'Could not do action : {e}')
        return jsonify({
            'status': False,
            'msg': f'Kan e-mailadres niet verwijderen.<br>{e}'
        })
    try:
        if action['action'] == 'toggle-activation':
            invite_id = action['id']
            invite = Invite.query.get(invite_id)
            invite.active = not invite.active
            db.session.commit()
            return jsonify({'status': True, 'msg': 'Activatie is aangepast.'})
    except Exception as e:
        log.error(f'Could not do action : {e}')
        return jsonify({
            'status': False,
            'msg': f'Kan activatie niet aanpassen.<br>{e}'
        })

    try:
        if action['action'] == 'resend-not-responded':
            responses = ContactResponse.query.filter(
                ContactResponse.organization == 'SUMLPU').all()
            invites = Invite.query.filter(Invite.organization == 'SUMLPU',
                                          Invite.enable == True).all()
            response_invit_first_last_name = [
                f'{r.invite.first_name}{r.invite.last_name}' for r in responses
            ]
            nbr_sent = 0
            for i in invites:
                if not f'{i.first_name}{i.last_name}' in response_invit_first_last_name:
                    i.contactmoment_sent = False
                    nbr_sent += 1
            db.session.commit()
            return jsonify({
                'status': True,
                'msg': f'{nbr_sent} e-mail(s) is/zijn verstuurd.'
            })
    except Exception as e:
        log.error(f'Could not do action : {e}')
        return jsonify({
            'status': False,
            'msg': f'Kan activatie niet aanpassen.<br>{e}'
        })
    return jsonify({'status': True})
Example #8
0
def gen_invite():
	if g.user.role != User.R_GUEST:
		Invite().generate(g.user)
	return redirect(url_for('user.invite'))
Example #9
0
def view(id: int):
    invites = None
    campaign: Campaign = Campaign.query.get(id)

    # Set up forms
    inviteform = InvitePlayerForm(prefix="inviteform")
    createinviteform = CreateInviteForm(prefix="createinviteform")
    characterform = AddCharacterForm(prefix="characterform")
    npcform = AddNPCForm(prefix="npcform")

    messageform = MessagePlayerForm(players=[
        (campaign.user_id, "GM"),
    ] + [(p.id, p.user.username) for p in campaign.players],
                                    campaign_id=campaign.id,
                                    from_id=current_user.profile.id)

    is_player = current_user.profile in campaign.players
    is_owner = current_user and current_user.profile.id == campaign.user_id

    logger.debug(f"Viewing campagin {campaign.title}")
    logger.debug(f"There are {campaign.players.count()} players")
    logger.debug(f"There are {campaign.characters.count()} characters")

    if not is_player and not is_owner:
        abort(404, "This is not the campaign your are looking for.")

    if is_owner:
        if createinviteform.submit.data and \
                createinviteform.validate_on_submit():
            invite = Invite(campaign)
            invite.owner_id = campaign.user_id
            session.add(invite)
            session.commit()

        if inviteform.submit.data and inviteform.validate_on_submit():
            player = (User.query.filter_by(
                email=inviteform.email.data).first().profile)
            campaign.players.append(player)
            session.commit()
            return redirect(url_for('campaign.view', id=id))

        invites = Invite.query_for(campaign)

        if npcform.submit.data and npcform.validate_on_submit():
            print("Adding NPC")
            character = npcform.character.data
            npc = NPC(character=character, campaign=campaign)
            session.add(npc)
            session.commit()

            return redirect(url_for('campaign.view', id=id))

    if characterform.submit.data and characterform.validate_on_submit():
        print("Adding character")
        character = characterform.character.data
        if (character not in campaign.characters
                and character.user_id == current_user.profile.id):
            campaign.characters.append(character)
            session.commit()
        else:
            flash("Character is already added to campaign")

        return redirect(url_for('campaign.view', id=id))

    createinviteform.submit.label.text = "Create share link."

    handouts = campaign.handouts.filter_by(status=HandoutStatus.visible)
    messages = campaign.messages.filter(
        or_(Message.from_id == current_user.profile.id,
            Message.to_id == current_user.profile.id, Message.to_id.is_(None)))

    added_npc_ids = [c.character_id for c in campaign.NPCs]

    npcform.character.query = current_user.profile.characters.filter(
        Character.id.notin_(added_npc_ids)).\
        order_by(
            Character.folder_id.__eq__(campaign.folder_id).desc()).\
        order_by('title')

    added_character_ids = [c.id for c in campaign.characters]
    characterform.character.query = current_user.profile.characters.\
        filter(Character.id.notin_(added_character_ids)).\
        order_by(Character.folder_id.__eq__(campaign.folder_id).desc()).\
        order_by('title')

    return render_template('campaign/campaign.html.jinja',
                           campaign=campaign,
                           handouts=handouts,
                           invites=invites,
                           inviteform=inviteform,
                           createinviteform=createinviteform,
                           characterform=characterform,
                           messages=messages,
                           npcform=npcform,
                           editable=is_owner,
                           messageform=messageform)