Ejemplo n.º 1
0
 def setUp(self):
     self.config = testing.setUp()
     import webtest
     from pyramid import  paster
     from sqlalchemy import create_engine
     engine = create_engine('sqlite://')
     myapp = paster.get_app('testing.ini')
     self.app = webtest.TestApp(myapp)
     from lingvodoc.models import (
         Base,
         Locale,
         User,
         Passhash,
         Client
         )
     DBSession.configure(bind=engine)
     Base.metadata.create_all(engine)
     with transaction.manager:
         ru_locale = Locale(id=1, shortcut="ru", intl_name="Русский")
         DBSession.add(ru_locale)
         en_locale = Locale(id=2, shortcut="en", intl_name="English")
         DBSession.add(en_locale)
         DBSession.flush()
         new_user = User(id=1, login='******', default_locale_id = 1)
         new_pass = Passhash(password='******')
         DBSession.add(new_pass)
         new_user.password = new_pass
         DBSession.add(new_user)
         new_client = Client(id=1, user=new_user)
         DBSession.add(new_client)
Ejemplo n.º 2
0
def signup_post(request):  # tested
    try:
        req = request.json_body
        login = req['login']
        name = req['name']
        email = req['email']
        password = req['password']

        day = req.get('day')
        month = req.get('month')
        year = req.get('year')
        if day is None or month is None or year is None:
            request.response.status = HTTPBadRequest.code
            return {'Error': "day, month or year of the birth is missing"}
        # birthday = datetime.datetime.strptime(day + month + year, "%d%m%Y").date()
        try:
            birthday = datetime.date(year, month, day)
        except ValueError:
            request.response.status = HTTPBadRequest.code
            return {'Error': "Invalid birthday"}

        if DBSession.query(User).filter_by(login=login).first():
            raise CommonException("The user with this login is already registered")
        if DBSession.query(Email).filter_by(email=email).first():
            raise CommonException("The user with this email is already registered")
        new_user = User(login=login, name=name, signup_date=datetime.datetime.utcnow(), intl_name=login, birthday=birthday, is_active=True)
        pwd = Passhash(password=password)
        email = Email(email=email)
        new_user.password = pwd
        new_user.email.append(email)
        DBSession.add(new_user)
        basegroups = []
        basegroups += [DBSession.query(BaseGroup).filter_by(name="Can create dictionaries").first()]
        basegroups += [DBSession.query(BaseGroup).filter_by(name="Can create languages").first()]
        basegroups += [DBSession.query(BaseGroup).filter_by(name="Can create organizations").first()]
        basegroups += [DBSession.query(BaseGroup).filter_by(name="Can create translation strings").first()]
        groups = []
        for base in basegroups:
            groups += [DBSession.query(Group).filter_by(subject_override=True, base_group_id=base.id).first()]
        for group in groups:
            if group not in new_user.groups:
                new_user.groups.append(group)
        DBSession.flush()
        return {}

    except KeyError as e:
        request.response.status = HTTPBadRequest.code
        return {'status': request.response.status, 'error': str(e)}

    except CommonException as e:
        request.response.status = HTTPConflict.code
        return {'status': request.response.status, 'error': str(e)}

    except ValueError as e:
        request.response.status = HTTPConflict.code
        return {'status': request.response.status, 'error': str(e)}
Ejemplo n.º 3
0
 def setUp(self):
     self.config = testing.setUp()
     import webtest
     from pyramid import paster
     from sqlalchemy import create_engine
     engine = create_engine('sqlite://')
     myapp = paster.get_app('testing.ini')
     self.app = webtest.TestApp(myapp)
     from lingvodoc.models import (Base, Language, Locale,
                                   UserEntitiesTranslationString, User,
                                   Passhash, Client)
     DBSession.configure(bind=engine)
     Base.metadata.create_all(engine)
     with transaction.manager:
         ru_locale = Locale(id=1, shortcut="ru", intl_name="Русский")
         DBSession.add(ru_locale)
         en_locale = Locale(id=2, shortcut="en", intl_name="English")
         DBSession.add(en_locale)
         DBSession.flush()
         new_user = User(id=1, login='******', default_locale_id=1)
         new_pass = Passhash(password='******')
         DBSession.add(new_pass)
         new_user.password = new_pass
         DBSession.add(new_user)
         new_client = Client(id=1, user=new_user)
         DBSession.add(new_client)
         DBSession.flush()
         new_uets = UserEntitiesTranslationString(object_id=1,
                                                  client_id=1,
                                                  locale_id=1,
                                                  translation_string='test',
                                                  translation='not working')
         DBSession.add(new_uets)
         new_lang = Language(client_id=1,
                             object_id=1,
                             translation_string='test')
         DBSession.add(new_lang)
         new_lang = Language(client_id=1,
                             object_id=2,
                             translation_string='testy')
         DBSession.add(new_lang)
