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


Python User.save_pwd方法代码示例

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


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

示例1: step_4_pre

# 需要导入模块: from core.models import User [as 别名]
# 或者: from core.models.User import save_pwd [as 别名]
def step_4_pre():

    if get_ini('main', 'DO_DB_CHECK') is None:
        store_ini('main', 'DO_DB_CHECK', 'Y')
        from core.utils import reboot
        reboot()

    report = []

    from core.models import db, Template
    try:
        db.connect()
    except:
        raise

    db.close()

    report.append("Database connection successful.")

    from settings import DB
    DB.recreate_database()

    report.append("Database tables created successfully.")

    username = "Administrator"
    email = get_ini("user", "email")
    password = get_ini("user", "password")
    blog_path = get_ini("install", "blog_path")

    from core.utils import encrypt_password
    p_key = get_ini('key', 'PASSWORD_KEY')
    password = encrypt_password(password, p_key)

    db.connect()

    with db.atomic():

        from core.models import Site
        new_site = Site.create(
            name="Your first site",
            description="The description for your first site.",
            url=get_ini('main', 'base_url_root'),
            path=blog_path)

        report.append("Initial site created successfully.")

        from core.models import User
        new_user = User(
            name='Administrator',
            email=email,
            encrypted_password=password)

        new_user.save_pwd()

        from core.auth import role

        new_user_permissions = new_user.add_permission(
            permission=role.SYS_ADMIN,
            site=new_site
            )

        new_user_permissions.save()

        report.append("Initial admin user created successfully.")

        plugindir = _join((_s.APPLICATION_PATH, 'data', 'plugins'))

        import shutil

        # TODO: warn on doing this?
        # this should only happen with a totally fresh install, not an upgrade

        install_directory = _join((_s.APPLICATION_PATH, _s.INSTALL_SRC_PATH))

        if (os.path.isdir(plugindir)):
            shutil.rmtree(plugindir)

        shutil.copytree(_join((install_directory, 'plugins')),
            plugindir)

        report.append("Default plugins copied successfully to data directory.")

        themedir = _join((_s.APPLICATION_PATH, 'data', 'themes'))

        if (os.path.isdir(themedir)):
            shutil.rmtree(themedir)

        shutil.copytree(_join((install_directory, 'themes')),
            themedir)

        report.append("Default themes copied successfully to data directory.")

        from core import plugins

        for x in os.listdir(plugindir):
            if (os.path.isdir(_join((plugindir, x))) is True and
                x != '__pycache__'):
                new_plugin = plugins.register_plugin(x, enable=True)
                report.append("New plugin '{}' installed successfully.".format(
                    new_plugin.name))
#.........这里部分代码省略.........
开发者ID:syegulalp,项目名称:mercury,代码行数:103,代码来源:install.py

示例2: system_new_user

# 需要导入模块: from core.models import User [as 别名]
# 或者: from core.models.User import save_pwd [as 别名]
def system_new_user():

    from core.models import db

    user = auth.is_logged_in(request)
    permission = auth.is_sys_admin(user)

    nav_tabs = None
    status = None

    from core.models import User

    if request.method == 'POST':

        new_name = request.forms.getunicode('user_name')
        new_email = request.forms.getunicode('user_email')
        new_password = request.forms.getunicode('user_password')
        new_password_confirm = request.forms.getunicode('user_password_confirm')

        from core.error import UserCreationError

        from core.libs import peewee

        # TODO: make this into a confirmation function a la what we did with blog settings

        new_user = User(
            name=new_name,
            email=new_email,
            password=new_password,
            password_confirm=new_password_confirm)

        try:
            new_user.save_pwd()

        except UserCreationError as e:
            status = utils.Status(
                type='danger',
                no_sure=True,
                message='There were problems creating the new user:',
                message_list=e.args[0]
                )
        # TODO: replace with integrity error utility
        except peewee.IntegrityError as e:
            status = utils.Status(
                type='danger',
                no_sure=True,
                message='There were problems creating the new user:',
                message_list=['The new user\'s email or username is the same as another user\'s. Emails and usernames must be unique.']
                )


        except Exception as e:
            raise e
        else:
            db.commit()
            from settings import BASE_URL
            return redirect(BASE_URL + '/system/user/{}'.format(new_user.id))

    else:
        new_user = User(name='',
            email='',
            password='')

    tags = template_tags(user=user)
    tags.status = status

    tpl = template('edit/user_settings',
        edit_user=new_user,
        menu=generate_menu('system_create_user', new_user),
        search_context=(search_contexts['sites'], None),
        nav_tabs=nav_tabs,
        nav_default='basic',
        **tags.__dict__
        )

    return tpl
开发者ID:syegulalp,项目名称:mercury,代码行数:78,代码来源:user.py


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