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


Python User.hash_password方法代码示例

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


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

示例1: new_user

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import hash_password [as 别名]
def new_user():
    if request.method == "POST":
        # Getting all parameters for new user
        username = request.args.get("username")
        password = request.args.get("password")
        email = request.args.get("email")
        # balance is 0 by default
        balance = 0

        # If some data is invalid
        if username is None or password is None or email is None:
            # Abort
            abort(400)
        # If user already exists
        if session.query(User).filter_by(username=username).first() is not None:
            # Abort
            abort(400)
        # Create user
        user = User(username=username, email=email, balance=balance)
        # Hash password
        user.hash_password(password)
        # Add entry to DB
        session.add(user)
        # Save changes
        session.commit()
        # return result
        return jsonify({"username": username}), 201
开发者ID:egorikem,项目名称:Flask-1,代码行数:29,代码来源:users.py

示例2: create

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import hash_password [as 别名]
def create():
    existing = User.query.filter(User.facebook_id == request.form["facebook_id"]).first()
    if existing is not None:
        existing.gcm = request.form["gcm"]
        db.session.commit()
        return jsonify({
            "creation": "success",
            "token": existing.token
        })

    user = User()
    user.name = request.form["name"]
    user.token_id = request.form["token_id"]
    user.facebook_id = request.form["facebook_id"]
    user.gcm = request.form["gcm"]

    user.hash_password(request.form["facebook_id"])

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

    return jsonify({
        "creation": "success",
        "token": user.token
    })
开发者ID:thecumets,项目名称:cumets-backend,代码行数:27,代码来源:users.py

示例3: post

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import hash_password [as 别名]
    def post(self):
        '''Register a new user.'''
        args = api.general_parse()
        username = args['username']

        # TODO: case insensitive? ver isso na hora de login tb
        # username = username.lower()
        if len(username) < 5 or len(username) > 20:
            api.abort_with_msg(
                400,
                'Invalid username size. Must be between 5 and 20 characters.',
                ['username'])
        if not re.match(r'[A-Za-z0-9]{5,}', username):
            api.abort_with_msg(400, 'Invalid characters in username...',
                               ['username'])

        password = args['password']
        validate_password(password)

        email = args.get('email')
        validate_email(email)

        user = User(username=username, email=email)
        user.hash_password(password)
        db.session.add(user)
        try:
            db.session.commit()
        except IntegrityError:
            api.abort_with_msg(
                400,
                'Error to create user.'
                ' Maybe username is already registered...',
                ['username'])
        return create_tokens(username)
开发者ID:okfn-brasil,项目名称:viralata,代码行数:36,代码来源:views.py

示例4: register

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import hash_password [as 别名]
def register():
    if 'email' not in request.form:
        return jsonify(errors=['Email is required']), 401

    if 'password' not in request.form:
        return jsonify(errors=['Password is required']), 401

    token = User.generate_auth_token(request.form['email'], request.form['password'])
    if token:
        return jsonify(token=token), 200

    user = User.objects(email=request.form['email'])
    if user:
        return jsonify(errors=['Email already taken']), 401

    if not is_email_address_valid(request.form['email']):
        return jsonify(errors=['Invalid email address']), 401

    if not is_password_valid(request.form['password']):
        return jsonify(errors=['Password too short']), 401

    user = User(email=request.form['email'])
    user.hash_password(request.form['password'])
    if user.save():
        token = User.generate_auth_token(request.form['email'], request.form['password'])
        return jsonify(token=token), 200

    return jsonify(errors=['Undefined error']), 401
开发者ID:mebusila,项目名称:bookmarks.rocks,代码行数:30,代码来源:api.py

示例5: add_user

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import hash_password [as 别名]
def add_user():
    form = AddUserForm(request.form)
    if form.validate():
        result = {}
        result['iserror'] = False
        if not form.id.data:
            if True:
                newuser = User(email=form.email.data)
                newuser.hash_password(form.password.data)
                db.session.add(newuser)
                db.session.commit()
                result['savedsuccess'] = True
            else:
                result['savedsuccess'] = False
            return json.dumps(result)
        else:
            edituser = User.query.get(form.id.data)
            edituser.email = form.email.data
            edituser.hash_password(form.password.data)
            db.session.commit()
            result['savedsuccess'] = True
            return json.dumps(result)
    else:
        form.errors['iserror'] = True
        print form.errors
        return json.dumps(form.errors)
开发者ID:pieceofchalk,项目名称:saulify-web,代码行数:28,代码来源:views.py

示例6: post

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import hash_password [as 别名]
 def post(self):
     args = self.reqparse.parse_args()
     username = args['username']
     password = args['password']
     user = User(username=username)
     user.hash_password(password)
     db.session.add(user)
     db.session.commit()
     return { 'username': user.username }, 201, { 'Location': url_for('get_user', id=user.id, _external=True)}
开发者ID:marcom04,项目名称:whose-is-this-box-flask,代码行数:11,代码来源:resources.py

