Пример #1
0
def update():
    form = UserUpdateForm(request)
    if not form.validate():
        return json({'message': 'Validation Failed', 'errors': form.errors}, 422)

    user = app.auth.user

    if user.name != form.name and User.nameExists(form.name):
        return json({'message': 'Validation Failed', 'errors': [
                {'code': 'already_exists', 'field': 'name'}]}, 422)

    if user.email != form.email and User.emailExists(form.email):
        return json({'message': 'Validation Failed', 'errors': [
                {'code': 'already_exists', 'field': 'email'}]}, 422)

    user.update_values(form.data)

    try:
        if form.avatar:
            user.saveAvatar(form.avatar)

        if user.update():
            app.auth.user = user
            return json(user, 200)
        else:
            return json({'message': 'An error ocurred while creating the user'}, 400)
    except ValidationException, e:
        return json({'message': 'Validation Failed', 'errors': [
                                                        {'reason': e.reason, 'field': e.field_name}]}, 422)
Пример #2
0
def create():
    form = UserCreateForm(request)
    if not form.validate():
        return json({
            'message': 'Validation Failed',
            'errors': form.errors
        }, 422)

    try:
        user = User.create(User(**form.data))
        if user:
            if form.avatar:
                user.saveAvatar(form.avatar)
            return json(user, 201)
        else:
            return json(
                {'message': 'An error ocurred while creating the user'}, 400)
    except ValidationException, e:
        return json(
            {
                'message': 'Validation Failed',
                'errors': [{
                    'reason': e.reason,
                    'field': e.field_name
                }]
            }, 422)
Пример #3
0
    def testUpdate(self):
        user = User(
            id=2,
            name='paul',
            avatar_url=
            'https://s3.amazonaws.com/boardhood_user_avatars/sheldoncooper.png'
        )
        user.email = "*****@*****.**"
        user.password = '******'

        self.assertTrue(user.update())
Пример #4
0
    def testCreate(self):
        obj = User.create(User(name=self.name, email=self.name + '@teste.com', password='******'))
        self.assertEqual(obj.name, self.name)
        self.assertTrue(is_integer(obj.id), 'ID was supposed to be int. Value: %s' % str(obj.id))

        try:
            name = 'teste&%***(9 "" '
            obj = User.create(User(name=name, email=name + '@teste.com', password='******'))
            self.fail("Create user should not succeed with invalid data")
        except ValidationException, e:
            self.assertTrue(True)
Пример #5
0
def update():
    form = UserUpdateForm(request)
    if not form.validate():
        return json({
            'message': 'Validation Failed',
            'errors': form.errors
        }, 422)

    user = app.auth.user

    if user.name != form.name and User.nameExists(form.name):
        return json(
            {
                'message': 'Validation Failed',
                'errors': [{
                    'code': 'already_exists',
                    'field': 'name'
                }]
            }, 422)

    if user.email != form.email and User.emailExists(form.email):
        return json(
            {
                'message': 'Validation Failed',
                'errors': [{
                    'code': 'already_exists',
                    'field': 'email'
                }]
            }, 422)

    user.update_values(form.data)

    try:
        if form.avatar:
            user.saveAvatar(form.avatar)

        if user.update():
            app.auth.user = user
            return json(user, 200)
        else:
            return json(
                {'message': 'An error ocurred while creating the user'}, 400)
    except ValidationException, e:
        return json(
            {
                'message': 'Validation Failed',
                'errors': [{
                    'reason': e.reason,
                    'field': e.field_name
                }]
            }, 422)
Пример #6
0
def show():
    user = User.findById(app.auth.user.id)

    if user is not None:
        return json(user.to_self_dict())
    else:
        return json({'message': 'There is no authenticated user'}, 404)
Пример #7
0
    def testCreate(self):
        obj = User.create(
            User(name=self.name,
                 email=self.name + '@teste.com',
                 password='******'))
        self.assertEqual(obj.name, self.name)
        self.assertTrue(is_integer(obj.id),
                        'ID was supposed to be int. Value: %s' % str(obj.id))

        try:
            name = 'teste&%***(9 "" '
            obj = User.create(
                User(name=name, email=name + '@teste.com', password='******'))
            self.fail("Create user should not succeed with invalid data")
        except ValidationException, e:
            self.assertTrue(True)
