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


Python User.new方法代码示例

本文整理汇总了Python中database.User.new方法的典型用法代码示例。如果您正苦于以下问题:Python User.new方法的具体用法?Python User.new怎么用?Python User.new使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在database.User的用法示例。


在下文中一共展示了User.new方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: post

# 需要导入模块: from database import User [as 别名]
# 或者: from database.User import new [as 别名]
    def post(self):
        if self.get_argument("username", default=None) is None:
            # TODO Check whether username is exist
            username = "GUEST_" + hashlib.md5(str(time.time()) + str(random())).hexdigest()[0:8]
            password = hashlib.md5(str(time.time()) + str(random())).hexdigest()
            user = User.new(username=username, password=hashlib.md5(password).hexdigest())
            user.screen_name = username.replace("GUEST_", u"游客")[0:6]
        else:
            username = self.get_argument("username")
            password = hashlib.md5(self.get_argument("password")).hexdigest()
            user = User.verify_user(username, password)

        if user is None:
            message = {"status": "failed", "content": "invalid username or password"}
        else:
            message = {"status": "success", "username": user.username, "password": password}
            self.session["user_id"] = user.id
            if user.last_login == None:
                user.bonus_notification = 1
            else:
                last_login_date = datetime.fromtimestamp(user.last_login)
                if last_login_date.date() < datetime.today().date():
                    user.bonus_notification = 1

            user.last_login = int(time.time())

        self.set_header("Access-Control-Allow-Origin", "*")
        self.write(json.dumps(message))
开发者ID:stephica,项目名称:HTML5-Texas-Hold-em-,代码行数:30,代码来源:login_controller.py

示例2: get_user_info

# 需要导入模块: from database import User [as 别名]
# 或者: from database.User import new [as 别名]
    def get_user_info(self, code):
        client = APIClient(app_key=APP_KEY, app_secret=APP_SECRET, redirect_uri=CALLBACK_URL)
        r = client.request_access_token(code)
        access_token = r.access_token
        expires_in = r.expires_in
        print r.access_token, r.expires_in
        client.set_access_token(access_token, expires_in)
        uid = client.get.account__get_uid().uid
        print uid
        user = User.verify_user_openID(accountType=User.USER_TYPE_SINA_WEIBO, accountID=uid)
        if not user:
            user_info = client.get.users__show(uid=uid)
            user = User.new(
                username="%s_%s" % (User.USER_TYPE_SINA_WEIBO, uid),
                accountType=User.USER_TYPE_SINA_WEIBO,
                accountID=uid,
            )
            user.screen_name = user_info.screen_name
            user.gender = user_info.gender
            user.headPortrait_url = user_info.profile_image_url  # avatar_large?
            print user_info
            user.openIDinfo = user_info
        else:
            print "old user"

        if user.last_login == None:
            user.bonus_notification = 1
        else:
            last_login_date = datetime.fromtimestamp(user.last_login)
            if last_login_date.date() < datetime.today().date():
                user.bonus_notification = 1
        user.last_login = int(time.time())

        self.got_user_info(uid, user)
开发者ID:stephica,项目名称:HTML5-Texas-Hold-em-,代码行数:36,代码来源:login_controller.py

示例3: handle_user_info

# 需要导入模块: from database import User [as 别名]
# 或者: from database.User import new [as 别名]
 def handle_user_info(self, response):
     content    = json.loads(response.body)
     uid        = content["id"]
     user    = User.new(    username    = "%s_%s" % (User.USER_TYPE_FACEBOOK, uid),
                         accountType    = User.USER_TYPE_FACEBOOK,
                         accountID    = uid,
                         access_token= self.access_token)
     if content["gender"] == "male":
         user.gender = "M"
     elif content["gender"] == "female":
         user.gender    = "F"
     else:
         user.gender    = "N/A"
     user.screen_name        = content["name"]
     #user.headPortrait_url    = content["picture"]
     user.headPortrait_url   = facebook_profile_pic % uid
     self._update_facebook_feed(user);
     self._login_user(user)
开发者ID:hackur,项目名称:HTML5-Texas-Hold-em-,代码行数:20,代码来源:facebook_controller.py


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