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


Python models.User类代码示例

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


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

示例1: setUp

    def setUp(self):
        self.app = create_app('TESTING_CONFIG')
        self.app_context = self.app.app_context()
        self.app_context.push()
        self.client = self.app.test_client()
        self.basedir = os.path.abspath(os.path.dirname(__file__))
        db.create_all()
        test_password = 'test'
        Organization.insert_org()
        UserScope.insert_scopes()
        User.insert_user(password=test_password)

        self.client = self.app.test_client(use_cookies=False)

        # set the vars for the connection
        self.cmisUrl =  \
            'https://alfresco.oceanobservatories.org/alfresco/s/api/cmis'
        self.cmisUsername = 'ooinet'
        self.cmisPassword = '75commonLIKEbrown76'
        self.cmisId = 'c161bc66-4f7e-4a4f-b5f2-aac9fbf1d3cd'

        # cmis is tested elsewhere

        from cmislib.model import CmisClient
        client = CmisClient(self.cmisUrl, self.cmisUsername, self.cmisPassword)
        repo = client.getRepository(self.cmisId)
开发者ID:Bobfrat,项目名称:ooi-ui-services,代码行数:26,代码来源:test_alfresco.py

示例2: setUp

    def setUp(self):
        self.app = create_app('TESTING_CONFIG')
        self.app_context = self.app.app_context()
        self.app_context.push()
        from sqlalchemy.orm.mapper import configure_mappers
        configure_mappers()
        db.create_all()

        test_username = 'admin'
        test_password = 'test'
        Organization.insert_org()
        User.insert_user(username=test_username, password=test_password, email='[email protected]')


        OperatorEventType.insert_operator_event_types()

        self.client = self.app.test_client(use_cookies=False)

        UserScope.insert_scopes()

        admin = User.query.filter_by(user_name='admin').first()
        scope = UserScope.query.filter_by(scope_name='asset_manager').first()
        admin.scopes.append(scope)

        db.session.add(admin)
        db.session.commit()

        joe = User.insert_user(username='joe', password='joe', email='[email protected]')
        bob = User.insert_user(username='bob', password='bob', email='[email protected]')
开发者ID:Bobfrat,项目名称:ooi-ui-services,代码行数:29,代码来源:test_log_entries.py

示例3: setUp

 def setUp(self):
     self.app = create_app('TESTING_CONFIG')
     self.app_context = self.app.app_context()
     self.app_context.push()
     db.create_all()
     self.client = self.app.test_client(use_cookies=False)
     Organization.insert_org()
     User.insert_user(username=test_username, password=test_password)
     UserScope.insert_scopes()
开发者ID:Bobfrat,项目名称:ooi-ui-services,代码行数:9,代码来源:test_sys.py

示例4: setUp

    def setUp(self):
        self.app = create_app("TESTING_CONFIG")
        self.app_context = self.app.app_context()
        self.app_context.push()
        db.create_all()
        test_password = "test"
        Organization.insert_org()
        User.insert_user(password=test_password, email="[email protected]")

        self.client = self.app.test_client(use_cookies=False)
开发者ID:asascience-open,项目名称:ooi-ui-services,代码行数:10,代码来源:test_user.py

示例5: add_admin_user

def add_admin_user(username, password, first_name, last_name, email, org_name):
    '''
    Creates a 'user_admin' scoped user using the supplied username and password
    :param username:
    :param password:
    :return:
    '''
    app.logger.info('Insert user_name: %s' % username)
    User.insert_user(username=username, password=password, first_name=first_name, last_name=last_name, email=email, org_name=org_name)
    admin = User.query.filter_by(user_name=username).first()
    admin.scopes.append(UserScope.query.filter_by(scope_name='user_admin').first())
    admin.scopes.append(UserScope.query.filter_by(scope_name='redmine').first())
    db.session.add(admin)
    db.session.commit()
开发者ID:RyanMaciel,项目名称:ooi-ui-services,代码行数:14,代码来源:manage.py

示例6: test_user

 def test_user(self):
     #Test the json in the object
     user = User()
     self.assertEquals(user.to_json(), {
         'email': None,
         'id': None,
         'user_id': None,
         'active':None,
         'first_name': None,
         'last_name' : None,
         'organization_id' : None,
         'phone_alternate' : None,
         'phone_primary' : None,
         'scopes' : [],
         'role' : None,
         'user_name': None})
开发者ID:birdage,项目名称:ooi-ui-services,代码行数:16,代码来源:test_models.py

示例7: oauth_callback