Пример #8
0
def show():
    user = User.findById(app.auth.user.id)
    	
    if user is not None:
        return json(user.to_self_dict())
    else:
        return json({'message': 'There is no authenticated user'}, 404)
Пример #9
0
 def followers(id, offset=0, limit=20):
     try:
         cursor = Interest.cursor()
         cursor.execute(FOLLOWERS, [str(id), limit, offset])
         return User.parse_all(cursor.fetchall())
     except Exception, e:
         Interest.report_error(e, cursor)
         return False
Пример #10
0
 def followers(id, offset=0, limit=20):
     try:
         cursor = Interest.cursor()
         cursor.execute(FOLLOWERS, [str(id), limit, offset])
         return User.parse_all(cursor.fetchall())
     except Exception, e:
         Interest.report_error(e, cursor)
         return False
Пример #11
0
def show_user(name):
    form = UserShowForm(url={'name': name})
    if not form.validate():
        return json({'message': 'Validation Failed', 'errors': form.errors}, 422)

    data = User.findByName(form.name)
    if data is not False:
        return json(data)
    else:
        return json({'message': 'User with given name not found'}, 404)
Пример #12
0
def show_user(name):
    form = UserShowForm(url={'name': name})
    if not form.validate():
        return json({
            'message': 'Validation Failed',
            'errors': form.errors
        }, 422)

    data = User.findByName(form.name)
    if data is not False:
        return json(data)
    else:
        return json({'message': 'User with given name not found'}, 404)
Пример #13
0
def create():
    form = UserCreateForm(request)
    if not form.validate():
        return json({'message': 'Validation Failed', 'errors': form.errors}, 422)

    try:
        user = User.create(User(**form.data))
        if user:
            if form.avatar:
                user.saveAvatar(form.avatar)
            return json(user, 201)
        else:
            return json({'message': 'An error ocurred while creating the user'}, 400)
    except ValidationException, e:
        return json({'message': 'Validation Failed',
                     'errors': [{'reason': e.reason, 'field': e.field_name}]}, 422)
Пример #14
0
def show_user_conversations(name):
    form = UserNameListForm(request, url={'name': name})
    if not form.validate():
        return json({'message': 'Validation Failed', 'errors': form.errors}, 422)

    if not User.nameExists(form.name):
        return json({'message': 'User with given name not found'}, 404)

    total = Conversation.countAllByUserName(form.name)
    pg = paginate(form, total)

    if total > 0:
        if pg.page_valid:
            data = Conversation.findAllByUserName(form.name, pg.offset, pg.per_page)
        else:
            return json({'message': "This is the end of the list"}, 404)
    else:
        data = []

    return json(dict(conversations=data, **pg.info))
Пример #15
0
def show_user_interests(name):
    form = UserNameListForm(request, url={'name': name})
    if not form.validate():
        return json({
            'message': 'Validation Failed',
            'errors': form.errors
        }, 422)

    if not User.nameExists(form.name):
        return json({'message': 'User with given name not found'}, 404)

    total = Interest.countAllByUserName(form.name)
    pg = paginate(form, total)

    if total > 0:
        if pg.page_valid:
            data = Interest.findAllByUserName(form.name, pg.offset,
                                              pg.per_page)
        else:
            return json({'message': "This is the end of the list"}, 404)
    else:
        data = []

    return json(dict(interests=data, **pg.info))
Пример #16
0
    def parse(row, **kwargs):
        if not row:
            return None

        if len(kwargs) > 0:
            row.update(kwargs)

        obj = Conversation(**row)
        obj.author = User(id=row.get('user_id'),
                          name=row.get('username'),
                          avatar_url=row.get('avatar_url'))

        if row.get('lat') and row.get('lon'):
            obj.location = {'lat': row.get('lat'), 'lon': row.get('lon')}

        if row.get('interest_id') or row.get('interest_name'):
            obj.interest = Interest(id=row.get('interest_id'),
                                    name=row.get('interest_name'))

        if row.get('parent_id') or row.get('parent_name'):
            obj.parent = Conversation(id=row.get('parent_id'),
                                      name=row.get('parent_name'))

        return obj