Ejemplo n.º 4
0
 def setUp(self):
     self.config = testing.setUp()
     self.config.testing_securitypolicy(userid='1',
                                        permissive=True)
     import webtest
     from pyramid import  paster
     from sqlalchemy import create_engine
     engine = create_engine('sqlite://')
     myapp = paster.get_app('testing.ini')
     self.app = webtest.TestApp(myapp)
     from lingvodoc.models import (
         Base,
         User,
         Client,
         Passhash,
         Locale,
         UserEntitiesTranslationString,
         Language
         )
     DBSession.configure(bind=engine)
     Base.metadata.create_all(engine)
     with transaction.manager:
         ru_locale = Locale(id=1, shortcut="ru", intl_name="Русский")
         DBSession.add(ru_locale)
         en_locale = Locale(id=2, shortcut="en", intl_name="English")
         DBSession.add(en_locale)
         DBSession.flush()
         new_user = User(id=1, login='******', default_locale_id = 1)
         new_pass = Passhash(password='******')
         DBSession.add(new_pass)
         new_user.password = new_pass
         DBSession.add(new_user)
         new_client = Client(id=1, user=new_user)
         DBSession.add(new_client)
         new_uets= UserEntitiesTranslationString(client_id = 1, object_id = 1, locale_id=2,
                                                 translation_string = 'imastring')
         DBSession.add(new_uets)
         new_lang = Language(client_id=1, object_id=1, translation_string='testy')
         DBSession.add(new_lang)
Ejemplo n.º 5
0
 def setUp(self):
     self.config = testing.setUp()
     import webtest
     from pyramid import paster
     from sqlalchemy import create_engine
     engine = create_engine('sqlite://')
     myapp = paster.get_app('testing.ini')
     self.app = webtest.TestApp(myapp)
     from lingvodoc.models import (
         Base,
         Dictionary,
         Language,
         Organization,
         Locale,
         User,
         Passhash,
         Client,
         DictionaryPerspective,
         UserEntitiesTranslationString
         )
     DBSession.configure(bind=engine)
     Base.metadata.create_all(engine)
     with transaction.manager:
         ru_locale = Locale(id=1, shortcut="ru", intl_name="Русский")
         DBSession.add(ru_locale)
         en_locale = Locale(id=2, shortcut="en", intl_name="English")
         DBSession.add(en_locale)
         DBSession.flush()
         new_user = User(id=1, login='******', default_locale_id = 1)
         new_pass = Passhash(password='******')
         DBSession.add(new_pass)
         new_user.password = new_pass
         DBSession.add(new_user)
         new_client = Client(id=1, user=new_user)
         DBSession.add(new_client)
         new_user2 = User(id=2, login='******', default_locale_id = 1)
         new_pass2 = Passhash(password='******')
         DBSession.add(new_pass)
         new_user2.password = new_pass2
         DBSession.add(new_user2)
         new_client = Client(id=2, user=new_user2)
         DBSession.add(new_client)
         new_client = Client(id=3, user=new_user)
         DBSession.add(new_client)
         DBSession.flush()
         new_user3 = User(id=3, login='******', default_locale_id = 1)
         new_pass3 = Passhash(password='******')
         DBSession.add(new_pass3)
         new_user3.password = new_pass3
         DBSession.add(new_user3)
         new_client = Client(id=4, user=new_user3)
         DBSession.add(new_client)
         new_user4 = User(id=4, login='******', default_locale_id = 1)
         new_pass4 = Passhash(password='******')
         DBSession.add(new_pass4)
         new_user4.password = new_pass4
         DBSession.add(new_user4)
         new_client = Client(id=5, user=new_user4)
         DBSession.add(new_client)
         new_lang1 = Language(client_id=1, object_id=1, translation_string='head')
         DBSession.add(new_lang1)
         new_lang2 = Language(client_id=2, object_id=5, translation_string='left son', parent=new_lang1)
         DBSession.add(new_lang2)
         new_lang3 = Language(client_id=1, object_id=3, translation_string='right son', parent=new_lang1)
         DBSession.add(new_lang3)
         new_lang4 = Language(client_id=2, object_id=4, translation_string='first grand son', parent=new_lang3)
         DBSession.add(new_lang4)
         new_lang5 = Language(client_id=1, object_id=5, translation_string='second grand son', parent=new_lang3)
         DBSession.add(new_lang5)
         new_lang6 = Language(client_id=1, object_id=6, translation_string='third grand son', parent=new_lang3)
         DBSession.add(new_lang6)
         new_lang7 = Language(client_id=1, object_id=7, translation_string='grand grand son', parent=new_lang5)
         DBSession.add(new_lang7)
         new_lang8 = Language(client_id=1, object_id=8, translation_string='second head')
         DBSession.add(new_lang8)
         new_lang9 = Language(client_id=1, object_id=9, translation_string='second left son', parent=new_lang8)
         DBSession.add(new_lang9)
         new_lang10 = Language(client_id=1, object_id=10, translation_string='second right son', parent=new_lang8)
         DBSession.add(new_lang10)
         new_org1 = Organization(name='first')
         new_org1.users.append(new_user)
         new_org1.users.append(new_user3)
         DBSession.add(new_org1)
         new_org2 = Organization(name='second')
         DBSession.add(new_org2)
         new_dict = Dictionary(client_id=1, object_id=1, name='dict')
         DBSession.add(new_dict)
         DBSession.flush()
         new_persp1 = DictionaryPerspective(client_id=1, object_id=1, name='persp', parent=new_dict)
         DBSession.add(new_persp1)
         new_persp2 = DictionaryPerspective(client_id=2, object_id=2, name='persp', parent=new_dict)
         DBSession.add(new_persp2)
         uets = UserEntitiesTranslationString(locale_id=1, translation_string='persp', translation='персп')
