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


Python User.save方法代码示例

本文整理汇总了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)))
开发者ID:seraphln,项目名称:chat2all,代码行数:35,代码来源:LoginHandler.py

示例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)
开发者ID:nightpool,项目名称:rox,代码行数:15,代码来源:users.py

示例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}
开发者ID:alexandercrosson,项目名称:braise,代码行数:18,代码来源:users.py

示例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()
开发者ID:yunlzheng,项目名称:PDFLabs,代码行数:24,代码来源:auth.py

示例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}))
开发者ID:vargi,项目名称:reko,代码行数:24,代码来源:app.py

示例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
开发者ID:thebrianzeng,项目名称:when2interview,代码行数:6,代码来源:__init__.py


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