本文整理汇总了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
示例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
})
示例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)
示例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
示例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)
示例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)}
示例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)
示例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)}
示例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)}
示例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})
示例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)}
示例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'))
示例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)}
示例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
示例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})