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


Python User.pass_hash方法代码示例

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


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

示例1: rebuild_schema

# 需要导入模块: from ooiservices.app.models import User [as 别名]
# 或者: from ooiservices.app.models.User import pass_hash [as 别名]
def rebuild_schema(schema, schema_owner, save_users, admin_username, admin_password, first_name, last_name, email, org_name):
    """
    Creates the OOI UI Services schema based on models.py
    :usage: python manage.py rebuild_schema --schema ooiui --schema_owner postgres --save_users False --admin_username admin --admin_password password --first_name Default --last_name Admin --email [email protected] --org_name Rutgers
    :param schema:
    :param schema_owner:
    :return:
    """
    # Check if schema exists
    timestamp = int((datetime.utcnow() - datetime(1970, 1, 1)).total_seconds())
    sql = "SELECT schema_name FROM information_schema.schemata WHERE schema_name = '{0}'".format(schema)
    sql_result = db.engine.execute(sql).first()
    if sql_result != None:
        # Move current schema to _timestamp
        app.logger.info('Backing up schema container {0} to {0}_{1}'.format(schema, timestamp))
        db.engine.execute('ALTER SCHEMA {0} RENAME TO {0}_{1}'.format(schema, timestamp))

    app.logger.info('Creating schema container: {0}'.format(schema))
    db.engine.execute('CREATE SCHEMA IF NOT EXISTS {0} AUTHORIZATION {1}'.format(schema, schema_owner))

    app.logger.info('Building schema objects')
    db.create_all()

    app.logger.info('Adding base user_scopes')
    UserScope.insert_scopes()

    app.logger.info('Loading default data into database')
    load_data('ooiui_schema_data.sql')
    db.session.commit()

    if save_users == 'True':
        app.logger.info('Re-populating users from backup schema')
        users_sql = 'SELECT * FROM {0}_{1}.users'.format(schema, timestamp)
        sql_result = db.engine.execute(users_sql)
        fa = sql_result.fetchall()
        for sresult in fa:
            new_user = User()
            new_user.id = sresult.id
            new_user.user_id = sresult.user_id
            new_user.pass_hash = sresult.pass_hash
            new_user.email = sresult.email
            new_user.user_name = sresult.user_name
            new_user.active = sresult.active
            new_user.confirmed_at = sresult.confirmed_at
            new_user.first_name = sresult.first_name
            new_user.last_name = sresult.last_name
            new_user.phone_primary = sresult.phone_primary
            new_user.phone_alternate = sresult.phone_alternate
            new_user.role = sresult.role
            new_user.organization_id = sresult.organization_id
            db.session.add(new_user)
            db.engine.execute("SELECT nextval('ooiui.users_id_seq')")
            db.session.commit()

        user_scope_link_sql = 'SELECT * FROM {0}_{1}.user_scope_link'.format(schema, timestamp)
        sql_resultc = db.engine.execute(user_scope_link_sql)
        fac = sql_resultc.fetchall()
        for scresult in fac:
            new_user_scope_link = UserScopeLink()
            new_user_scope_link.id = scresult.id
            new_user_scope_link.user_id = scresult.user_id
            new_user_scope_link.scope_id = scresult.scope_id
            db.session.add(new_user_scope_link)
            db.engine.execute("SELECT nextval('ooiui.user_scope_link_id_seq')")
            db.session.commit()

        # db.engine.execute('INSERT INTO {0}.users SELECT * FROM {0}_{1}.users'.format(schema, timestamp))
        # db.engine.execute('INSERT INTO {0}.user_scope_link SELECT * FROM {0}_{1}.user_scope_link'.format(schema, timestamp))

    else:
        app.logger.info('Adding the default admin user')
        if admin_username is None:
            app.logger.info('Admin username set to: admin')
            admin_username = 'admin'
        if admin_password is None:
            app.logger.info('Admin password set to: password')
            admin_password = 'password'
        if first_name is None:
            app.logger.info('Admin first_name set to: Default')
            first_name = 'Default'
        if last_name is None:
            app.logger.info('Admin last_name set to: Admin')
            last_name = 'Admin'
        if email is None:
            app.logger.info('Admin email set to: [email protected]')
            email = '[email protected]'
        if org_name is None:
            app.logger.info('Admin org_name set to: Rutgers')
            org_name = 'Rutgers'
        add_admin_user(username=admin_username, password=admin_password, first_name=first_name, last_name=last_name, email=email, org_name=org_name)
    load_data(sql_file='ooiui_schema_data_notifications.sql')
    app.logger.info('Database reloaded successfully')
开发者ID:RyanMaciel,项目名称:ooi-ui-services,代码行数:94,代码来源:manage.py


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