当前位置: 首页>>代码示例>>Python>>正文


Python User.login_code方法代码示例

本文整理汇总了Python中models.user.User.login_code方法的典型用法代码示例。如果您正苦于以下问题:Python User.login_code方法的具体用法?Python User.login_code怎么用?Python User.login_code使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在models.user.User的用法示例。


在下文中一共展示了User.login_code方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: users

# 需要导入模块: from models.user import User [as 别名]
# 或者: from models.user.User import login_code [as 别名]
def users():
    form = NewUserForm()

    if form.validate_on_submit():
        email, name = form.email.data, form.name.data
        user = User(email, name)

        db.session.add(user)
        db.session.commit()
        app.logger.info('%s manually created new user with email %s and id: %s',
                        current_user.id, email, user.id)

        code = user.login_code(app.config['SECRET_KEY'])
        msg = Message('Welcome to the EMF website',
                      sender=app.config['CONTACT_EMAIL'],
                      recipients=[email])
        msg.body = render_template('emails/manually-added-user.txt',
                                   user=user, code=code)
        mail.send(msg)

        flash('Created account for: %s' % name)
        return redirect(url_for('.users'))

    users = User.query.order_by(User.id).options(joinedload(User.permissions)).all()
    return render_template('admin/users/users.html', users=users, form=form)
开发者ID:dominicgs,项目名称:Website,代码行数:27,代码来源:users.py

示例2: tickets_reserve

# 需要导入模块: from models.user import User [as 别名]
# 或者: from models.user.User import login_code [as 别名]
def tickets_reserve(email):
    user = User.get_by_email(email)

    if user is None:
        form = ReserveTicketsNewUserForm()
        new_user = True
    else:
        form = ReserveTicketsForm()
        new_user = False

    pts = PriceTier.query.join(Product, ProductGroup) \
                         .order_by(ProductGroup.name, Product.display_name, Product.id).all()

    form.add_price_tiers(pts)

    if form.validate_on_submit():
        if not user:
            name = form.name.data

            app.logger.info('Creating new user with email %s and name %s', email, name)
            user = User(email, name)
            flash('Created account for %s' % name)
            db.session.add(user)

        basket = form.create_basket(user)

        app.logger.info('Admin basket for %s %s', user.email, basket)

        try:
            basket.create_purchases()
            basket.ensure_purchase_capacity()

            db.session.commit()

        except CapacityException as e:
            db.session.rollback()
            app.logger.warn('Limit exceeded creating admin tickets: %s', e)
            return redirect(url_for('.tickets_reserve', email=email))

        code = user.login_code(app.config['SECRET_KEY'])
        msg = Message('Your reserved tickets to EMF',
                      sender=app.config['TICKETS_EMAIL'],
                      recipients=[user.email])

        msg.body = render_template('emails/tickets-reserved.txt',
                            user=user, code=code, tickets=basket.purchases,
                            new_user=new_user, currency=form.currency.data)

        mail.send(msg)
        db.session.commit()

        flash('Reserved tickets and emailed {}'.format(user.email))
        return redirect(url_for('.tickets_issue'))

    return render_template('admin/tickets/tickets-reserve.html',
                           form=form, pts=pts, user=user)
开发者ID:emfcamp,项目名称:Website,代码行数:58,代码来源:tickets.py

示例3: tickets_choose_free

# 需要导入模块: from models.user import User [as 别名]
# 或者: from models.user.User import login_code [as 别名]
def tickets_choose_free(user_id=None):
    has_price = TicketPrice.query.filter(TicketPrice.price_int > 0)

    free_tts = TicketType.query.filter(
        ~has_price.filter(TicketPrice.type.expression).exists(),
    ).order_by(TicketType.order).all()

    if user_id is None:
        form = FreeTicketsNewUserForm()
        user = None
        new_user = True
    else:
        form = FreeTicketsForm()
        user = User.query.get_or_404(user_id)
        new_user = False

    if request.method != 'POST':
        for tt in free_tts:
            form.types.append_entry()
            form.types[-1].type_id.data = tt.id

    tts = {tt.id: tt for tt in free_tts}
    for f in form.types:
        f._type = tts[f.type_id.data]
        # TODO: apply per-user limits
        values = range(f._type.personal_limit + 1)
        f.amount.values = values
        f._any = any(values)

    if form.validate_on_submit():
        if new_user:
            app.logger.info('Creating new user with email %s and name %s',
                            form.email.data, form.name.data)
            user = User(form.email.data, form.name.data)
            flash('Created account for %s' % form.email.data)

        tickets = []
        for f in form.types:
            if f.amount.data:
                tt = f._type
                for i in range(f.amount.data):
                    t = Ticket(type=tt, user_id=user_id)
                    t.paid = True
                    user.tickets.append(t)
                    tickets.append(t)

                app.logger.info('Allocated %s %s tickets to user', f.amount.data, tt.name)

        db.session.add(user)
        db.session.commit()

        code = user.login_code(app.config['SECRET_KEY'])
        msg = Message('Your complimentary tickets to EMF',
                      sender=app.config['TICKETS_EMAIL'],
                      recipients=[user.email])

        msg.body = render_template('emails/tickets-free.txt',
                            user=user, code=code, tickets=tickets,
                            new_user=new_user)

        if feature_enabled('ISSUE_TICKETS'):
            attach_tickets(msg, user)

        mail.send(msg)

        flash('Allocated %s ticket(s)' % len(tickets))
        return redirect(url_for('.tickets_choose_free'))

    if new_user:
        users = User.query.order_by(User.id).all()
    else:
        users = None

    return render_template('admin/tickets-choose-free.html',
                           form=form, tts=free_tts, user=user, users=users)
