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


Python User.create方法代码示例

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


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

示例1: test_invalid_password_is_rejected

# 需要导入模块: from app.users.models import User [as 别名]
# 或者: from app.users.models.User import create [as 别名]
    def test_invalid_password_is_rejected(self):
        User.create(name="Joe", email="[email protected]", password="12345")

        with self.client:
            self.client.post("/login/", data={"name": "Joe", "password": "****"})

            self.assertTrue(current_user.is_anonymous())
开发者ID:KirkHadley,项目名称:flask-tracking,代码行数:9,代码来源:tests.py

示例2: test_users_can_logout

# 需要导入模块: from app.users.models import User [as 别名]
# 或者: from app.users.models.User import create [as 别名]
    def test_users_can_logout(self):
        User.create(name="Joe", email="[email protected]", password="12345")

        with self.client:
            self.client.post("/login/", data={"name": "Joe", "password": "12345"})
            self.client.get("/logout/")

            self.assertTrue(current_user.is_anonymous())
开发者ID:KirkHadley,项目名称:flask-tracking,代码行数:10,代码来源:tests.py

示例3: test_users_can_login

# 需要导入模块: from app.users.models import User [as 别名]
# 或者: from app.users.models.User import create [as 别名]
    def test_users_can_login(self):
        User.create(name="Joe", email="[email protected]", password="12345")

        with self.client:
            response = self.client.post("/login/", data={"name": "Joe", "password": "12345"})

            self.assert_redirects(response, url_for("index"))
            self.assertTrue(current_user.name == "Joe")
            self.assertFalse(current_user.is_anonymous())
开发者ID:KirkHadley,项目名称:flask-tracking,代码行数:11,代码来源:tests.py

示例4: post

# 需要导入模块: from app.users.models import User [as 别名]
# 或者: from app.users.models.User import create [as 别名]
    def post(self):
        resp = request.get_json()
        avatar = resp.get('avatar')
        email = resp.get('email')
        username = resp.get('username')
        first_name = resp.get('first_name') or ''
        last_name = resp.get('last_name') or ''
        password = resp.get('password')
        gender = resp.get('gender') or ''


        user = User.create(
            avatar=avatar, 
            email=email, 
            first_name=first_name, 
            gender=gender,  
            last_name=last_name, 
            password=password,
            username=username,
            created=datetime.datetime.now(),
            last_login=datetime.datetime.now(),
            activated=False,
        )
        
        return Response(json.dumps(user.serialize), mimetype='application/json')
开发者ID:47bytes,项目名称:flask-big-app,代码行数:27,代码来源:views.py

示例5: test_visitors_location_is_derived_from_ip

# 需要导入模块: from app.users.models import User [as 别名]
# 或者: from app.users.models.User import create [as 别名]
    def test_visitors_location_is_derived_from_ip(self):
        user = User.create(name="Joe", email="[email protected]", password="12345")
        site = Site.create(user_id=user.id)

        mock_geodata = Mock(name="get_geodata")
        mock_geodata.return_value = {
            'city': 'Los Angeles',
            'zipcode': '90001',
            'latitude': '34.05',
            'longitude': '-118.25'
        }

        url = url_for("tracking.register_visit", site_id=site.id)
        wsgi_environment = {"REMOTE_ADDR": "1.2.3.4"}

        with patch.object(app.tracking.views, "get_geodata", mock_geodata):
            with self.client:
                self.client.get(url, environ_overrides=wsgi_environment)

                visits = Visit.query.all()

                mock_geodata.assert_called_once_with("1.2.3.4")
                self.assertEquals(1, len(visits))
                self.assertEquals("Los Angeles, 90001", visits[0].location)
                self.assertEquals("Los Angeles, 90001, 34.05, -118.25",
                                  visits[0].location_full)
开发者ID:KirkHadley,项目名称:flask-tracking,代码行数:28,代码来源:tests.py

示例6: signup

# 需要导入模块: from app.users.models import User [as 别名]
# 或者: from app.users.models.User import create [as 别名]
def signup():
    if current_user.is_authenticated():
        flash(gettext('You are already signed in.'))
        return redirect(url_for('index'))        
    
    form = SignUpForm()
    if form.validate_on_submit():
        try:
            ## Create user from the form
            user = User.create()

            form.populate_obj(user)
            user.set_password(form.password.data)
            user.last_seen = datetime.datetime.utcnow()
            user.last_login = datetime.datetime.utcnow()
            ## Store in database
            user.save()
            ## Login User
            login_user(user)
            flash(gettext('Welcome! You have signed up successfully.'))
            return redirect(url_for('index'))
        except:
            flash(gettext('Error while saving the new user, please retry later'), 'error')

    return render_template('admin/signup.html', 
        title = gettext('Sign Up'),
        form = form)
开发者ID:Tibodef,项目名称:PythonBlog,代码行数:29,代码来源:views.py

示例7: init_db

# 需要导入模块: from app.users.models import User [as 别名]
# 或者: from app.users.models.User import create [as 别名]
 def init_db(cls):
     user = User.create()
     user.name = u'Juan Tabares'
     user.nickname = u'jctt'
     user.set_password(u'admin123456')
     user.role = 1
     user.email = u'[email protected]'
     user.last_seen = datetime.datetime.utcnow()
     user.save()
     DbInit.init_categories()
开发者ID:Tibodef,项目名称:PythonBlog,代码行数:12,代码来源:db_init.py


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