예제 #1
0
def init_instances():
    with transaction.manager:
        admins_group = Group(
            id=ADMINS_GROUP, description='Group of administrators')
        unlimited_limit = UserLimit(
            id='unlimited', collections_limit=1000000, samples_limit=1000000,
            templates_limit=1000000, storage_limit=50000 * 1000000)
        commercial_limit = UserLimit(
            id='commercial', collections_limit=1000, samples_limit=10000,
            templates_limit=10, storage_limit=10000 * 1000000)
        academic_limit = UserLimit(
            id='academic', collections_limit=10, samples_limit=250,
            templates_limit=5, storage_limit=100 * 1000000,
            email_pattern=r'.*\.(edu|ac\.[a-z][a-z])$')
        free_limit = UserLimit(
            id='free', collections_limit=3, samples_limit=50,
            templates_limit=2, storage_limit=1 * 1000000)
        admin_user = User(
            salutation='', given_name='Administrator', surname='',
            limits_id='unlimited')
        admin_email = EmailAddress(
            email='*****@*****.**', verified=datetime.utcnow())
        admin_collection = Collection(name='Default', owner='Administrator')
        owner_role = Role(
            id=OWNER_ROLE,
            description='Owner and administrator of the collection')
        editor_role = Role(
            id=EDITOR_ROLE,
            description='Can add and remove samples from a collection, but '
                        'cannot administer members of the collection')
        auditor_role = Role(
            id=AUDITOR_ROLE,
            description='Can audit samples within the collection but cannot '
                        'manipulate the collection')
        viewer_role = Role(
            id=VIEWER_ROLE,
            description='Can view samples within the collection but cannot '
                        'manipulate the collection')
        DBSession.add(admins_group)
        DBSession.add(unlimited_limit)
        DBSession.add(commercial_limit)
        DBSession.add(academic_limit)
        DBSession.add(free_limit)
        DBSession.add(admin_user)
        DBSession.add(admin_email)
        DBSession.add(admin_collection)
        DBSession.add(owner_role)
        DBSession.add(editor_role)
        DBSession.add(auditor_role)
        DBSession.add(viewer_role)
        admins_group.users.append(admin_user)
        admin_user.emails.append(admin_email)
        admin_user.password = '******'
        admin_user.collections[admin_collection] = owner_role
예제 #2
0
def authenticate(email_address, password):
    "Authenticates the user with the specified email address and password"
    # Need a transaction as User.authenticate can potentially write to the
    # database in the event of hash transitions
    with transaction.manager:
        user = User.by_email(email_address)
        if user is not None:
            return user.authenticate(password)
        else:
            return False
예제 #3
0
def authenticate(email_address, password):
    "Authenticates the user with the specified email address and password"
    # Need a transaction as User.authenticate can potentially write to the
    # database in the event of hash transitions
    with transaction.manager:
        user = User.by_email(email_address)
        if user is not None:
            return user.authenticate(password)
        else:
            return False
예제 #4
0
 def create(self):
     # TODO Determine user timezone as default
     form = Form(self.request, schema=AccountCreateSchema)
     if form.validate():
         new_user = form.bind(User())
         DBSession.add(new_user)
         new_email = form.bind(EmailAddress())
         new_email.user = new_user
         DBSession.add(new_email)
         new_collection = Collection()
         new_collection.name = 'Default'
         new_collection.owner = new_user.full_name
         owner_role = DBSession.query(Role).filter(Role.id == 'owner').one()
         new_user.collections[new_collection] = owner_role
         return HTTPFound(location=self.request.route_url(
             'account_verify_email', _query=dict(email=form.data['email'])))
     return dict(form=FormRenderer(form))
예제 #5
0
def init_instances():
    with transaction.manager:
        admins_group = Group(id=ADMINS_GROUP,
                             description='Group of administrators')
        unlimited_limit = UserLimit(id='unlimited',
                                    collections_limit=1000000,
                                    samples_limit=1000000,
                                    templates_limit=1000000,
                                    storage_limit=50000 * 1000000)
        commercial_limit = UserLimit(id='commercial',
                                     collections_limit=1000,
                                     samples_limit=10000,
                                     templates_limit=10,
                                     storage_limit=10000 * 1000000)
        academic_limit = UserLimit(id='academic',
                                   collections_limit=10,
                                   samples_limit=250,
                                   templates_limit=5,
                                   storage_limit=100 * 1000000,
                                   email_pattern=r'.*\.(edu|ac\.[a-z][a-z])$')
        free_limit = UserLimit(id='free',
                               collections_limit=3,
                               samples_limit=50,
                               templates_limit=2,
                               storage_limit=1 * 1000000)
        admin_user = User(salutation='',
                          given_name='Administrator',
                          surname='',
                          limits_id='unlimited')
        admin_email = EmailAddress(email='*****@*****.**',
                                   verified=datetime.utcnow())
        admin_collection = Collection(name='Default', owner='Administrator')
        owner_role = Role(
            id=OWNER_ROLE,
            description='Owner and administrator of the collection')
        editor_role = Role(
            id=EDITOR_ROLE,
            description='Can add and remove samples from a collection, but '
            'cannot administer members of the collection')
        auditor_role = Role(
            id=AUDITOR_ROLE,
            description='Can audit samples within the collection but cannot '
            'manipulate the collection')
        viewer_role = Role(
            id=VIEWER_ROLE,
            description='Can view samples within the collection but cannot '
            'manipulate the collection')
        DBSession.add(admins_group)
        DBSession.add(unlimited_limit)
        DBSession.add(commercial_limit)
        DBSession.add(academic_limit)
        DBSession.add(free_limit)
        DBSession.add(admin_user)
        DBSession.add(admin_email)
        DBSession.add(admin_collection)
        DBSession.add(owner_role)
        DBSession.add(editor_role)
        DBSession.add(auditor_role)
        DBSession.add(viewer_role)
        admins_group.users.append(admin_user)
        admin_user.emails.append(admin_email)
        admin_user.password = '******'
        admin_user.collections[admin_collection] = owner_role
예제 #6
0
def get_user(request):
    "Returns the User object based on a request's unauth'ed user"
    email_address = unauthenticated_userid(request)
    if email_address is not None:
        return User.by_email(email_address)
예제 #7
0
 def _to_python(self, value, state):
     result = User.by_email(value)
     if result is None:
         raise Invalid('No users have address %s' % value, value, state)
     return result
예제 #8
0
def get_user(request):
    "Returns the User object based on a request's unauth'ed user"
    email_address = unauthenticated_userid(request)
    if email_address is not None:
        return User.by_email(email_address)