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


Python User.get_by_email方法代码示例

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


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

示例1: login

# 需要导入模块: from models.user import User [as 别名]
# 或者: from models.user.User import get_by_email [as 别名]
def login():
    is_pwd = request.values.get('is_pwd', '')
    username = request.values.get('username', '')
    password = request.values.get('password', '')
    if is_pwd:
        if check_auth_by_mail(username, password):
            user = User.query.filter_by(email=username).first()
            data = {
                'uid': user.id,
                'name': user.name,
                'email': user.email
            }
            return jsonify({'ret': True, 'data': data})
        else:
            return jsonify({'ret': False, 'msg': u'用户名或密码不正确'})
    else:
        user = User.get_by_email(email=username.lower())
        if user and user.check_password(password):
            data = {
                'uid': user.id,
                'name': user.name,
                'email': user.email
            }
            return jsonify({'ret': True, 'data': data})
        else:
            return jsonify({'ret': False, 'msg': u'用户名或密码不正确'})
    return jsonify({'ret': False})
开发者ID:giveme168,项目名称:braavos,代码行数:29,代码来源:account.py

示例2: create_new_post

# 需要导入模块: from models.user import User [as 别名]
# 或者: from models.user.User import get_by_email [as 别名]
def create_new_post(blog_id):
    
    user = User.get_by_email(session['email']) 
    blogs = user.get_blogs()    
    
    if request.method == 'GET':
        return render_template('new_post.html', blog_id=blog_id,blogs=blogs, email=user.email)
    else:
        title = request.form['title']
        content = request.form['content']
        user = User.get_by_email(session['email'])

        new_post = Post(blog_id, title, content, user.email)
        new_post.save_to_mongo()

        return make_response(blog_posts(blog_id))
开发者ID:wmsgood,项目名称:Mongoblog,代码行数:18,代码来源:app.py

示例3: test_add_user

# 需要导入模块: from models.user import User [as 别名]
# 或者: from models.user.User import get_by_email [as 别名]
def test_add_user(session):
    user = add_user('testuser1', DEFAULT_PASSWORD)

    user2 = User.get_by_email('[email protected]')
    assert user2.id == user.id
    assert user2.email == user.email
    assert user2.check_password(DEFAULT_PASSWORD)
开发者ID:giveme168,项目名称:braavos,代码行数:9,代码来源:test_user.py

示例4: create_new_blog

# 需要导入模块: from models.user import User [as 别名]
# 或者: from models.user.User import get_by_email [as 别名]
def create_new_blog():
    
    user = User.get_by_email(session['email']) 
    blogs = user.get_blogs() 
    
    
    if request.method == 'GET':
        return render_template('new_blog.html', blogs=blogs, email=user.email)
    else:
        title = request.form['title']
        description = request.form['description']
        user = User.get_by_email(session['email'])

        new_blog = Blog(user.email, title, description, user._id)
        new_blog.save_to_mongo()

        return make_response(user_blogs(user._id))
开发者ID:wmsgood,项目名称:Mongoblog,代码行数:19,代码来源:app.py

示例5: blog_posts

# 需要导入模块: from models.user import User [as 别名]
# 或者: from models.user.User import get_by_email [as 别名]
def blog_posts(blog_id):
    user = User.get_by_email(session['email']) 
    blogs = user.get_blogs() 
    
    blog = Blog.from_mongo(blog_id)
    posts = blog.get_posts()
        
    return render_template('posts.html', posts=posts, blog_title=blog.title, blog_id=blog._id,blogs=blogs, email=user.email)
开发者ID:wmsgood,项目名称:Mongoblog,代码行数:10,代码来源:app.py

示例6: get_default_user

# 需要导入模块: from models.user import User [as 别名]
# 或者: from models.user.User import get_by_email [as 别名]
def get_default_user():
    name = 'defaultuser'
    email = '[email protected]'
    user = User.get_by_email(email)
    if user:
        return user
    else:
        return add_user(name)
开发者ID:giveme168,项目名称:braavos,代码行数:10,代码来源:helper.py

示例7: user_blogs

# 需要导入模块: from models.user import User [as 别名]
# 或者: from models.user.User import get_by_email [as 别名]
def user_blogs(user_id=None):
	if user_id is not None:
		user = User.get_by_id(user_id)
	else:
		user = User.get_by_email(sesssion['email'])

	blogs = user.get_blogs()

	return render_template('user_blogs.html', blogs=blogs, email=user.email)
开发者ID:asimonia,项目名称:web-blog,代码行数:11,代码来源:app.py

示例8: login_by_email

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

    if current_user.is_authenticated():
        logout_user()

    login_user(user)
    session.permanent = True
    return redirect(request.args.get('next', url_for('tickets.main')))
开发者ID:bfirsh,项目名称:Website,代码行数:11,代码来源:users.py

示例9: tickets_reserve

# 需要导入模块: from models.user import User [as 别名]
# 或者: from models.user.User import get_by_email [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

示例10: login_by_email

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

    if current_user.is_authenticated:
        logout_user()

    if user is None:
        flash("Your email address was not recognised")
    else:
        login_user(user)
        session.permanent = True

    return redirect(request.args.get('next', url_for('.account')))
开发者ID:dominicgs,项目名称:Website,代码行数:15,代码来源:users.py

示例11: test_schedule

