Ejemplo n.º 1
0
def register_event(event):
    form = EventRegistrationForm()
    members = current_user.get_members()
    event = Event.query.filter_by(id=int(event)).first()
    form.members.choices = [(member.id, "{} {}".format(member.fname,
                                                       member.lname))
                            for member in members]
    if request.method == 'POST':
        member_id = form.members.data
        member = Member.query.filter_by(id=member_id).first()
        if member.has_registered(event):
            flash('The member has already registered the event!')
            return redirect(url_for('index'))
        elif event.registrable():
            member.register(event)
            event.participants = event.participants + 1
            db.session.commit()
            send_confirmation_email(current_user, member, event)
            flash('The member has successfully registered the event!')
            return redirect(url_for('index'))
        else:
            flash(
                'There registration is up to limit, contact us for further info!'
            )
            return redirect(url_for('index'))
    return render_template('event_register.html', form=form)
Ejemplo n.º 2
0
def register():

    if current_user.is_authenticated:
        return redirect(url_for('index'))

    form = RegistrationForm()

    if form.validate_on_submit():
        user = User(username=form.username.data,
                    email=form.email.data,
                    email_confirmed=False)
        user.set_password(form.password.data)

        # if (form.email.data)[-4:0] == '.edu':
        db.session.add(user)
        db.session.commit()
        token = app.config['SERIALIZER'].dumps(user.email,
                                               salt='email-confirm')
        send_confirmation_email(user.email, token, user.username)
        flash(
            'Congratulations, you are now a registered user! Please check your email for confirmation'
        )
        return redirect(url_for('login'))
        # else:
        #     flash("Please use your school email to register!")

    return render_template('register.html', title='Register', form=form)
Ejemplo n.º 3
0
def register():
    """ End-point to handle User/Staff Registration """

    form = UserRegistrationForm()
    position = current_user.position
    if current_user.is_master():
        position = 'Master'

    if form.validate_on_submit():
        if dict(form.position.choices).get(
                form.position.data) == "Upper Management":
            if not current_user.is_master(
            ) and current_user.position != "Upper Management":
                flash("You don't have permissions to set Upper Management.")
                return redirect(url_for('auth.register'))

        academy = Academy.query.filter_by(
            name=dict(form.academy.choices).get(form.academy.data)).first()

        if not current_user.is_master(
        ) and current_user.position != "Upper Management":
            if not current_user.has_academy_access(academy.id):
                flash('You can only add people to your own academy.')
                return redirect(url_for('auth.register'))
        send_confirmation_email(form.email.data)
        flash('Please check given email to confirm the email address.',
              'success')
        user = User(username=form.username.data,
                    name=form.name.data,
                    phone=form.phone.data,
                    email=form.email.data,
                    position=form.position.data)
        user.set_password(form.password.data)
        db.session.add(user)
        db.session.commit()

        trained = form.trained.data
        for t in trained:
            i = TrainedIn(name=t, teacher=user.id)
            db.session.add(i)
            db.session.commit()
        user.academy_id = academy.id
        permission = PermissionGroups.query.filter_by(
            group_name=form.position.data).first()
        user.add_access(permission)
        db.session.commit()
        flash('Registration successful.')
        return redirect(url_for('staff.user', name=user.name))
    return render_template('auth/user_register.html',
                           title="Register Staff",
                           form=form,
                           position=position)
Ejemplo n.º 4
0
def register():
    if(current_user.is_authenticated):
        return(redirect(url_for("index", title = "Home")))
    form = RegistrationForm()
    if(form.validate_on_submit()):
        user = User(username = form.username.data, email = form.email.data)
        user.set_password(form.password.data)
        if(form.display_picture.data):
            if(not file_uploader(form.username.data, form.display_picture.data, USER_UPLOAD_FOLDER)):
                db.session.rollback()
                return(redirect(url_for("register", title = "Sign Up")))
        db.session.add(user)
        db.session.commit()
        send_confirmation_email(user)
        flash("Congratulations you have now joined, please check your email for an email confirmation link", category = "info")
        return(redirect(url_for("login", title = "Sign In")))
    return(render_template("register.html", title = "Sign Up", form = form))
Ejemplo n.º 5
0
def register_league(league):
    form = LeagueRegistrationForm()
    league = League.query.filter_by(id=int(league)).first()
    teams = current_user.get_teams()
    if teams is not None:
        form.teams.choices = [(team.id, "{}".format(team.name))
                              for team in teams]
    if request.method == 'POST':
        if form.new_team.data:
            # create a new team
            team = Team.query.filter_by(name=form.new_team.data).first()
            if team is not None and team.account_id == current_user.id:
                flash(
                    'The team already exists, please select the team in the menu or create a team with another name!'
                )
                return redirect(url_for('register_league', league=league.id))
            else:
                team = Team(name=form.new_team.data, account=current_user)
                db.session.add(team)
        else:
            team_id = form.teams.data
            team = Team.query.filter_by(id=team_id).first()
        if team.has_registered(league):
            flash('The team has already registered the league!')
            return redirect(url_for('index'))
        elif league.registrable():
            league_team = League_Team(
                league_id=league.id,
                team_id=team.id,
                scheduling_requests=form.scheduling_requests.data)
            league.team_num = league.team_num + 1
            league_team.league = league
            league_team.team = team
            db.session.add(league_team)
            db.session.commit()
            send_confirmation_email(current_user, team, league)
            flash('The member has successfully registered the event!')
            return redirect(url_for('index'))
        else:
            flash(
                'There registration is up to limit, contact us for further info!'
            )
            return redirect(url_for('index'))
    return render_template('league_register.html', form=form)
