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


Python models.User类代码示例

本文整理汇总了Python中api.models.User的典型用法代码示例。如果您正苦于以下问题:Python User类的具体用法?Python User怎么用?Python User使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: TestUserApiRetrieve

class TestUserApiRetrieve(APITestCase):
    def setUp(self):
        self.user = User(first_name='Etienne',last_name='Chabert',email='[email protected]',password='password',date_of_birth='1990-11-18')
        self.user.save()

    def test_user_valid_token(self):
        token = self.user.get_valid_token()
        data = {
            'token' : token.token.__str__()
        }
        response = self.client.post('/api/users/retrieve',data)
        self.assertEqual(response.status_code, 200)

    def test_user_expired_token(self):
        token = self.user.get_valid_token()
        token.creation_dateTime -= timedelta(days=42)
        token.save()

        data = {
            'token' : token.token.__str__()
        }
        response = self.client.post('/api/users/retrieve',data)
        self.assertEqual(response.status_code, 400)

    def test_user_unknown_token(self):
        data = {
            'token' : uuid.uuid4()
        }
        response = self.client.post('/api/users/retrieve',data)
        self.assertEqual(response.status_code, 400)
开发者ID:etiennechabert,项目名称:kolibree_backend_test,代码行数:30,代码来源:test_user_api.py

示例2: add_user

def add_user(name, birthday, phone, pushtoken, photo=None, phone_model=None):
    user = User(name, birthday, phone, pushtoken, phone_model)
    db.session.add(user)
    db.session.commit()
    if photo is not None:
        user.photo = func.get_user_photo_path(user.id)
        db.session.commit()
开发者ID:Corea,项目名称:singlo_server,代码行数:7,代码来源:queries.py

示例3: get

    def get(self, username=None):
        response = {}
        if username:
            user = User.objects(username__iexact=username).first()

            if not user:
                abort(404, message="Username does not exist.")

            response = {
                'username': user.username,
                'email': user.email,
                'type': user.user_type,
                'created_at': str(user.created_at),
                'updated_at': str(user.updated_at)
            }
        else:
            users = User.objects()

            for index, user in enumerate(users):
                response[index + 1] = {
                    'username': user.username,
                    'email': user.email,
                    'type': user.user_type,
                    'created_at': str(user.created_at),
                    'updated_at': str(user.updated_at)
                }

        return response
开发者ID:dita-dev-team,项目名称:MemoApi,代码行数:28,代码来源:userapi.py

示例4: register_user

def register_user(request):
	try:
		username = request.GET["username"]
	except KeyError:
		return HttpResponseBadRequest("username required but not provided")
	u = User(username=username)
	u.save()
	return HttpResponse(user_json(registered=True))
开发者ID:usmanm,项目名称:goodplates,代码行数:8,代码来源:views.py

示例5: setUp

 def setUp(self):
     self.app = create_app("test_config")
     self.ctx = self.app.app_context()
     self.ctx.push()
     db.drop_all()
     db.create_all()
     u = User(username=self.default_username, password=self.default_password)
     db.session.add(u)
     db.session.commit()
     self.client = TestClient(self.app, u.generate_auth_token(), "")
开发者ID:Zabanaa,项目名称:api-pycon2014,代码行数:10,代码来源:test_api.py

示例6: post

    def post(self):
        args = parser.parse_args()

        user = User.objects(username__iexact=args['username']).first()
        if user:
            abort(409, message="Username already exists.")

        user = User(username=args['username'])
        user.password = bcrypt.generate_password_hash(args['password'])

        if args['type'] == 'individual':
            user.user_type = args['type']
            user.user_profile = Individual()
        elif args['type'] == 'group':
            user.user_type = args['type']
            user.user_profile = Group()

        user.save()

        response = {
            'username': user.username,
            'email': user.email,
            'type': user.user_type,
            'created_at': str(user.created_at),
            'updated_at': str(user.updated_at)
        }

        return response
开发者ID:dita-dev-team,项目名称:MemoApi,代码行数:28,代码来源:userapi.py

示例7: adduser

def adduser(username):
    u"""Adds user to the REST API"""
    from getpass import getpass
    password = getpass()
    password2 = getpass(prompt='Confirm: ')
    if password != password2:
        sys.exit('Sorry, passwords are not matching.')
        db.set(username, username)
        user = User(username=username)
        user.password = password
        print("User {} is correctly created.".format(username))
