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


Python User.create方法代码示例

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


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

示例1: test_user_management

# 需要导入模块: from auth.models import User [as 别名]
# 或者: from auth.models.User import create [as 别名]
    def test_user_management(self):
        """
        test user creation and deletion
        """
        # creation
        user = User.create('[email protected]', 'world')
        self.assertTrue(user)

        # retrieve
        self.assertTrue(User.get_by_id(user.id))
        self.assertTrue(User.get_by_email(user.email))

        # duplicated users
        self.assertFalse(User.create('[email protected]', 'world'))

        try:
            user2 = User(email='[email protected]', password='world')
            user2.save()
        except UserSaveError:
            pass
        else:
            self.assertFalse('The user wrongly saved')

        # deletion
        self.assertTrue(user.delete())
        user4 = User.get_by_email('[email protected]')
        self.assertFalse(user4)
开发者ID:digitaldreamer,项目名称:fivesquare,代码行数:29,代码来源:tests.py

示例2: setUp

# 需要导入模块: from auth.models import User [as 别名]
# 或者: from auth.models.User import create [as 别名]
    def setUp(self):
        from service import main
        from paste.deploy import appconfig
        from webtest import TestApp

        # set settings
        os.environ['PYRAMID_SETTINGS'] = 'development.ini#main'
        self.settings = appconfig('config:{}'.format(os.environ['PYRAMID_SETTINGS']), relative_to='.')
        app = main({}, **self.settings)
        self.testapp = TestApp(app)
        self.config = testing.setUp(settings=self.settings)

        self.created_ids = []

        # init user
        self.user = User.create('[email protected]', 'hello')
        payload = {
            'email': '[email protected]',
            'password': 'hello',
        }
        response = self.testapp.post_json('/api/v1/authenticate', payload, status=200)
        self.access_token = response.json['access_token']

        # init business
        address = {
            'street1': 'Central Park',
            'city': 'New York',
            'state': 'NY',
        }
        self.business = Business.create('Test Location', address)
开发者ID:digitaldreamer,项目名称:fivesquare,代码行数:32,代码来源:tests.py

示例3: run

# 需要导入模块: from auth.models import User [as 别名]
# 或者: from auth.models.User import create [as 别名]
def run(env):
    user = User.create('[email protected]', 'test')
    print 'created user'

    businesses = create_businesses()
    business = businesses[0]
    print 'created businesses'

    reviews = create_reviews(user, business)
    print 'created reviews'
开发者ID:digitaldreamer,项目名称:fivesquare,代码行数:12,代码来源:load_db.py

示例4: prompt

# 需要导入模块: from auth.models import User [as 别名]
# 或者: from auth.models.User import create [as 别名]
def prompt(env):
    email = raw_input('email: ')
    password1, password2 = pprompt()

    while password1 != password2:
        print "Passwords do not match. Try again."
        password1, password2 = pprompt()

    user = User.create(email, password1)

    if user:
        print "user '{}' created".format(user.id)
    else:
        # TODO: better error messaging
        print "error: user {} not created".format(email)
开发者ID:digitaldreamer,项目名称:fivesquare,代码行数:17,代码来源:create_user.py

示例5: users_post

# 需要导入模块: from auth.models import User [as 别名]
# 或者: from auth.models.User import create [as 别名]
    def users_post(request):
        """
        an endpoint to create new users

        new users are not active by default

        TODO: have a user activation process


        errors
        ======

        * status 400 - if failed


        returns
        =======

        ::

            {
                "id": ""
            }
        """
        email = request.validated['email']
        password = request.validated['password']

        user = User.create(email, password)

        if user:
            # TODO: send activation email
            logger.debug('new user created')
            response_body = json.dumps({'id': user.json['id']})
        else:
            logger.debug('failed to create new user')
            request.response.status_int = 400
            response_body = json.dumps({
                'status': 'error',
                'message': 'failed to create new user'
            })

        request.response.body = response_body
        request.response.content_type = 'application/json'
        return request.response
开发者ID:digitaldreamer,项目名称:fivesquare,代码行数:46,代码来源:views.py

示例6: test_create_user_with_success

# 需要导入模块: from auth.models import User [as 别名]
# 或者: from auth.models.User import create [as 别名]
def test_create_user_with_success():
    User.create(username='testuser', email='[email protected]', password='12345678', confirm_password='12345678')
    user = User.query.filter_by(username='testuser').one()
    assert user.email == '[email protected]'
开发者ID:maxnovais,项目名称:flapy_auth,代码行数:6,代码来源:test_user.py

示例7: test_create_user_raises_error

# 需要导入模块: from auth.models import User [as 别名]
# 或者: from auth.models.User import create [as 别名]
def test_create_user_raises_error(user, exception, username, email, password, confirm_password):
    with pytest.raises(exception):
        User.create(username=username, email=email, password=password, confirm_password=confirm_password)
开发者ID:maxnovais,项目名称:flapy_auth,代码行数:5,代码来源:test_user.py

示例8: create_admin

# 需要导入模块: from auth.models import User [as 别名]
# 或者: from auth.models.User import create [as 别名]
def create_admin(console=True):
    email = raw_input('Email: ')
    password = raw_input('Password: ')
    User.create(email=email, is_admin=True, password=password)
    print('Ok')
开发者ID:mkaplenko,项目名称:containers,代码行数:7,代码来源:manage.py

示例9: create_user

# 需要导入模块: from auth.models import User [as 别名]
# 或者: from auth.models.User import create [as 别名]
def create_user():
    """ Create User

    Create a new user
    ---
    tags:
      - User
    parameters:
      - in: body
        name: body
        required: true
        schema:
          id: create_edit_user_form
          required:
            - username
            - email
            - password
            - confirm_password
          properties:
            username:
              type: string
            email:
              type: string
            password:
              type: string
            confirm_password:
              type: string
    responses:
      201:
        description: Created User
        schema:
          id: create_edit_user
          properties:
            user:
              schema:
                $ref: "#/definitions/User"
      400:
        description: Invalid json informations
        schema:
          $ref: "#/definitions/generic_error"
      401:
        description: Invalid credentials
        schema:
          $ref: "#/definitions/generic_error"
      409:
        description: Conflict
        schema:
          $ref: "#/definitions/generic_error"
    """
    required_fields = ('username', 'email', 'password', 'confirm_password')
    if all(request.json.get(field) for field in required_fields):
        username = request.json.get('username')
        email = request.json.get('email')
        password = request.json.get('password')
        confirm_password = request.json.get('confirm_password')
    else:
        return abort(400)

    try:
        user = User.create(username=username, email=email, password=password, confirm_password=confirm_password)
        data = {'user': dict_object(user)}
        return jsonify(data), 201

    except (InvalidUsername, InvalidEmail, InvalidPassword, PasswordMismatch):
        abort(400)

    except UserAlreadyExist:
        abort(409)
开发者ID:maxnovais,项目名称:flapy_auth,代码行数:70,代码来源:admin.py

示例10: create_user

# 需要导入模块: from auth.models import User [as 别名]
# 或者: from auth.models.User import create [as 别名]
 def create_user(self):
     # check user
     user = User.create('[email protected]', 'hello')
     self.assertTrue(user)
     return user
开发者ID:digitaldreamer,项目名称:fivesquare,代码行数:7,代码来源:tests.py


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