本文整理汇总了Python中model.user.User.objects方法的典型用法代码示例。如果您正苦于以下问题:Python User.objects方法的具体用法?Python User.objects怎么用?Python User.objects使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类model.user.User
的用法示例。
在下文中一共展示了User.objects方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: post
# 需要导入模块: from model.user import User [as 别名]
# 或者: from model.user.User import objects [as 别名]
def post(self):
args = fbUserParser.parse_args()
fb_id = args['fbid']
fb_token = args['fbtoken']
if fb_id is None or fb_token is None:
abort(400)
fbuser_info = requests.get('https://graph.facebook.com/me?access_token=%s' %fb_token).json()
if not fbuser_info.get('id') or fb_id != fbuser_info['id']:
raise InvalidUsage('User info does not match',406)
fb_email = args['fbemail']
user = User.objects(email=fb_email).first()
if user is None:
user = User(email=fb_email, fb_id=fbuser_info['id'])
user.save()
profile = Profile.objects(user=user).first()
if profile is None:
profile = Profile(user=user)
profile.save()
rongToken = rongcloudToken(profile.id)
token = user.generate_auth_token()
redis_store.set(str(user.id), token)
return {'token': token, 'rongToken' : rongToken}
示例2: post
# 需要导入模块: from model.user import User [as 别名]
# 或者: from model.user.User import objects [as 别名]
def post(self):
"""
Login in with a Facebook account if the user has existed
Otherwises, create a new user with information from Facebook
"""
args = fbUserParser.parse_args()
fb_id = args['fbid']
fb_token = args['fbtoken']
if fb_id is None or fb_token is None:
abort(400)
# verify the user's facebook account using the facebook token
fbuser_info = requests.get(
'https://graph.facebook.com/me?access_token=%s' % fb_token).json()
if not fbuser_info.get('id') or fb_id != fbuser_info['id']:
abort(406)
fb_email = args['fbemail']
user = User.objects(email=fb_email).first()
if user is None:
user = User(email=fb_email, fb_id=fbuser_info['id'])
user.save()
token = user.generate_auth_token(expiration=360000)
redis_store.set(str(user.id), token)
return {'token': token}
示例3: post
# 需要导入模块: from model.user import User [as 别名]
# 或者: from model.user.User import objects [as 别名]
def post(self):
"""
Verify the information from user
Send a reset password email if the information is correct
"""
args = forgetPasswordParser.parse_args()
email = args['email']
username = args['username']
school = args['school']
if email is None or username is None or school is None:
abort(400)
user = User.objects(email=email).first()
if user is None:
return {'status': 'error', 'message':
'There is no user associated with the email'}
profile = Profile.objects(user=user).first()
if not profile.checkInfo(username, school):
return {'status': 'error', 'message':
'The information does not match the record'}
token = user.generate_auth_token(expiration=360000)
send_forget_password_email(email, token)
return {'status': 'success', 'message':
'An email has been sent to you letting you reset password'}
示例4: login
# 需要导入模块: from model.user import User [as 别名]
# 或者: from model.user.User import objects [as 别名]
def login(user_info):
result = User.objects(email = user_info['email'], password = user_info['password'])
if len(result) > 0:
login_user(result[0])
return True
else:
return False
示例5: get
# 需要导入模块: from model.user import User [as 别名]
# 或者: from model.user.User import objects [as 别名]
def get(self, user_id):
"""
Renew the authorisation token by providing old token
"""
user = User.objects(id=user_id).first()
token = user.generate_auth_token(expiration=360000)
redis_store.set(user_id, token)
return {'token': token}
示例6: monitoring
# 需要导入模块: from model.user import User [as 别名]
# 或者: from model.user.User import objects [as 别名]
def monitoring():
if not g.user.editor:
redirect('/')
users = User.objects(editor=False)
exercises = Exercise.objects()
progress = {user: {p.exercise: p for p in ExerciseProgress.objects(user=user)} for user in users}
breadcrumbs = [('Home', '/'), ('Monitoring', None)]
return render_template('monitoring.html', users=users, exercises=exercises, progress=progress, breadcrumbs=breadcrumbs)
示例7: post
# 需要导入模块: from model.user import User [as 别名]
# 或者: from model.user.User import objects [as 别名]
def post(self):
username = request.form.get('username')
password = request.form.get('password')
if username is None or password is None:
abort(400)
user = User.objects(username=username)[0]
if not user or not user.verify_password(password):
abort(400)
token = user.generate_auth_token(expiration=360000)
redis_store.set(username, token)
return {'token': token}
示例8: process_login
# 需要导入模块: from model.user import User [as 别名]
# 或者: from model.user.User import objects [as 别名]
def process_login():
email, password = request.form['email'].lower(), request.form['password']
user = User.objects(email=email).first()
if user is None or not user.valid_password(password):
app.logger.warning("Couldn't login : {}".format(user))
return render_template('login.html', error="Wrong password or username.", email=email)
else:
session['logged_in'] = user.email
inject_user()
load_user()
return redirect('/')
示例9: send_digest
# 需要导入模块: from model.user import User [as 别名]
# 或者: from model.user.User import objects [as 别名]
def send_digest():
users = User.objects()
contests = OperationData.getContests(1)
body = """
We had %d contests yesterday! Come and see what's new contests on contestify!
""" % contests
count = 0
for user in users:
send_email(user.email, "Come and Read the latest Info!", body)
print 'sent email to %s with body %s' % (user.email, body)
count = count + 1
if count > 0:
break
示例10: get
# 需要导入模块: from model.user import User [as 别名]
# 或者: from model.user.User import objects [as 别名]
def get(self):
args = activateAccountParser.parse_args()
token = args['token']
if token is None:
abort()
user_id = load_token(token)
user = User.objects(id=user_id).first()
if user is None:
abort(400)
user.is_activated = True
user.save()
return "Your account has been activated!"
示例11: post
# 需要导入模块: from model.user import User [as 别名]
# 或者: from model.user.User import objects [as 别名]
def post(self, user_id):
args = passwordParser.parse_args()
old_password = args['old_password']
new_password = args['new_password']
if old_password is None or new_password is None:
abort(400)
user = User.objects(id=user_id).first()
if not user.verify_password(old_password):
raise InvalidUsage('Password incorrect',401)
user.hash_password(new_password)
user.save()
return {'status': 'success'}
示例12: get
# 需要导入模块: from model.user import User [as 别名]
# 或者: from model.user.User import objects [as 别名]
def get(self):
args = forgetPasswordParser.parse_args()
token = args['token']
if token is None:
abort(400)
user_id = load_token(token)
user = User.objects(id=user_id).first()
if user is None:
raise InvalidUsage('User not found',404)
temp_password = (''.join(str(random.randint(0, 9)) for x in range(8)))
user.hash_password(temp_password)
user.save()
return "Your temperate password is: %s" %temp_password
示例13: post
# 需要导入模块: from model.user import User [as 别名]
# 或者: from model.user.User import objects [as 别名]
def post(self):
args = userParser.parse_args()
email = args['email']
password = args['password']
if email is None or password is None:
abort(400)
user = User.objects(email=email).first()
if not user or not user.verify_password(password):
return {'status': 'error', 'message':
'The email does not exist or password is wrong'}
if not user.is_activated:
return {'status': 'error', 'message':
'The account has not been activated'}
token = user.generate_auth_token(expiration=360000)
redis_store.set(str(user.id), token)
return {'token': token}
示例14: get
# 需要导入模块: from model.user import User [as 别名]
# 或者: from model.user.User import objects [as 别名]
def get(self):
"""
Reset user's password and return the temporary password
"""
args = forgetPasswordParser.parse_args()
token = args['token']
if token is None:
abort(400)
user_id = load_token(token)
user = User.objects(id=user_id).first()
if user is None:
return {'status': 'error', 'token': 'Token is not valid'}
# generate a random temporary password
temp_password = (''.join(str(random.randint(0, 9)) for x in range(8)))
user.hash_password(temp_password)
user.save()
return "Your temperate password is: %s" % temp_password
示例15: get
# 需要导入模块: from model.user import User [as 别名]
# 或者: from model.user.User import objects [as 别名]
def get(self, user_id):
user = User.objects(id=user_id).first()
token = user.generate_auth_token(expiration=360000)
redis_store.set(user_id, token)
return {'token': token}