def oauth_callback(provider):
    # rand_pass will be a new password every time a user logs in
    # with oauth.
    temp_pass = str(uuid.uuid4())

    # lets create the oauth object that will issue the request.
    oauth = OAuthSignIn.get_provider(provider)

    # assign the response
    email, first_name, last_name = oauth.callback()

    if email is None:
        return unauthorized('Invalid credentials')

    # see if this user already exists, and
    # and give the user a brand new password.
    user = User.query.filter_by(email=email).first()
    if user:
        user.password = temp_pass

    # if there is no user, create a new one and setup
    # it's defaults and give it a new password.
    else:
        user = User.insert_user(password=temp_pass,
                         username=email,
                         email=email,
                         first_name=first_name,
                         last_name=last_name)

    return jsonify({'uuid': temp_pass, 'username': email})
开发者ID:petercable,项目名称:ooi-ui-services,代码行数:30,代码来源:authentication.py

示例8: setUp

    def setUp(self):
        self.app = create_app('TESTING_CONFIG')
        self.app_context = self.app.app_context()
        self.app_context.push()
        db.create_all()
        test_username = 'admin'
        test_password = 'test'
        Organization.insert_org()
        User.insert_user(username=test_username, password=test_password)

        self.client = self.app.test_client(use_cookies=False)
        UserScope.insert_scopes()
        admin = User.query.filter_by(user_name='admin').first()
        scope = UserScope.query.filter_by(scope_name='user_admin').first()
        admin.scopes.append(scope)
        db.session.add(admin)
        db.session.commit()
开发者ID:birdage,项目名称:ooi-ui-services,代码行数:17,代码来源:test_instrument_deployments.py

示例9: create_user

def create_user():
    """
    Requires either a CSRF token shared between the UI and the Services OR an
    authenticated request from a valid user.
    """
    csrf_token = request.headers.get("X-Csrf-Token")
    if not csrf_token or csrf_token != current_app.config["UI_API_KEY"]:
        auth = False
        if request.authorization:
            auth = verify_auth(request.authorization["username"], request.authorization["password"])
        if not auth:
            return jsonify(error="Invalid Authentication"), 401
    data = json.loads(request.data)
    # add user to db
    role_mapping = {
        1: ["annotate", "asset_manager", "user_admin", "redmine"],  # Administrator
        2: ["annotate", "asset_manager"],  # Marine Operator
        3: [],  # Science User
    }
    role_scopes = role_mapping[data["role_id"]]
    valid_scopes = UserScope.query.filter(UserScope.scope_name.in_(role_scopes)).all()

    try:
        new_user = User.from_json(data)
        new_user.scopes = valid_scopes
        new_user.active = True
        db.session.add(new_user)
        db.session.commit()
    except Exception as e:
        return jsonify(error=e.message), 409

    try:
        redmine = redmine_login()
        organization = new_user.organization.organization_name
        tmp = dt.datetime.now() + dt.timedelta(days=1)
        due_date = dt.datetime.strftime(tmp, "%Y-%m-%d")
        issue = redmine.issue.new()
        issue.project_id = current_app.config["REDMINE_PROJECT_ID"]
        issue.subject = "New User Registration for OOI UI: %s, %s" % (new_user.first_name, new_user.last_name)
        issue.description = (
            "A new user has requested access to the OOI User Interface. Please review the application for %s, their role in the organization %s is %s and email address is %s"
            % (new_user.first_name, organization, new_user.role, new_user.email)
        )
        issue.priority_id = 1
        issue.due_date = due_date
        # Get the list of ticker Trackers
        trackers = list(redmine.tracker.all())
        # Find the REDMINE_TRACKER (like 'Support') and get the id
        # This make a difference for field validation and proper tracker assignment
        config_redmine_tracker = current_app.config["REDMINE_TRACKER"]
        tracker_id = [tracker.id for tracker in trackers if tracker.name == config_redmine_tracker][0]
        issue.tracker_id = tracker_id
        issue.save()
    except Exception as e:
        current_app.logger.exception("Failed to generate redmine issue for new user")
        return jsonify(error=e.message), 409

    return jsonify(new_user.to_json()), 201
开发者ID:asascience-open,项目名称:ooi-ui-services,代码行数:58,代码来源:user.py

示例10: setUp

    def setUp(self):
        self.app = create_app('TESTING_CONFIG')
        self.app_context = self.app.app_context()
        self.app_context.push()
        db.create_all()
        test_password = 'test'
        Organization.insert_org()
        UserScope.insert_scopes()
        User.insert_user(password=test_password)

        self.client = self.app.test_client(use_cookies=False)
        self.basedir = os.path.abspath(os.path.dirname(__file__))
        with open(self.basedir + '/mock_data/event_post.json', 'r') as f:
            doc = json.load(f)
        self.event_json_in = doc

        with open(self.basedir + '/mock_results/event_from.json', 'r') as f:
            doc = json.load(f)
        self.event_from_json = doc