# 需要导入模块: from models.user import User [as 别名]
# 或者: from models.user.User import get_by_email [as 别名]
def test_schedule(session):
    unit1 = add_unit('unit1', 800)
    unit2 = add_unit('unit2', 700)
    position1 = add_position('position1')
    position2 = add_position('position2')
    position1.units = [unit1, unit2]
    position2.units = [unit1, unit2]

    assert unit1.estimate_num == 800
    assert unit2.estimate_num == 700
    assert position1.estimate_num == unit1.estimate_num + unit2.estimate_num
    assert position2.estimate_num == unit1.estimate_num + unit2.estimate_num

    item1 = add_item(position=position1)
    item2 = add_item(position=position2)

    _date = date.today()

    assert position1.schedule_num(_date) == 0
    assert position2.schedule_num(_date) == 0

    assert unit1.schedule_num(_date) == 0
    assert unit2.schedule_num(_date) == 0

    assert unit1.retain_num(_date) == 800
    assert unit2.retain_num(_date) == 700

    assert position1.retain_num(_date) == 1500
    assert position2.retain_num(_date) == 1500

    AdSchedule.add(item1, 500, _date)
    AdSchedule.add(item2, 100, _date)

    user = User.get_by_email('[email protected]')
    AdItem.update_items_with_action([item1], ITEM_STATUS_ACTION_PRE_ORDER, user)
    AdItem.update_items_with_action([item2], ITEM_STATUS_ACTION_PRE_ORDER, user)

    assert position1.schedule_num(_date) == 500
    assert position2.schedule_num(_date) == 100

    assert unit1.schedule_num(_date) == 320
    assert unit2.schedule_num(_date) == 280

    assert unit1.retain_num(_date) == 480
    assert unit2.retain_num(_date) == 420

    assert position1.retain_num(_date) == 900
    assert position2.retain_num(_date) == 900
开发者ID:giveme168,项目名称:braavos,代码行数:50,代码来源:test_schedule.py

示例12: user_blogs

# 需要导入模块: from models.user import User [as 别名]
# 或者: from models.user.User import get_by_email [as 别名]
def user_blogs(user_id=None):
    if user_id is not None:
        user = User.get_by_id(user_id)
    else:
        user = User.get_by_email(session['email'])
        
    blogs = user.get_blogs()
    
    blog_id = request.args.get('bg')
    
    if blog_id is not None:
        blog = Blog.from_mongo(blog_id)
        posts = blog.get_posts()
        return render_template("user_blogs.html", blogs=blogs, email=user.email,posts=posts, blog_title=blog.title, blog_id=blog._id)
    
    return render_template("user_blogs.html", blogs=blogs, email=user.email)
开发者ID:wmsgood,项目名称:Mongoblog,代码行数:18,代码来源:app.py

示例13: run

# 需要导入模块: from models.user import User [as 别名]
# 或者: from models.user.User import get_by_email [as 别名]
    def run(self):
        fake = Faker()
        if not User.query.filter_by(email='[email protected]').first():
            user_admin = User('[email protected]', 'Test Admin')
            user_admin.grant_permission('admin')
            db.session.add(user_admin)

        if not User.query.filter_by(email='[email protected]').first():
            user_cfp_admin = User('[email protected]', 'Test CFP Admin')
            user_cfp_admin.grant_permission('cfp_admin')
            db.session.add(user_cfp_admin)

        if not User.query.filter_by(email='[email protected]').first():
            user_anonymiser = User('[email protected]', 'Test Anonymiser')
            user_anonymiser.grant_permission('cfp_anonymiser')
            db.session.add(user_anonymiser)

        reviewers = []
        for i in range(10):
            email = 'reviewer{}@test.invalid'.format(i)
            user = User.query.filter_by(email=email).first()
            if not user:
                user = User(email, 'Reviewer {}'.format(i))
                user.grant_permission('cfp_reviewer')
                db.session.add(user)
            reviewers.append(user)

        if not User.query.filter_by(email='[email protected]').first():
            user_arrivals = User('[email protected]', 'Test Arrivals')
            user_arrivals.grant_permission('arrivals')
            db.session.add(user_arrivals)


        for i in range(0, 500):
            email = fake.safe_email()
            if User.get_by_email(email):
                continue
            user = User(email, fake.name())

            for i in range(0, int(round(random.uniform(0, 2)))):
                cfp = fake_proposal(fake, reviewers)
                cfp.user = user

            db.session.add(user)

        db.session.commit()
开发者ID:dominicgs,项目名称:Website,代码行数:48,代码来源:dev.py

示例14: transfer_ticket_user

# 需要导入模块: from models.user import User [as 别名]
# 或者: from models.user.User import get_by_email [as 别名]
def transfer_ticket_user(ticket_id, email):
    ticket = Ticket.query.get_or_404(ticket_id)

    if not ticket.is_paid_for:
        flash("Unpaid tickets cannot be transferred")
        return redirect(url_for('.user', user_id=ticket.owner_id))

    if not ticket.product.get_attribute('is_transferable'):
        flash("This purchase cannot be transferred")
        return redirect(url_for('.user', user_id=ticket.owner_id))

    user = User.get_by_email(email)

    if user is None:
        form = TransferTicketNewUserForm()
    else:
        form = TransferTicketForm()

    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)

        ticket = Ticket.query.with_for_update().get(ticket.id)

        previous_owner = ticket.owner
        # This contract is loopy
        ticket.transfer(from_user=previous_owner, to_user=user)
        db.session.commit()

        app.logger.info('Ticket %s transferred from %s to %s', ticket,
                        previous_owner, user)

        # We don't send any emails because this is an admin operation

        flash('Transferred ticket {}'.format(ticket.id))
        return redirect(url_for('.user', user_id=user.id))

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

示例15: tickets_issue_free

# 需要导入模块: from models.user import User [as 别名]
# 或者: from models.user.User import get_by_email [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.get_by_email方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。