def contact():
    static = StaticElements.query.first()
    socials = SocialMediaLink.query.order_by(SocialMediaLink.order).all()
    form = ContactForm()
    if form.validate_on_submit():
        message = Message(name=form.name.data,
                          email=form.email.data,
                          message=form.message.data)
        db.session.add(message)
        db.session.commit()
        send_message_email(message)
        send_confirmation_email(message)
        flash(
            "You're message has been sent! You will also receive confirmation by email."
        )
        return redirect(url_for('contact'))
    return render_template('contact.html',
                           title='Contact',
                           static=static,
                           form=form,
                           socials=socials)
Ejemplo n.º 7
0
def qrcode():
    if 'username' not in session:
        abort(404)
    user = User.query.filter_by(username=session['username']).first()

    if user is None:
        abort(404)

    del session['username']

    url = pyqrcode.create(user.get_totp_uri())
    stream = BytesIO()
    url.svg(stream, scale=5)

    send_confirmation_email(user)
    return stream.getvalue(), 200, {
        'Content-Type': 'image/svg+xml',
        'Cache-Control': 'no-cache, no-store, must-revalidate',
        'Pragma': 'no-cache',
        'Expires': '0'
    }
Ejemplo n.º 8
0
def confirm_email_request():
    if current_user.email and current_user.email_confirmed:
        flash("Your email is already confirmed!", "warning")
        return redirect(url_for('user', username=current_user.username))

    if current_user.email:
        send_confirmation_email(current_user, current_user.email)
        flash('A confirmation email has been sent to your inbox', 'success')
        return redirect(url_for('user', username=current_user.username))

    form = ConfirmEmailRequestForm()
    if form.validate_on_submit():
        user = User.query.filter_by(email=form.email.data).first()
        if user:
            flash("That email is already taken!", "danger")
        else:
            current_user.email = form.email.data
            db.session.commit()
            send_confirmation_email(current_user, form.email.data)
            flash('A confirmation email has been sent to your inbox',
                  'success')
            return redirect(url_for('user', username=current_user.username))

    return render_template("confirm_email_request.html", form=form)
Ejemplo n.º 9
0
def edit_user(name):
    """ End-Point to handle changes to User/Staff data """

    user = User.query.filter_by(name=name).first()
    academy = Academy.query.filter_by(id=user.academy_id).first()
    trained = TrainedIn.query.filter_by(teacher=user.id).all()

    if user.position == "Upper Management" or user.is_master():
        if not current_user.is_master(
        ) and current_user.position != "Upper Management":
            flash("You don't have permissions to edit Upper Management.")
            return redirect(url_for('staff.user', name=name))
    if not current_user.is_master(
    ) and current_user.position != "Upper Management":
        if current_user.academy_id != academy.id:
            flash('You can only edit profiles from your own academy.')
            return redirect(url_for('staff.user', name=name))
    form = EditProfileForm(obj=user.id)
    position = current_user.position
    position_edit = user.position

    if current_user.is_master():
        position = 'Master'

    if form.validate_on_submit():
        if dict(form.position.choices).get(
                form.position.data) == "Upper Management":
            if not current_user.is_master(
            ) and current_user.position != "Upper Management":
                flash("You don't have permissions to set Upper Management.")
                return redirect(url_for('staff.user', name=name))

        academy_new = Academy.query.filter_by(
            name=dict(form.academy.choices).get(form.academy.data)).first()

        if not current_user.is_master(
        ) and current_user.position != "Upper Management":
            if current_user.academy_id != academy_new.id:
                flash('You can only edit profiles from your own academy.')
                return redirect(url_for('staff.user', name=name))

        if user.name != form.name.data:
            user.name = form.name.data
            db.session.commit()
        if user.phone != form.phone.data:
            user.phone = form.phone.data
            db.session.commit()
        if user.email != form.email.data:
            user.email = form.email.data
            send_confirmation_email(form.email.data)
            flash('Please check given email to confirm the email address.',
                  'success')
            db.session.commit()
        if user.position != form.position.data:
            permission_old = PermissionGroups.query.filter_by(
                group_name=user.position).first()
            permission_new = PermissionGroups.query.filter_by(
                group_name=form.position.data).first()
            user.remove_access(permission_old)
            user.add_access(permission_new)
            user.position = form.position.data
            db.session.commit()
        if academy.name != academy_new.name:
            user.academy_id = academy_new.id
            db.session.commit()

        trained_new = form.trained.data
        for t in trained_new:
            u = TrainedIn.query.filter_by(teacher=user.id).filter_by(
                name=t).first()
            if u is None:
                i = TrainedIn(name=t, teacher=user.id)
                db.session.add(i)
                db.session.commit()
        for t in trained:
            if t.name not in trained_new:
                db.session.delete(t)
                db.session.commit()

        flash('User information updated')
        return redirect(url_for('staff.user', name=user.name))
    elif not form.is_submitted():
        form.name.data = user.name
        form.phone.data = user.phone
        form.email.data = user.email
        form.position.data = user.position
        form.academy.data = academy.name
        form.trained.data = [t.name for t in trained]
    return render_template('staff/edit_user.html',
                           title='Edit User',
                           user=user,
                           form=form,
                           position=position,
                           position_edit=position_edit)