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


Python UserData.get_from_user_input_email方法代码示例

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


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

示例1: post

# 需要导入模块: from models import UserData [as 别名]
# 或者: from models.UserData import get_from_user_input_email [as 别名]
    def post(self):
        custom_badge_name = self.request_string("name", default="")
        custom_badges = CustomBadge.all()
        custom_badge_awarded = None
        emails_awarded = []
        
        for custom_badge in custom_badges:
            if custom_badge.name == custom_badge_name:
                custom_badge_awarded = custom_badge

        if custom_badge_awarded:
            # Award badges and show successful email addresses
            emails_newlines = self.request_string("emails", default="")
            emails = emails_newlines.split()
            emails = map(lambda email: email.strip(), emails)

            for email in emails:
                user_data = UserData.get_from_user_input_email(email)
                if user_data:
                    if not custom_badge_awarded.is_already_owned_by(user_data):
                        custom_badge_awarded.award_to(user_data)
                        user_data.put()
                        emails_awarded.append(email)
        
        template_values = {
                "custom_badges": CustomBadge.all(),
                "custom_badge_awarded": custom_badge_awarded, 
                "emails_awarded": emails_awarded
                }

        self.render_jinja2_template("badges/award_custom_badge.html", template_values)
开发者ID:di445,项目名称:server,代码行数:33,代码来源:custom_badges.py

示例2: get

# 需要导入模块: from models import UserData [as 别名]
# 或者: from models.UserData import get_from_user_input_email [as 别名]
    def get(self):
        current_email = self.request.get('curremail') #email that is currently used 
        new_email = self.request.get('newemail') #email the user wants to change to
        swap = self.request.get('swap') #Are we changing emails?
        

        currdata = UserData.get_from_user_input_email(current_email)
        newdata = UserData.get_from_user_input_email(new_email)
        
        if swap and currdata: #are we swapping? make sure account exists
            currdata.current_user = users.User(new_email)
            currdata.user_email = new_email
            if newdata: #delete old account 
                currdata.user_id = newdata.user_id
                newdata.delete()
            currdata.put()

        template_values = {'App' : App, 'curremail': current_email, 'newemail':  new_email, 'currdata': currdata, 'newdata': newdata, "properties": UserData.properties()}

        self.render_jinja2_template('devemailpanel.html', template_values)
开发者ID:avh4,项目名称:khan-academy,代码行数:22,代码来源:devpanel.py

示例3: post

# 需要导入模块: from models import UserData [as 别名]
# 或者: from models.UserData import get_from_user_input_email [as 别名]
    def post(self):
        """Handle registration request on our site.

        Note that new users can still be created via PostLogin if the user
        signs in via Google/FB for the first time - this is for the
        explicit registration via our own services.
        """

        values = {
            'birthdate': self.request_string('birthdate', default=None),
            'email': self.request_string('email', default=None),
        }

        errors = {}

        # Under-13 check (note the JavaScript on our form should never really
        # send an invalid date, but just to make sure...)
        birthdate = None
        if values['birthdate']:
            try:
                birthdate = datetime.datetime.strptime(values['birthdate'],
                                                       '%Y-%m-%d')
                birthdate = birthdate.date()
            except ValueError:
                errors['birthdate'] = "Invalid birthdate"
        else:
            errors['birthdate'] = "Birthdate required"

        if birthdate and age_util.get_age(birthdate) < 13:
            # We don't yet allow under13 users. We need to lock them out now,
            # unfortunately. Set an under-13 cookie so they can't try again.
            Logout.delete_all_identifying_cookies(self)
            auth.cookies.set_under13_cookie(self)

            self.render_json({"under13": True})
            return

        existing_google_user_detected = False
        resend_detected = False

        if values['email']:
            email = values['email']

            # Perform loose validation - we can't actually know if this is
            # valid until we send an e-mail.
            if not _email_re.search(email):
                errors['email'] = "That email appears to be invalid."
            else:
                existing = UserData.get_from_user_input_email(email)
                if existing is not None:
                    if existing.has_password():
                        # TODO(benkomalo): do something nicer and maybe ask the
                        # user to try and login with that e-mail?
                        errors['email'] = "Oops. There's already an account with that e-mail."
                    else:
                        existing_google_user_detected = True
                        logging.warn("User tried to register with password, "
                                     "but has an account w/ Google login")
                else:
                    # No full user account detected, but have they tried to
                    # signup before and still haven't verified their e-mail?
                    existing = user_models.UnverifiedUser.get_for_value(email)
                    resend_detected = existing is not None
        else:
            errors['email'] = "Please enter your email."

        if existing_google_user_detected:
            # TODO(benkomalo): just deny signing up with username/password for
            # existing users with a Google login. In the future, we can show
            # a message to ask them to sign in with their Google login
            errors['email'] = (
                    "There is already an account with that e-mail. " +
                    "If it's yours, sign in with Google below.")

        if len(errors) > 0:
            self.render_json({'errors': errors})
            return

        # Success!
        unverified_user = user_models.UnverifiedUser.get_or_insert_for_value(
                email,
                birthdate)
        Signup.send_verification_email(unverified_user)

        response_json = {
                'success': True,
                'email': email,
                'resend_detected': resend_detected,
                }

        if App.is_dev_server:
            # Send down the verification token so the client can easily
            # create a link to test with.
            response_json['token'] = unverified_user.randstring

        # TODO(benkomalo): since users are now blocked from further access
        #    due to requiring verification of e-mail, we need to do something
        #    about migrating phantom data (we can store the phantom id in
        #    the UnverifiedUser object and migrate after they finish
        #    registering, for example)
#.........这里部分代码省略.........
开发者ID:PaulWagener,项目名称:khan-website,代码行数:103,代码来源:login.py


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