本文整理汇总了Python中models.users.User.save方法的典型用法代码示例。如果您正苦于以下问题:Python User.save方法的具体用法?Python User.save怎么用?Python User.save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.users.User
的用法示例。
在下文中一共展示了User.save方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get
# 需要导入模块: from models.users import User [as 别名]
# 或者: from models.users.User import save [as 别名]
def get(self):
api = QQAPIClient(config.get('qq_apiid'),
config.get('qq_appkey'),
redirect_uri=config.get('qq_callback_url'))
code = self.request.query_arguments.get('code')[0]
print code
access_token = api.request_access_token(code)
api.set_access_token(access_token['access_token'],
access_token['expires_in'])
user_info = api.get.user__get_user_info()
openid = api.get_openid()
now = datetime.utcnow()
user = User.objects.filter(third_info__third_type='qq',
third_info__openid=openid).first()
if not user:
user = User(create_on=now, modify_on=now, last_login=now)
else:
user.modify_on = now
user.last_login = now
user.username = openid
user.nick_name = user_info.get('nickname', '')
user.email = '%[email protected]' % openid
gender = 'm' if user_info.get('gender') == u'男' else 'f'
user.gender = gender
user.avatar = user_info.get('figureurl_qq_2', '')
user.third_info = {'third_type': 'qq', 'info': dict(user_info), 'openid': openid}
user.save()
# set user cookie
self.set_secure_cookie(config.get('uname'), openid)
self.write(json.dumps(make_success_response(user_info)))
示例2: signup
# 需要导入模块: from models.users import User [as 别名]
# 或者: from models.users.User import save [as 别名]
def signup():
form = SignupForm(flask.request.form)
if flask.request.method == "POST" and form.validate():
user = User(**form.data)
user.passwd(form.data['password'])
user.generate_new_inventory()
user.save()
flask.session['login'] = user.name
flask.flash("Signup successful!")
print flask.url_for('.single_user', name=user.name)
return flask.redirect(flask.url_for('.single_user', name=user.name))
return flask.render_template("signup.html", form=form)
示例3: post
# 需要导入模块: from models.users import User [as 别名]
# 或者: from models.users.User import save [as 别名]
def post(self):
"""Checks if user already exists, otherwise creates a new User in db"""
args = post_parser.parse_args()
user = User(args.email, args.password)
# Check if already registered
user_already_exists = User.query.filter(User.email == args.email).first()
if user_already_exists:
return {'success': False, 'message': 'That user already exists', 'data': None}
# Try saving the user to db
try:
user.save()
return {'success': True, 'message': 'User successfully added', 'data': None}
except ValueError as e:
return {'success': False, 'message': str(e), 'data': None}
示例4: get
# 需要导入模块: from models.users import User [as 别名]
# 或者: from models.users.User import save [as 别名]
def get(self):
if self.get_argument("openid.mode", None):
result = yield self.get_authenticated_user()
try:
user = User.objects(type='google', email=result['email'])[0]
except Exception as ex:
app_log.error(ex)
user = User(uid=str(uuid4()),
type='google',
email=result['email'],
name=result['name'],
avatar=getAvatar('email')
)
user.save()
self.set_secure_cookie('userid', str(user.id))
self.set_secure_cookie('type', 'google')
self.redirect("/")
else:
yield self.authenticate_redirect()
示例5: authenticate
# 需要导入模块: from models.users import User [as 别名]
# 或者: from models.users.User import save [as 别名]
def authenticate():
from models.users import User
email = None
password = None
if request.json:
email = request.json.get("email")
password = request.json.get("password")
if not (email and password):
token = "tok-%s" % uuid.uuid4().hex
user = User(**{})
user.save()
user.set_token(token)
else:
user = User.q.filter_by(email=email).first()
if not user:
return Response(status=403)
check = user.check_password(password)
if not check:
return Response(status=403)
token = user.token
return Response(json_encode({"token": token,
"email": email}))
示例6: create_user
# 需要导入模块: from models.users import User [as 别名]
# 或者: from models.users.User import save [as 别名]
def create_user(email):
user = User(email=email)
user.save()
return user