示例7: register

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import hash_password [as 别名]
def register():
	form = RegistrationForm()
	if form.validate_on_submit():
		user = User(email=form.email.data,
					username=form.username.data)
		user.hash_password(form.password.data)
		db.session.add(user)
		db.session.commit()
		flash('You can now login.')
		return redirect('/login')
	return render_template('register.html', title="Register", form=form)
开发者ID:gladnashah,项目名称:bc-7-suggestion-box,代码行数:13,代码来源:views.py

示例8: new_user

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import hash_password [as 别名]
def new_user():
    username = request.json['username']
    password = request.json['password']
    if username is None or password is None:
        abort(400) # missing arguments
    if session.query(User).filter_by(username = username).first() is not None:
        abort(400) # existing user
    user = User(username = username)
    user.hash_password(password)
    session.add(user)
    session.commit()
    return jsonify({ 'username': user.username }), 201, {'Location': url_for('get_user', id = user.id, _external = True)}
开发者ID:nick-singh,项目名称:utt-resources,代码行数:14,代码来源:views.py

示例9: new_user

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import hash_password [as 别名]
def new_user():
    username = request.json.get("username")
    password = request.json.get("password")
    if username is None or password is None:
        abort(400)  # missing arguments
    if User.query.filter_by(username=username).first() is not None:
        abort(400)  # existing user
    user = User(username=username)
    user.hash_password(password)
    db_session.add(user)
    db_session.commit()
    return jsonify({"username": user.username}), 201, {"Location": url_for("get_user", id=user.id, _external=True)}
开发者ID:tranfong1991,项目名称:aro,代码行数:14,代码来源:aroserver.py

示例10: new_user

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import hash_password [as 别名]
def new_user():
    username = request.json.get('username')
    password = request.json.get('password')
    if username is None or password is None:
        abort(400)  # missing arguments
    if User.query.filter_by(username=username).first() is not None:
        abort(400)  # existing user
    user = User(username=username, password=password)
    user.hash_password(password)
    db.session.add(user)
    db.session.commit()
    return jsonify({'username': user.username})
开发者ID:ckduy,项目名称:ngx_ip_blacklist_admin,代码行数:14,代码来源:controllers.py

示例11: new_user

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import hash_password [as 别名]
def new_user():
    name = request.json.get('username')
    password = request.json.get('password')
    if name is None or password is None:
        abort(400) # missing arguments
    if User.query.filter_by(name = name).first() is not None:
        abort(400) # existing user
    user = User(name = name)
    user.hash_password(password)
    db.session.add(user)
    db.session.commit()
    return jsonify({ 'username': user.name }), 201, {'Location': url_for('get_user', id = user.id, _external = True)}
开发者ID:avalikarvamus,项目名称:pinguinvoice,代码行数:14,代码来源:views.py

示例12: signup

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import hash_password [as 别名]
def signup():
    username =  request.form['username']
    password =  request.form['password']
    email = request.form['email']
    if username is None or password is None or email is None:
        abort(400) #missing arguments
    if User.query.filter_by(username = username).first() is not None:
        abort(400) #existing user
    user = User(username = username, email = email)
    user.hash_password(password)
    db.session.add(user)
    db.session.commit()
    return redirect(url_for('home'))
开发者ID:sebastianiag,项目名称:Webdev,代码行数:15,代码来源:views.py

示例13: new_user

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import hash_password [as 别名]
def new_user():
    username = request.json.get('username')
    password = request.json.get('password')
    if username is None or password is None:
        abort(400) # missing arguments
    if session.query(User).filter_by(username = username).first() is not None:
        abort(400) # existing user
    user = User(username = username)
    user.hash_password(password)
    session.add(user)
    session.commit()
    app.logger.info("New user has been successfuly added")
    return jsonify({ 'username': user.username }), 201, {'Location': url_for('get_user', id = user.id, _external = True)}
开发者ID:krapivchenkon,项目名称:udacity-rest-api,代码行数:15,代码来源:views.py

示例14: post

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import hash_password [as 别名]
 def post(self):
     username = request.json.get("username")
     password = request.json.get("password")
     if username is None or password is None:
         abort(400) # missing arguments
     if User.query.filter_by(username = username).first() is not None:
         abort(400) # existing user
     user = User(username = username)
     user.hash_password(password)
     db.session.add(user)
     db.session.commit()
     res = make_response(jsonify({"username": user.username }), 201)
     res.headers["Location"] = api.url_for(self, id = user.id, _external = True)
     return res
开发者ID:lukasz-madon,项目名称:crud,代码行数:16,代码来源:api.py

示例15: post

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import hash_password [as 别名]
 def post(self):
     args = self.reqparse.parse_args()
     email = args.get('email')
     password = args.get('password')
     if UserModel.get(email) is not None:
         abort(400, 'User with given mail exists')
     user = UserModel(email = email)
     user.hash_password(password)
     try:
         user.save()
     except ValidationError as err:
         logging.info(err.errors)
         abort(400, str(err.errors))
     return jsonify({'email': user.email})
开发者ID:MichalJagiello,项目名称:android_todo_backend,代码行数:16,代码来源:views.py


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