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


Python User.get方法代码示例

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


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

示例1: before_request

# 需要导入模块: from db import User [as 别名]
# 或者: from db.User import get [as 别名]
def before_request():
    g.user = None
    try:
        if 'id' in session:
            g.user = User.get(User.id == session['id'])

    except User.DoesNotExist:
        g.user = None

    if "test" in request.headers:
        g.user = User.get(User.id == request.headers.get("test"))
开发者ID:b1naryth1ef,项目名称:juicebox,代码行数:13,代码来源:app.py

示例2: join

# 需要导入模块: from db import User [as 别名]
# 或者: from db.User import get [as 别名]
def join():
	if request.method == 'GET':
		return render_template('join.html')
	username = request.form.get('username')
	password = request.form.get('password')
	email = request.form.get('email')
	if not username:
		flash('Please input username')
            	return redirect(url_for('join'))
	elif not password:
		flash('Please input password')
            	return redirect(url_for('join'))
	elif not email:
		flash('Please input email')
            	return redirect(url_for('join'))
        try:
         	# use the .get() method to quickly see if a user with that name exists
           	user = User.get(username=username)
            	flash('That username is already taken')
	except User.DoesNotExist:
           	# if not, create the user and store the form data on the new model
            	user = User.create(username=username,
			password=md5(password).hexdigest(),	
			email=email,join_date=datetime.datetime.now())
            		# mark the user as being 'authenticated' by setting the session vars
           	auth_user(user)
            	return redirect(url_for('homepage'))
开发者ID:justasabc,项目名称:python_tutorials,代码行数:29,代码来源:app.py

示例3: index

# 需要导入模块: from db import User [as 别名]
# 或者: from db.User import get [as 别名]
def index(response):
    form_id = response.get_field('form_id', 'front')
    if form_id == 'front':
        response.write(LOGIN_HTML)
    elif form_id == 'login':
        user = response.get_field('user')
        try:
            user = User.get(user=user)
            set_user(response, user)
            response.redirect('/profile')
        except DoesNotExistError:
            response.redirect('/')
    elif form_id == 'signup':
        user = response.get_field('user')
        passwd1 = response.get_field('passwd1')
        #passwd2 = response.get_field('passwd2')
        first = response.get_field('first')
        last = response.get_field('last')
        dob = response.get_field('dob')
        logger.info('adding user {} ({} {}) with passwd {}'.format(user, first, last, passwd1))
        if user and first and last and passwd1:
            try:
                user = User.add(user=user, passwd=passwd1, first=first, last=last, dob=dob)
                set_user(response, user)
                response.redirect('/profile')
            except IntegrityError:
                response.write(LOGIN_HTML)
        else:
            response.write(LOGIN_HTML)
开发者ID:kennib,项目名称:ncssbook,代码行数:31,代码来源:ncssbook.py

示例4: get_user_rating

# 需要导入模块: from db import User [as 别名]
# 或者: from db.User import get [as 别名]
def get_user_rating():
    name = request.args.get('name')
    if name is None:
        abort(400)
    fmt = request.args.get('format', 'json')
    try:
        user = User.get(User.user == name)
    except User.DoesNotExist:
        abort(404)
    if fmt == 'xml':
        def quoteattr(s):
            return '"{0}"'.format(str(s)
                                  .replace('&', '&')
                                  .replace('<', '&lt;')
                                  .replace('>', '&gt;')
                                  .replace('"', '&quot;'))
        xml = '<?xml version="1.0" encoding="UTF-8"?>\n<mmwatch>\n'
        for field in (
            ('name', user.user.encode('utf-8')),
            ('rank', user.rank),
            ('edits', user.edits),
            ('joined', user.joined.isoformat())
        ):
            xml = xml + '  <{0} value={1} />\n'.format(field[0], quoteattr(field[1]))
        xml = xml + '</mmwatch>'
        return Response(xml, mimetype='application/xml')
    return jsonify(name=user.user, rank=user.rank, edits=user.edits, joined=user.joined.isoformat())
开发者ID:Zverik,项目名称:mmwatch,代码行数:29,代码来源:mmwatch.py

示例5: get_userinfo

# 需要导入模块: from db import User [as 别名]
# 或者: from db.User import get [as 别名]
def get_userinfo(email):
    try:
        userinfo = User.get(User.email == email)
    except Exception:
        return False
    else:
        return userinfo
开发者ID:GregorioDiStefano,项目名称:URLShort,代码行数:9,代码来源:urlfinder.py

示例6: wrap

# 需要导入模块: from db import User [as 别名]
# 或者: from db.User import get [as 别名]
    def wrap(*args, **kwargs):
        try:
            user = User.get(User.api_key == request.form['k'])
            g.user = user
        except (KeyError, DoesNotExist):
            return jsonify(status='not authorized'), 403

        return f(*args, **kwargs)
开发者ID:nolanlum,项目名称:pshuu,代码行数:10,代码来源:api_native.py

示例7: update_password

# 需要导入模块: from db import User [as 别名]
# 或者: from db.User import get [as 别名]
def update_password(email, new_password):
    try:
        userinfo = User.get(User.email == email)
        userinfo.password = new_password
        userinfo.save()
    except Exception:
        return False
    else:
        return userinfo
开发者ID:GregorioDiStefano,项目名称:URLShort,代码行数:11,代码来源:urlfinder.py