开发者ID:birdage,项目名称:ooi-ui-services,代码行数:19,代码来源:test_assetController.py

示例11: logged_in

def logged_in():
    '''
    Checks the TOKEN not the user identity to see if it's current and valid.
    '''
    auth = request.authorization
    if not auth:
        return jsonify(valid=False)
    token, password = auth.username, auth.password
    if token and not password:
        user = User.verify_auth_token(token)
        return jsonify(valid=(user is not None))
    return jsonify(valid=False)
开发者ID:petercable,项目名称:ooi-ui-services,代码行数:12,代码来源:authentication.py

示例12: test_user

 def test_user(self):
     # Test the json in the object
     user = User()
     self.assertEquals(
         user.to_json(),
         {
             "email": None,
             "id": None,
             "user_id": None,
             "active": None,
             "first_name": None,
             "last_name": None,
             "organization_id": None,
             "phone_alternate": None,
             "phone_primary": None,
             "scopes": [],
             "role": None,
             "user_name": None,
             "email_opt_in": None,
         },
     )
开发者ID:RyanMaciel,项目名称:ooi-ui-services,代码行数:21,代码来源:test_models.py

示例13: setUp

    def setUp(self):
        self.app = create_app("TESTING_CONFIG")
        self.app_context = self.app.app_context()
        self.app_context.push()
        db.create_all()
        test_username = "admin"
        test_password = "test"
        Organization.insert_org()

        User.insert_user(username=test_username, password=test_password)

        self.client = self.app.test_client(use_cookies=False)
        UserScope.insert_scopes()
        admin = User.query.filter_by(user_name="admin").first()
        scope = UserScope.query.filter_by(scope_name="user_admin").first()
        cc_scope = UserScope.query.filter_by(scope_name="command_control").first()
        admin.scopes.append(scope)
        admin.scopes.append(cc_scope)
        db.session.add(admin)
        db.session.commit()

        self.headers = self.get_api_headers("admin", "test")
开发者ID:asascience-open,项目名称:ooi-ui-services,代码行数:22,代码来源:test_c2_missions.py

示例14: verify_auth

def verify_auth(email_or_token, password):
    if email_or_token == '':
        return True
    if password == '':
        g.current_user = User.verify_auth_token(email_or_token)
        g.token_used = True
        return g.current_user is not None
    user = User.query.filter(User.user_name==email_or_token, User.active==True).first()
    if not user:
        return False
    g.current_user = user
    g.token_used = False
    return user.verify_password(password)
开发者ID:RyanMaciel,项目名称:ooi-ui-services,代码行数:13,代码来源:authentication.py

示例15: deploy

def deploy(password, bulkload):
    from flask.ext.migrate import upgrade
    from ooiservices.app.models import User, UserScope, UserScopeLink, Array, Organization
    from ooiservices.app.models import PlatformDeployment, InstrumentDeployment, Stream, StreamParameterLink
    from sh import psql
    #Create the local database
    app.logger.info('Creating DEV and TEST Databases')
    psql('-c', 'create database ooiuidev;', '-U', 'postgres')
    psql('ooiuidev', '-c', 'create schema ooiui')
    psql('ooiuidev', '-c', 'create extension postgis')
    #Create the local test database
    psql('-c', 'create database ooiuitest;', '-U', 'postgres')
    psql('ooiuitest', '-c', 'create schema ooiui')
    psql('ooiuitest', '-c', 'create extension postgis')
    from sqlalchemy.orm.mapper import configure_mappers
    configure_mappers()
    db.create_all()
    if bulkload:
        with open('db/ooiui_schema_data.sql') as f:
            psql('ooiuidev', _in=f)
        app.logger.info('Bulk test data loaded.')

    # migrate database to latest revision
    #upgrade()
    if not os.getenv('TRAVIS'):
        Organization.insert_org()
        UserScope.insert_scopes()
        app.logger.info('Insert default user, name: admin')
        User.insert_user(password=password)
        admin = User.query.first()
        admin.scopes.append(UserScope.query.filter_by(scope_name='user_admin').first())
        admin.scopes.append(UserScope.query.filter_by(scope_name='redmine').first())
        db.session.add(admin)
        db.session.commit()
        if bulkload:
            with open('db/ooiui_schema_data_notifications.sql') as f:
                psql('ooiuidev', _in=f)
            app.logger.info('Bulk test data loaded for notifications.')
开发者ID:RyanMaciel,项目名称:ooi-ui-services,代码行数:38,代码来源:manage.py


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