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


Python User.user_from_email方法代码示例

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


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

示例1: post

# 需要导入模块: from model import User [as 别名]
# 或者: from model.User import user_from_email [as 别名]
    def post(self):
        email = self.request.get('email', '')
        password = self.request.get('password', '')
        other_username = self.request.get('other-user')

        logging.info('%s, %s' % (email, other_username))

        user = User.user_from_email(email)

        if not user:
            logging.info('not a valid email address')
            self.render('error.html', **{'error_msg': 'You cannot do this'})
            return
        if not self.validate_user(user, password):
            logging.info('username password fail')
            self.render('error.html', **{'error_msg': 'You cannot do this'})
            return
        if not user.admin:
            logging.info('Need to be admin to login as other user')
            self.render('error.html', **{'error_msg': 'You cannot do this'})
            return

        other_user = User.user_from_name(other_username)
        logging.info('Other user: %s' % other_user)

        if not other_user:
            logging.info('cannot find other user')
            self.render('error.html', **{'error_msg': "Can't find other user"})
            return

        self.set_cookie(other_user)
        self.redirect('/user/%d' % other_user.key.id())
开发者ID:PreludeAndFugue,项目名称:prelude-hmpc,代码行数:34,代码来源:user_admin.py

示例2: input_errors

# 需要导入模块: from model import User [as 别名]
# 或者: from model.User import user_from_email [as 别名]
    def input_errors(self, username, password, validate, email):
        '''Return a list of errors with user registration data.'''
        # collect error text strings
        errors = []

        # username errors
        if not username:
            errors.append('You forgot to enter a username.')
            logging.warning('Register: forgot username.')
        elif not self.valid_name(username):
            errors.append(
                'A Valid user name can contain only the characters '
                'a-z, A-Z, 0-9, _ (underscore) and - (dash) and must be at '
                'least 3 characters long.'
            )
            logging.warning('Register: invalid username: %s.', username)

        user = User.user_from_name(username)
        if user:
            # user name already exists
            errors.append(
                'That user name already exists, please choose another one.'
            )
            logging.warning('Register: username already in use. %s', user)

        # email errors
        if not email:
            errors.append('You forgot to enter an email address.')
            logging.warning('Register: forgot email.')
        elif not self.valid_email(email):
            errors.append(
                'Check your email address - it may not '
                'be correct.')
            logging.warning('Register: invalid email: %s', email)
        else:
            # maybe the email address is being used by another user - can't
            # have more than one user with the same email address because the
            # email address is used as login id
            user = User.user_from_email(email)
            if user:
                # email address is attached to other user
                errors.append(
                    'This email address is used by another user.'
                )
                msg = 'Register: email address already in use: %s'
                logging.warning(msg, email)

        # password errors
        if not password or not validate:
            errors.append('You forgot to enter your password twice.')
            logging.warning('Register: forgot to enter password twice.')
        elif password != validate:
            msg = "Your password confirmation doesn't match your password."
            errors.append(msg)
            logging.warning('Register: validate != password.')
        if not self.valid_pass(password):
            errors.append(
                'Not a valid password - it must contain at least '
                '3 characters.')
            logging.warning('Register: invalid password.')

        return errors
开发者ID:PreludeAndFugue,项目名称:prelude-hmpc,代码行数:64,代码来源:user_admin.py


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