Пример #1
0
def invite_user():
    """Invites a new user to create an account and set their own password."""
    form = InviteUserForm()
    if form.validate_on_submit():
        user = User(
            role=form.role.data,
            user_name=form.user_name.data,
            full_name=form.full_name.data,
            email=form.email.data)
        db.session.add(user)
        db.session.commit()
        token = user.generate_confirmation_token()
        invite_link = url_for(
            'account.join_from_invite',
            user_id=user.id,
            token=token,
            _external=True)
        get_queue().enqueue(
            send_email,
            recipient=user.email,
            subject='You Are Invited To Join',
            template='account/email/invite',
            user=user,
            invite_link=invite_link,
        )
        flash('User {} successfully invited'.format(user.full_name),
              'form-success')
    return render_template('admin/new_user.html', form=form)
Пример #2
0
def invite_user():
    """Invites a new user to create an account and set their own password."""
    form = InviteUserForm()
    if form.validate_on_submit():
        user = User(
            #role=form.role.data,
            first_name=form.first_name.data,
            last_name=form.last_name.data,
            email=form.email.data)
        db.session.add(user)
        db.session.commit()
        user.role.append(form.role.data)
        db.session.commit()
        token = user.generate_confirmation_token()
        invite_link = url_for(
            'account.join_from_invite',
            user_id=user.id,
            token=token,
            _external=True)
        status = send_email(recipient=user.email,subject= 'You Are Invited To Join Us',
                            template='account/email/invite',user=user,invite_link=invite_link)
        # get_queue().enqueue(
        #     send_email,
        #     recipient=user.email,
        #     subject='You Are Invited To Join',
        #     template='account/email/invite',
        #     user=user,
        #     invite_link=invite_link,
        # )
        if status:
            flash('A new user was successfully invited','form-success')

    return render_template('admin/new_user.html', form=form)
Пример #3
0
def invite_user():
    """Invites a new user to create an account and set their own password."""
    form = InviteUserForm()
    if form.validate_on_submit():
        user = User(
            role=form.role.data,
            first_name=form.first_name.data,
            last_name=form.last_name.data,
            email=form.email.data,
        )
        db.session.add(user)
        db.session.commit()
        token = user.generate_confirmation_token()
        invite_link = url_for(
            "account.join_from_invite", user_id=user.id, token=token, _external=True
        )
        user.__dict__.pop("storage_files")
        get_queue().enqueue(
            send_email,
            recipient=user.email,
            subject="You Are Invited To Join",
            template="account/email/invite",
            user=user,
            invite_link=invite_link,
        )
        flash("User {} successfully invited".format(user.full_name()), "form-success")
    return render_template("admin/new_user.html", form=form)
Пример #4
0
def admin():
    if current_user.admin_level < current_app.config['ADMIN_LEVEL_EDIT_USER']:
        flash('You are not authorized to view the admin panel.', 'danger')
        return redirect(url_for('index.main'))
    form = InviteUserForm()
    if form.validate_on_submit():
        password = secrets.token_hex(nbytes=16)
        user = User(email=form.email.data)
        user.set_password(password)
        db.session.add(user)
        db.session.commit()
        email.send_registration_invitation_email(user)
        flash('Invitation sent!', 'success')
        return redirect(url_for('main.index'))
    users = User.query.order_by(User.id).all()
    return render_template('admin/admin.html',
                           title='Admin',
                           form=form,
                           users=users)