Ejemplo n.º 6
0
def signup_post(request):  # tested
    try:
        req = request.json_body
        login = req['login']
        name = req['name']
        email = req['email']
        password = req['password']

        day = req.get('day')
        month = req.get('month')
        year = req.get('year')
        if day is None or month is None or year is None:
            request.response.status = HTTPBadRequest.code
            return {'Error': "day, month or year of the birth is missing"}
        # birthday = datetime.datetime.strptime(day + month + year, "%d%m%Y").date()
        try:
            day = int(day)
            month = int(month)
            year = int(year)
            birthday = datetime.date(year, month, day)
        except ValueError:
            request.response.status = HTTPBadRequest.code
            return {'Error': "Invalid birthday"}

        if DBSession.query(User).filter_by(login=login).first():
            raise CommonException(
                "The user with this login is already registered")
        if DBSession.query(Email).filter_by(email=email).first():
            raise CommonException(
                "The user with this email is already registered")
        new_user = User(login=login,
                        name=name,
                        created_at=datetime.datetime.utcnow(),
                        intl_name=login,
                        birthday=birthday,
                        is_active=True)
        pwd = Passhash(password=password)
        email = Email(email=email)
        new_user.password = pwd
        new_user.email = email
        DBSession.add(new_user)
        basegroups = []
        basegroups += [
            DBSession.query(BaseGroup).filter_by(
                name="Can create dictionaries").first()
        ]
        basegroups += [
            DBSession.query(BaseGroup).filter_by(
                name="Can create languages").first()
        ]
        basegroups += [
            DBSession.query(BaseGroup).filter_by(
                name="Can create organizations").first()
        ]
        basegroups += [
            DBSession.query(BaseGroup).filter_by(
                name="Can create translation strings").first()
        ]
        groups = []
        for base in basegroups:
            groups += [
                DBSession.query(Group).filter_by(
                    subject_override=True, base_group_id=base.id).first()
            ]
        for group in groups:
            add_user_to_group(new_user, group)
        DBSession.flush()
        return {}

    except KeyError as e:
        request.response.status = HTTPBadRequest.code
        return {'status': request.response.status, 'error': str(e)}

    except CommonException as e:
        request.response.status = HTTPConflict.code
        return {'status': request.response.status, 'error': str(e)}

    except ValueError as e:
        request.response.status = HTTPConflict.code
        return {'status': request.response.status, 'error': str(e)}