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


Python UserData.get_from_db_key_email方法代码示例

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


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

示例1: get_user_data

# 需要导入模块: from models import UserData [as 别名]
# 或者: from models.UserData import get_from_db_key_email [as 别名]
    def get_user_data(self):
        from models import UserData

        user_id = None
        email = None

        if self.uses_google():
            user_id, email = get_google_user_id_and_email_from_oauth_map(self)
        elif self.uses_facebook():
            user_id = get_facebook_user_id_from_oauth_map(self)
            email = user_id

        user_data = UserData.get_from_user_id(user_id) or \
                    UserData.get_from_db_key_email(email) or \
                    UserData.insert_for(user_id, email)

        return user_data
开发者ID:KhanWorld,项目名称:KhanAcademy,代码行数:19,代码来源:auth_models.py

示例2: award_author_badges

# 需要导入模块: from models import UserData [as 别名]
# 或者: from models.UserData import get_from_db_key_email [as 别名]
    def award_author_badges(self, entity):

        user_data_author = UserData.get_from_db_key_email(entity.author.email())

        if not user_data_author:
            return

        possible_badges = badges_with_context_type(BadgeContextType.FEEDBACK)

        awarded = False
        for badge in possible_badges:
            if not badge.is_already_owned_by(user_data=user_data_author, feedback=entity):
                if badge.is_satisfied_by(user_data=user_data_author, feedback=entity):
                    badge.award_to(user_data=user_data_author, feedback=entity)
                    awarded = True

        if awarded:
            user_data_author.put()
开发者ID:johnfelipe,项目名称:server,代码行数:20,代码来源:voting.py

示例3: get

# 需要导入模块: from models import UserData [as 别名]
# 或者: from models.UserData import get_from_db_key_email [as 别名]
    def get(self):
        cont = self.request_continue_url()

        self._consume_auth_token()

        user_data = UserData.current(create_if_none=True)
        if not user_data:
            # Nobody is logged in - clear any expired Facebook cookies
            # that may be hanging around.
            facebook_util.delete_fb_cookies(self)

            logging.critical(("Missing UserData during PostLogin, " +
                              "with id: %s, cookies: (%s), google user: %s") %
                             (util.get_current_user_id_unsafe(),
                              os.environ.get('HTTP_COOKIE', ''),
                              users.get_current_user()))
            self._finish_and_redirect(cont)
            return

        first_time = not user_data.last_login

        if not user_data.has_sendable_email():

            if not user_data.is_facebook_user:
                # TODO(benkomalo): seems like there are some phantoms hitting
                # this code path at least - are there any others?
                logging.error(
                    "Non-FB users should have a valid email. User: [%s]" %
                    user_data)

            # Facebook can give us the user's e-mail if the user granted
            # us permission to see it - try to update existing users with
            # emails, if we don't already have one for them.
            fb_email = facebook_util.get_fb_email_from_cookies()
            if fb_email:
                # We have to be careful - we haven't always asked for emails
                # from facebook users, so getting an e-mail after the fact
                # may result in a collision with an existing Google or Khan
                # account. In those cases, we silently drop the e-mail.
                existing_user = \
                    user_models.UserData.get_from_user_input_email(fb_email)

                if (existing_user and
                        existing_user.user_id != user_data.user_id):
                    logging.warning("FB user gave us e-mail and it "
                                    "corresponds to an existing account. "
                                    "Ignoring e-mail value.")
                else:
                    user_data.user_email = fb_email

        # If the user has a public profile, we stop "syncing" their username
        # from Facebook, as they now have an opportunity to set it themself
        if not user_data.username:
            user_data.update_nickname()

        # Set developer and moderator to True if user is admin
        if ((not user_data.developer or not user_data.moderator) and
                users.is_current_user_admin()):
            user_data.developer = True
            user_data.moderator = True

        user_data.last_login = datetime.datetime.utcnow()
        user_data.put()

        complete_signup = self.request_bool("completesignup", default=False)
        if first_time:
            email_now_verified = None
            if user_data.has_sendable_email():
                email_now_verified = user_data.email

                # Look for a matching UnverifiedUser with the same e-mail
                # to see if the user used Google login to verify.
                unverified_user = user_models.UnverifiedUser.get_for_value(
                        email_now_verified)
                if unverified_user:
                    unverified_user.delete()

            # Note that we can only migrate phantom users right now if this
            # login is not going to lead to a "/completesignup" page, which
            # indicates the user has to finish more information in the
            # signup phase.
            if not complete_signup:
                # If user is brand new and has 0 points, migrate data.
                phantom_id = get_phantom_user_id_from_cookies()
                if phantom_id:
                    phantom_data = UserData.get_from_db_key_email(phantom_id)
                    if _upgrade_phantom_into(phantom_data, user_data):
                        cont = "/newaccount?continue=%s" % cont
        if complete_signup:
            cont = "/completesignup"

        self._finish_and_redirect(cont)
