當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。