开发者ID:drowolath,项目名称:dvbbox,代码行数:11,代码来源:core.py

示例8: post

 def post(self):
     req_kwargs = self.reqparse.parse_args()
     user = User(email=req_kwargs['email'])
     user.hash_password(req_kwargs['password'])
     try:
         user.save()
     except ValidationError as e:
         return {'message': e.message}, status.HTTP_400_BAD_REQUEST
     except NotUniqueError:
         return {'message': 'This email already registered'}, status.HTTP_409_CONFLICT
     return {'message': 'Success'}, status.HTTP_200_OK
开发者ID:himynameisvlad,项目名称:angular_flask_jwt_auth_example,代码行数:11,代码来源:views.py

示例9: users_post

def users_post():
    email = request.form['email']
    password = request.form['password']
    info = request.form['info']
    if email is None or password is None:
        abort(400)
    if User.query.filter_by(email=email).first() is not None:
        abort(400)
    user = User(email=email, info=info)
    user.hash_password(password)
    user.registered_on = datetime.utcnow()
    db.session.add(user)
    db.session.commit()
    return jsonify({'status': 'OK', 'user': user.email, 'pass': password})
开发者ID:stamigos,项目名称:job,代码行数:14,代码来源:views.py

示例10: create_user

 def create_user(self, author, user, passhash, user_root):
     u = User()
     u.author = author
     u.user_root = user_root
     u.active = True
     u.name = user
     u.password = passhash
     u.save()
开发者ID:molinamiguel,项目名称:cityhall,代码行数:8,代码来源:users.py

示例11: create_user

def create_user():
    j = request.get_json()
    u = User(first_name=j['first_name'],
             last_name=j['last_name'],
             username=j['username'],
             role=j['role'])

    # Hash password
    # This is not a secure way at all to do this...
    u.password_hash = hashlib.sha256(j['password'].encode()).hexdigest()

    db_session.add(u)
    db_session.commit()

    return jsonify(UserSchema().dump(u).data)
开发者ID:AaronBuxbaum,项目名称:CS6310-FinalProject,代码行数:15,代码来源:user.py

示例12: delete

 def delete(self, project_id, collaborator_id):
     collaborator = Collaborator.get(collaborator_id)
     current_user = User.current_user()
     if current_user.key() != collaborator.user.key():
         collaborator.remove()
     else:
         self.error(404)
开发者ID:likr,项目名称:egrid,代码行数:7,代码来源:collaborator_handler.py

示例13: get_token_validity_status

def get_token_validity_status():
    """check if the token is still valid. If not return 400. If valid, return new token"""
    token = request.authorization.username
    user = User.verify_auth_token(token)
    if not user:
        return get_error("token not valid"), 400
    else:
        return jsonify(user_info(user)), 200
开发者ID:ntung,项目名称:JoggingTracker,代码行数:8,代码来源:auth_service.py

示例14: get

	def get(self, request, *args, **kwargs):
		csrf_token = get_token(request)
		id = kwargs.get('id')
		user = User.get_by_pk(id)
		if user is None:
			data = {'user': {}, 'csrf_token': csrf_token}
		else:
			data = {'user': user.to_dict(), 'csrf_token': csrf_token}
		return render_json_response(request, data)
开发者ID:arvelt,项目名称:ateraku,代码行数:9,代码来源:views.py

示例15: user_add

def user_add(request):
	name = request.GET.get('name', '')
	email = request.GET.get('email', '')
	context={}
	"""  check if email is correct and name not empty  """
	if not re.match(r"[^@][email protected][^@]+\.[^@]+", email) or name == '':
		return render(request, 'webapp/user_form.html', context)
	"""  check if user already exists  """
	try:
		exists = User.objects.get(email=email)
	except User.DoesNotExist:
		exists = None
		user = User(email = email, name = name)
		user.save()
		user_list = User.objects.all().order_by('email')
		context={"user_list":user_list}
		return render(request, 'webapp/user.html', context)
	return render(request, 'webapp/user_form.html', context)
开发者ID:IvoPintodaSilva,项目名称:ubiChallenge,代码行数:18,代码来源:views.py


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