示例8: post

# 需要导入模块: from db import User [as 别名]
# 或者: from db.User import get [as 别名]
def post(response):
    user = get_user(response)
    if user is None:
        return

    profile_id = response.get_field('profile_id')
    wall = User.get(id=profile_id)
    msg = response.get_field('msg')
    user.add_post(wall, msg)
    render_wall(response, wall.id)
开发者ID:kennib,项目名称:ncssbook,代码行数:12,代码来源:ncssbook.py

示例9: route_register_api

# 需要导入模块: from db import User [as 别名]
# 或者: from db.User import get [as 别名]
def route_register_api():
    if g.user:
        raise APIError("Already logged in!")

    params = {k:v for k, v in request.values.items() if k in ["username", "password", "email"]}

    if not all(params.values()):
        raise APIError("Missing required paramaters!")

    try:
        User.get((User.username == params["username"]) | (User.email == params["email"]))
        raise APIError("User with that username/email already exists!")
    except User.DoesNotExist: pass

    u = User(username=params["username"], email=params["email"])
    u.password = User.hash_password(params["password"])

    session["id"] = u.save()
    return APIResponse()
开发者ID:b1naryth1ef,项目名称:juicebox,代码行数:21,代码来源:app.py

示例10: get_user

# 需要导入模块: from db import User [as 别名]
# 或者: from db.User import get [as 别名]
def get_user(response):
    user_id = response.get_secure_cookie('user_id')
    user = None
    if user_id is None:
        response.redirect('/')
    else:
        try:
            user = User.get(id=int(user_id))
        except DoesNotExistError:
            response.redirect('/')
    return user
开发者ID:kennib,项目名称:ncssbook,代码行数:13,代码来源:ncssbook.py

示例11: route_register

# 需要导入模块: from db import User [as 别名]
# 或者: from db.User import get [as 别名]
def route_register():
    if g.user:
        return redirect("/", code=302)

    if request.method == "GET":
        return render_template("register.html")

    params = {k:v for k, v in request.values.items() if k in ["username", "password", "email"]}

    if not all(params.values()):
        return redirect("/", code=302)

    try:
        User.get((User.username == params["username"]) | (User.email == params["email"]))
        return redirect("/", code=302)
    except User.DoesNotExist: pass

    u = User(username=params["username"], email=params["email"])
    u.password = User.hash_password(params["password"])

    session["id"] = u.save()
    g.user = u
    return redirect("/", code=302)
开发者ID:b1naryth1ef,项目名称:juicebox,代码行数:25,代码来源:app.py

示例12: profile

# 需要导入模块: from db import User [as 别名]
# 或者: from db.User import get [as 别名]
def profile(response, profile_id=None):
    user = get_user(response)
    if user is None:
        return

    if profile_id is None:
        profile = user
    else:
        profile = User.get(id=profile_id)

    content = open('static/html_plates/profile.html', 'rU').read()
    content = content.replace('<% first_name %>', profile.first)
    content = content.replace('<% last_name %>', profile.last)
    content = content.replace('<% profile_id %>', str(profile.id))
    response.write(content)
开发者ID:kennib,项目名称:ncssbook,代码行数:17,代码来源:ncssbook.py

示例13: route_api_login

# 需要导入模块: from db import User [as 别名]
# 或者: from db.User import get [as 别名]
def route_api_login():
    user = request.values.get("user")
    pw = request.values.get("password")

    if not user or not pw:
        raise APIError("Invalid Paramaters")

    try:
        u = User.get(User.username == user)
    except User.DoesNotExist:
        raise APIError("Incorrect Username")

    if not u.check_password(pw):
        raise APIError("Incorrect Password")

    session["id"] = u.id
    return APIResponse()
开发者ID:b1naryth1ef,项目名称:juicebox,代码行数:19,代码来源:app.py

示例14: list_files

# 需要导入模块: from db import User [as 别名]
# 或者: from db.User import get [as 别名]
def list_files():
    putative_key = request.args.get('k') or request.form.get('k')
    try:
        user = User.get(User.api_key == putative_key)
    except DoesNotExist:
        user = None

    if user is None:
        return jsonify(status='not authorized'), 403
    else:
        return jsonify(
            status='pshuu~',
            files={
                f.id: {'original_filename': f.original_filename,
                       'upload_time': f.upload_time,
                       'url': url_for_file(f)
                       }
                for f in File.select().where(File.user == user)})
开发者ID:nolanlum,项目名称:pshuu,代码行数:20,代码来源:api_native.py

示例15: login

# 需要导入模块: from db import User [as 别名]
# 或者: from db.User import get [as 别名]
def login():
	if request.method == 'GET':
		return render_template('login.html')
	username = request.form.get('username')
	password = request.form.get('password')
	if not username:
		flash('Please input username')
            	return redirect(url_for('login'))
	elif not password:
		flash('Please input password')
            	return redirect(url_for('login'))
        try:
            user = User.get(
                username=username,
                password=md5(password).hexdigest()
            )
        except User.DoesNotExist:
		flash('The username or password is incorrect')
            	return redirect(url_for('login'))
        else:
		auth_user(user)
        	return redirect(url_for('homepage'))
开发者ID:justasabc,项目名称:python_tutorials,代码行数:24,代码来源:app.py


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