开发者ID:bfirsh,项目名称:Website,代码行数:77,代码来源:tickets.py

示例4: transfer

# 需要导入模块: from models.user import User [as 别名]
# 或者: from models.user.User import login_code [as 别名]
def transfer(ticket_id):
    try:
        ticket = current_user.owned_purchases.filter_by(id=ticket_id).one()
    except NoResultFound:
        abort(404)

    if not ticket.is_paid_for:
        flash("Unpaid tickets cannot be transferred")
        return redirect(url_for('users.purchases'))

    if not ticket.product.get_attribute('is_transferable'):
        flash("This purchase cannot be transferred")
        return redirect(url_for('users.purchases'))

    form = TicketTransferForm()

    if form.validate_on_submit():
        email = form.email.data

        if not User.does_user_exist(email):
            new_user = True

            # Create a new user to transfer the ticket to
            to_user = User(email, form.name.data)
            db.session.add(to_user)
            db.session.commit()

        else:
            new_user = False
            to_user = User.get_by_email(email)

        ticket = Ticket.query.with_for_update().get(ticket_id)
        assert ticket.owner_id == current_user.id

        ticket.transfer(from_user=current_user, to_user=to_user)
        db.session.commit()

        app.logger.info('Ticket %s transferred from %s to %s', ticket,
                        current_user, to_user)

        # Alert the users via email
        code = to_user.login_code(app.config['SECRET_KEY'])

        msg = Message("You've been sent a ticket to EMF!",
                      sender=app.config.get('TICKETS_EMAIL'),
                      recipients=[to_user.email])

        already_emailed = set_tickets_emailed(to_user)
        msg.body = render_template('emails/ticket-transfer-new-owner.txt',
                                   to_user=to_user, from_user=current_user,
                                   new_user=new_user, code=code,
                                   already_emailed=already_emailed)

        if feature_enabled('ISSUE_TICKETS'):
            attach_tickets(msg, to_user)

        mail.send(msg)
        db.session.commit()

        msg = Message("You sent someone an EMF ticket",
                      sender=app.config.get('TICKETS_EMAIL'),
                      recipients=[current_user.email])
        msg.body = render_template('emails/ticket-transfer-original-owner.txt',
                                   to_user=to_user, from_user=current_user)

        mail.send(msg)

        flash("Your ticket was transferred.")
        return redirect(url_for('users.purchases'))

    return render_template('ticket-transfer.html', ticket=ticket, form=form)
开发者ID:emfcamp,项目名称:Website,代码行数:73,代码来源:__init__.py

示例5: tickets_issue_free

# 需要导入模块: from models.user import User [as 别名]
# 或者: from models.user.User import login_code [as 别名]
def tickets_issue_free(email):
    user = User.get_by_email(email)

    if user is None:
        form = IssueFreeTicketsNewUserForm()
        new_user = True
    else:
        form = IssueTicketsForm()
        new_user = False

    free_pts = PriceTier.query.join(Product).filter(
        ~PriceTier.prices.any(Price.price_int > 0),
    ).order_by(Product.name).all()

    form.add_price_tiers(free_pts)

    if form.validate_on_submit():
        if not user:
            app.logger.info('Creating new user with email %s and name %s',
                            email, form.name.data)
            user = User(email, form.name.data)
            db.session.add(user)
            flash('Created account for %s' % email)

        basket = form.create_basket(user)
        app.logger.info('Admin basket for %s %s', user.email, basket)

        try:
            basket.create_purchases()
            basket.ensure_purchase_capacity()
            assert basket.total == 0

        except CapacityException as e:
            db.session.rollback()
            app.logger.warn('Limit exceeded creating admin tickets: %s', e)
            return redirect(url_for('.tickets_issue_free', email=email))

        for p in basket.purchases:
            p.set_state('paid')

        app.logger.info('Allocated %s tickets to user', len(basket.purchases))
        db.session.commit()

        code = user.login_code(app.config['SECRET_KEY'])
        msg = Message('Your complimentary tickets to Electromagnetic Field',
                      sender=app.config['TICKETS_EMAIL'],
                      recipients=[user.email])

        already_emailed = set_tickets_emailed(user)
        msg.body = render_template('emails/tickets-free.txt',
                            user=user, code=code, tickets=basket.purchases,
                            new_user=new_user, already_emailed=already_emailed)

        if feature_enabled('ISSUE_TICKETS'):
            attach_tickets(msg, user)

        mail.send(msg)
        db.session.commit()

        flash('Allocated %s ticket(s)' % len(basket.purchases))
        return redirect(url_for('.tickets_issue'))
    return render_template('admin/tickets/tickets-issue-free.html',
                           form=form, user=user, email=email)
开发者ID:emfcamp,项目名称:Website,代码行数:65,代码来源:tickets.py


注:本文中的models.user.User.login_code方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。