开发者ID:PaulWagener,项目名称:khan-website,代码行数:94,代码来源:login.py

示例4: retrieve_identity

# 需要导入模块: from models import UserData [as 别名]
# 或者: from models.UserData import get_from_db_key_email [as 别名]
def retrieve_identity(query):
    from models import UserData
    user_data = UserData.get_from_db_key_email(query)
    return user_data.gae_bingo_identity if user_data else None
开发者ID:KhanWorld,项目名称:KhanAcademy,代码行数:6,代码来源:config.py

示例5: get

# 需要导入模块: from models import UserData [as 别名]
# 或者: from models.UserData import get_from_db_key_email [as 别名]
    def get(self):
        cont = self.request_string('continue', default = "/")

        # Immediately after login we make sure this user has a UserData entity
        user_data = UserData.current()
        if user_data:

            # Update email address if it has changed
            current_google_user = users.get_current_user()
            if current_google_user and current_google_user.email() != user_data.email:
                user_data.user_email = current_google_user.email()
                user_data.put()

            # Update nickname if it has changed
            current_nickname = get_nickname_for(user_data)
            if user_data.user_nickname != current_nickname:
                user_data.user_nickname = current_nickname
                user_data.put()

            # Set developer and moderator to True if user is admin
            if (not user_data.developer or not user_data.moderator) and users.is_current_user_admin():
                user_data.developer = True
                user_data.moderator = True
                user_data.put()

            # If user is brand new and has 0 points, migrate data
            phantom_id = get_phantom_user_id_from_cookies()
            if phantom_id:
                phantom_data = UserData.get_from_db_key_email(phantom_id)

                # First make sure user has 0 points and phantom user has some activity
                if user_data.points == 0 and phantom_data and phantom_data.points > 0:

                    # Make sure user has no students
                    if not user_data.has_students():

                        # Clear all "login" notifications
                        UserNotifier.clear_all(phantom_data)

                        # Update phantom user_data to real user_data
                        phantom_data.user_id = user_data.user_id
                        phantom_data.current_user = user_data.current_user
                        phantom_data.user_email = user_data.user_email
                        phantom_data.user_nickname = user_data.user_nickname

                        if phantom_data.put():
                            # Phantom user was just transitioned to real user
                            user_counter.add(1)
                            user_data.delete()

                        cont = "/newaccount?continue=%s" % cont
        else:

            # If nobody is logged in, clear any expired Facebook cookie that may be hanging around.
            self.delete_cookie("fbsr_" + App.facebook_app_id)
            self.delete_cookie("fbs_" + App.facebook_app_id)

            logging.critical("Missing UserData during PostLogin, with id: %s, cookies: (%s), google user: %s" % (
                    util.get_current_user_id(), os.environ.get('HTTP_COOKIE', ''), users.get_current_user()
                )
            )

        # Always delete phantom user cookies on login
        self.delete_cookie('ureg_id')

        self.redirect(cont)
开发者ID:KhanWorld,项目名称:KhanAcademy,代码行数:68,代码来源:main.py


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