Пример #17
0
 def testAuthenticate(self):
     user = User(name='john', password='******')
     auth = User.authenticate(user)
     if auth is False:
         self.fail("User is not authenticated")
Пример #18
0
 def testNameExists(self):
     self.assertTrue(User.nameExists('john'))
     self.assertFalse(User.nameExists('dasdasdjskow3'))
Пример #19
0
 def emailExists(self):
     self.assertTrue(User.emailExists('*****@*****.**'))
     self.assertFalse(User.emailExists('*****@*****.**'))
Пример #20
0
from boardhood.helpers.response import json
from boardhood.helpers.image import resize
from boardhood.helpers.pagination import paginate
from boardhood.helpers.auth import require_user_auth
from boardhood.models.applications import Application, require_app_auth
from boardhood.models.users import User
from boardhood.models.interests import Interest
from boardhood.models.conversations import Conversation
from boardhood.models.base import ValidationException, UniqueViolationException
from boardhood.forms import (UserCreateForm, UserUpdateForm, UserListForm,
                             UserNameListForm, UserShowForm, InterestSearchForm,
                             UserActivityForm)

module = Blueprint('users', __name__)
User.register_app(module, app)
Interest.register_app(module, app)
Conversation.register_app(module, app)


# POST /users  -----------------------------------------------------------------
@module.route('/users', methods=['POST'])
@require_app_auth(app, Application.LEVEL_ALL)
def create():
    form = UserCreateForm(request)
    if not form.validate():
        return json({'message': 'Validation Failed', 'errors': form.errors}, 422)

    try:
        user = User.create(User(**form.data))
        if user:
Пример #21
0
    def testUpdate(self):
        user = User(id=2, name='paul', avatar_url='https://s3.amazonaws.com/boardhood_user_avatars/sheldoncooper.png')
        user.email = "*****@*****.**"
        user.password = '******'

        self.assertTrue(user.update())
Пример #22
0
 def testExists(self):
     self.assertTrue(User.exists(1))
Пример #23
0
    def init_app(self, app):
        self.app = app
        self.store = app.cache

        User.register_app(app)
Пример #24
0
 def check_auth(self, auth):
     user = User(name=auth.username, password=auth.password, ip=request.remote_addr, timestamp=datetime.utcnow())
     self.user = User.authenticate(user)
     return self.user is not False
Пример #25
0
 def testExists(self):
     self.assertTrue(User.exists(1))
Пример #26
0
 def testFindByName(self):
     name = 'john'
     obj = User.findByName(name)
     self.assertTrue(obj.name == name)
Пример #27
0
from boardhood.helpers.response import json
from boardhood.helpers.image import resize
from boardhood.helpers.pagination import paginate
from boardhood.helpers.auth import require_user_auth
from boardhood.models.applications import Application, require_app_auth
from boardhood.models.users import User
from boardhood.models.interests import Interest
from boardhood.models.conversations import Conversation
from boardhood.models.base import ValidationException, UniqueViolationException
from boardhood.forms import (UserCreateForm, UserUpdateForm, UserListForm,
                             UserNameListForm, UserShowForm,
                             InterestSearchForm, UserActivityForm)

module = Blueprint('users', __name__)
User.register_app(module, app)
Interest.register_app(module, app)
Conversation.register_app(module, app)


# POST /users  -----------------------------------------------------------------
@module.route('/users', methods=['POST'])
@require_app_auth(app, Application.LEVEL_ALL)
def create():
    form = UserCreateForm(request)
    if not form.validate():
        return json({
            'message': 'Validation Failed',
            'errors': form.errors
        }, 422)
Пример #28
0
 def testAuthenticate(self):
     user = User(name='john', password='******')
     auth = User.authenticate(user)
     if auth is False:
         self.fail("User is not authenticated")
Пример #29
0
 def testFindByName(self):
     name = 'john'
     obj = User.findByName(name)
     self.assertTrue(obj.name == name)
Пример #30
0
 def emailExists(self):
     self.assertTrue(User.emailExists('*****@*****.**'))
     self.assertFalse(User.emailExists('*****@*****.**'))
Пример #31
0
 def testNameExists(self):
     self.assertTrue(User.nameExists('john'))
     self.assertFalse(User.nameExists('dasdasdjskow3'))