本文整理汇总了Python中model.User.hash_password方法的典型用法代码示例。如果您正苦于以下问题:Python User.hash_password方法的具体用法?Python User.hash_password怎么用?Python User.hash_password使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类model.User
的用法示例。
在下文中一共展示了User.hash_password方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: load_users
# 需要导入模块: from model import User [as 别名]
# 或者: from model.User import hash_password [as 别名]
def load_users():
"""Load users from user.csv into database."""
# open file
user_csv = open("user.csv")
# Iterate through the lines
# This will put the data into a list
for line in user_csv:
line_list = line.strip().split("|")
# Another for loop to iterate through
for i in range(len(line_list)):
line_list[i] = line_list[i].strip()
user_id, email, password, street_address, zipcode, first_name, last_name, admin = line_list[0], line_list[1], \
line_list[2], line_list[3], \
line_list[4], line_list[5], \
line_list[6], line_list[7]
print "EMAIL: {}, PASSWORD: {}, STREET_ADDRESS: {}, ZIPCODE: {}, FIRST {}, LAST {}".format(email, password,
street_address,
zipcode, first_name,
last_name)
user = User(user_id=user_id, email=email, street_address=street_address, zipcode=zipcode, first_name=first_name,
last_name=last_name, admin=admin)
user.hash_password(password)
db.session.add(user)
db.session.commit()
示例2: new_user
# 需要导入模块: from model import User [as 别名]
# 或者: from model.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)}
示例3: new_user
# 需要导入模块: from model import User [as 别名]
# 或者: from model.User import hash_password [as 别名]
def new_user():
data = json.loads(request.data)
username = data.get('username')
password = data.get('password')
if username is None or password is None:
abort(400)
if User.query.filter_by(username=username).first() is not None:
abort(400)
user = User(username=username)
user.hash_password(password)
db.session.add(user)
db.session.commit()
return jsonify({'username': user.username}), 201
示例4: add_user
# 需要导入模块: from model import User [as 别名]
# 或者: from model.User import hash_password [as 别名]
def add_user():
""" Add user to db """
first_name = request.form["first_name"]
last_name = request.form["last_name"]
email = request.form["email"]
address = request.form["address"]
zipcode = request.form["zipcode"]
if 'admin' in request.form:
admin = True
else:
admin = False
password = request.form["password"]
new_user = User(first_name=first_name, last_name=last_name, email=email, street_address=address, zipcode=zipcode,
admin=admin)
new_user.hash_password(password)
db.session.add(new_user)
db.session.commit()
flash("User {} added".format(email), 'info')
return redirect("/users")
示例5: register_process
# 需要导入模块: from model import User [as 别名]
# 或者: from model.User import hash_password [as 别名]
def register_process():
"""Add user to database. login_submit"""
# inputs form the form checking the db to see if user is in DB already
# Add the admin
email = request.form['email']
password = request.form['password']
street_address = request.form['address']
zipcode = request.form['zipcode']
first_name = request.form['first_name']
last_name = request.form['last_name']
admin = False
# Check if this email address has already registered an account
user = User.query.filter_by(email=email).first()
print user
if user:
flash("Email already registered", "info")
return redirect("/register")
else:
# Otherwise, create the account in the db
print "Register-process: {}, {}, {}".format(email, street_address, zipcode)
new_user = User(email=email, street_address=street_address, zipcode=zipcode, first_name=first_name,
last_name=last_name, admin=admin)
new_user.hash_password(password)
db.session.add(new_user)
db.session.commit()
flash("You have created your account", "info")
session["user_id"] = new_user.user_id
session["email"] = new_user.email
session["street_address"] = street_address
session["zipcode"] = zipcode
session["first_name"] = first_name
session["last_name"] = last_name
session["admin"] = admin
audit_event(event="New user registered ({})".format(session['email']))
return redirect("/")
示例6: new_user
# 需要导入模块: from model import User [as 别名]
# 或者: from model.User import hash_password [as 别名]
def new_user():
if request.method == 'POST':
emailVar = request.args.get('email')
passwordVar = request.args.get('password')
if emailVar is None or passwordVar is None:
print "missing arguments"
abort(400)
if session.query(User).filter_by(email = emailVar).first() is not None:
print "existing user"
return jsonify({'message':'user already exists'}), 200
if session.query(User).filter_by(email = emailVar).first() is None:
lastID = session.query(func.max(User.id))
user = User((lastID + 1), emailVar, (user.hash_password(passwordVar)))
session.add(user)
session.commit()
user = session.query(User).filter_by(email = emailVar).first()
return jsonify(user), 201
示例7: process_users
# 需要导入模块: from model import User [as 别名]
# 或者: from model.User import hash_password [as 别名]
def process_users():
if request.method == 'GET':
users = session.query(User).all()
return jsonify(users = [u.serialize for u in users])
elif request.method == 'POST':
email = request.json['email']
password = request.json['password']
#issue uploading picture
#picture = request.json['picture']
if(email and password and len(email) > 3 and len(password) > 3):
if(session.query(User).filter_by(email = email).first()):
#username already exists, return error message
return jsonify({'error': 'the email provided already exists.'})
else:
newUser = User(email = email, password_hash = User.hash_password(password))
session.add(newUser)
session.commit()
return jsonify(newUser.serialize)
else:
return get_invalid_input_msg("email, password")