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


Python User.isEmailValid方法代码示例

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


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

示例1: testEmail

# 需要导入模块: from model import User [as 别名]
# 或者: from model.User import isEmailValid [as 别名]
 def testEmail(self):
     # Valid emails
     email = '[email protected]'
     self.assertTrue(User.isEmailValid(email), 'Misqualified valid email: ' + email)
     email = '[email protected]'
     self.assertTrue(User.isEmailValid(email), 'Misqualified valid email: ' + email)
     email = 'dfssd32e23esd_%[email protected]w.info'
     self.assertTrue(User.isEmailValid(email), 'Misqualified valid email: ' + email)
     
     # Invalid emails
     email = 'ja\'[email protected]'
     self.assertFalse(User.isEmailValid(email), 'Misqualified invalid email: ' + email)
     email = 'ja\"[email protected]'
     self.assertFalse(User.isEmailValid(email), 'Misqualified invalid email: ' + email)
     email = ''
     self.assertFalse(User.isEmailValid(email), 'Misqualified invalid email: ' + email)
     email = ' '
     self.assertFalse(User.isEmailValid(email), 'Misqualified invalid email: ' + email)
     email = 'asd'
     self.assertFalse(User.isEmailValid(email), 'Misqualified invalid email: ' + email)
     email = "a'[email protected]"
     self.assertFalse(User.isEmailValid(email), 'Misqualified invalid email: ' + email)
开发者ID:szilardhuber,项目名称:shopper,代码行数:24,代码来源:test_user_unit.py

示例2: __register

# 需要导入模块: from model import User [as 别名]
# 或者: from model.User import isEmailValid [as 别名]
    def __register(self, api):
        """ Check incoming parameters and register user """
        # Validate email
        email = self.request.get(constants.VAR_NAME_EMAIL)
        logging.info('User registering: ' + str(email))
        if not User.isEmailValid(email) or User.isAlreadyRegistered(email):
            logging.error('Email mismatched or already registered')
            self.set_error(constants.STATUS_BAD_REQUEST,
                           self.gettext('REGISTER_ERROR'),
                           url=self.request.url)
            return

        # Validate password
        password = self.request.get(constants.VAR_NAME_PASSWORD)
        if not User.isPasswordValid(password):
            logging.error('Invalid password')
            self.set_error(constants.STATUS_BAD_REQUEST,
                           self.gettext('REGISTER_ERROR'),
                           url=self.request.url)
            return

        # Calculate password hash
        salt_and_key = CryptoUtil.get_salt_and_key(password)
        salt = salt_and_key[0]
        key = salt_and_key[1]

        # Create and store user object
        user = User(key_name=email)
        user.email = email.lower()
        user.salt = salt
        user.password = key
        user.verified = False
        user.put()

        # Send email for verification
        self.__send_verification(email)

        if api == '':
            # Display message
            template_values = {
                'message': self.gettext('PLEASE_CHECK_YOUR_EMAIL')
            }
            template = self.jinja2_env.get_template('staticmessage.html')
            self.response.out.write(template.render(template_values))

        self.ok()
开发者ID:szilardhuber,项目名称:shopper,代码行数:48,代码来源:userhandler.py

示例3: __login

# 需要导入模块: from model import User [as 别名]
# 或者: from model.User import isEmailValid [as 别名]
    def __login(self):
        """ Validate incoming parameters and log in user if all is ok """
        # Validate email and get user from db
        email = self.request.get(constants.VAR_NAME_EMAIL)
        logging.info('User logging in: ' + str(email))
        if not User.isEmailValid(email) or not User.isAlreadyRegistered(email):
            logging.error('Email mismatched or not registered')
            self.set_error(constants.STATUS_BAD_REQUEST,
                           self.gettext('LOGIN_ERROR'), url=self.request.url)
            return
        user = User.getUser(email.lower())

        # Calculate password hash
        password = self.request.get(constants.VAR_NAME_PASSWORD)
        if not User.isPasswordValid(password):
            logging.error('Invalid password')
            self.set_error(constants.STATUS_BAD_REQUEST,
                           self.gettext('LOGIN_ERROR'), url=self.request.url)
            return
        key = CryptoUtil.getKey(password, user.salt)

        # Validate password
        if not user.password == key:
            logging.error('Incorrect password for email')
            self.set_error(constants.STATUS_BAD_REQUEST,
                           self.gettext('LOGIN_ERROR'), url=self.request.url)
            return

        # Check remember me
        remember_string = self.request.get('remember').lower()
        remember = remember_string != '' and remember_string != 'false'
        if remember:
            token_id = LoginToken.generate_id()
            token = LoginToken()
            token.tokenid = token_id
            token.ip = self.request.remote_addr
            token.user = email
            token.put()
            cookie_value = token.get_cookie_value()
            delta = timedelta(days=constants.PERSISTENT_LOGIN_LIFETIME_DAYS)
            self.response.set_cookie(constants.PERSISTENT_LOGIN_NAME,
                                     cookie_value,
                                     expires=datetime.utcnow() + delta,
                                     path="/", httponly=True, secure=True)

        # Log in user
        if user.verified:
            user.login(self.request.remote_addr)
            session = get_current_session()
            url = session.pop(constants.VAR_NAME_REDIRECT)
            if url is None:
                url = "/"
            self.ok(url)
        else:
            logging.error('User unverified')
            self.set_error(constants.STATUS_FORBIDDEN,
                           self.gettext('UNVERIFIED_PRE') +
                           ' <a href=\"/User/Verify">' +
                           self.gettext('UNVERIFIED_HERE') +
                           '</a> ' +
                           self.gettext('UNVERIFIED_POST'),
                           url=self.request.url)
            return
开发者ID:szilardhuber,项目名称:shopper,代码行数:65,代码来源:userhandler.py


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