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


Python User.is_admin方法代码示例

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


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

示例1: post

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import is_admin [as 别名]
    def post(self):
        form = forms.LoginForm(request.form)
        authorized = False
        error = ''

        username = form.username.data
        password = form.password.data

        if form.validate():
            authorized = ldap_auth.authenticate(username, password)
            if authorized:
                # authorized via LDAP, log in session.  If database is unaware of 
                # LDAP user create a new user with username of authenticated user
                user = User.get_user_by_username(crypto.encrypt(username))
                if not user:
                    user = User(username=crypto.encrypt(username), is_admin=ldap_auth.hasMembershipWithSession(username, authorized, "PayrollAdmin"), is_approver=ldap_auth.hasMembershipWithSession(username, authorized, "PayrollApprover")).save()
                else:
                    user.is_approver = ldap_auth.hasMembershipWithSession(username, authorized, "PayrollApprover")
                    user.is_admin = ldap_auth.hasMembershipWithSession(username, authorized, "PayrollAdmin")
                    user.save()

                # free up the LDAP resources, we are done with it
                ldap_auth.unauthenticate(authorized)
                
                flask_login.login_user(user, remember=False)
                return "success"
            else:
                print "[Username: ", username, " invalid login.]"

        return "Incorrect Username or Password"
开发者ID:benjholla,项目名称:NCDC2013,代码行数:32,代码来源:views.py

示例2: admin

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import is_admin [as 别名]
def admin(username, is_admin):
    try:
        user = User.objects.get(name=username)
    except User.DoesNotExist:
        user = User(name=username)
    user.is_admin = is_admin
    user.save()
开发者ID:ojii,项目名称:checklists.ojii.ch,代码行数:9,代码来源:utils.py

示例3: authenticate

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import is_admin [as 别名]
def authenticate():
    if not request.args.get('ticket'):
        return redirect(url_for("base.index"))

    ticket = request.args.get("ticket")
    r = requests.get(
        "%sserviceValidate?ticket=%s&service=%s" % (conf.CAS, ticket, conf.HOSTNAME + url_for('cas.authenticate')))

    if "authenticationFailure" in r.text:
        return redirect(url_for("base.index"))
    else:
        dom = parseString(r.text)
        username = dom.getElementsByTagName("cas:user")[0].firstChild.nodeValue
        session["username"] = username
        existing = User.query.get(username)
        if existing is None:
            user = User(username)
            if username == "alecalve":
                user.is_admin = 1
            db.session.add(user)
            db.session.commit()
            return redirect(url_for("collection.mine"))
        else:
            existing.last_login = datetime.datetime.now()

        db.session.commit()
        session["logged_in"] = True
        flash("Bienvenue !", "success")
        return redirect(url_for("base.index"))
开发者ID:alecalve,项目名称:troc-ecocup,代码行数:31,代码来源:cas.py

示例4: setUp

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import is_admin [as 别名]
 def setUp(self):
     db_session.query(User).delete()
     email = '[email protected]'
     password = '123456'
     u = User(email, password, u'firstname', u'lastname')
     u.is_admin = True
     db_session.add(u)
     db_session.commit()
开发者ID:hackrole,项目名称:daily-program,代码行数:10,代码来源:tests.py

示例5: make_superuser

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import is_admin [as 别名]
def make_superuser(email, password):
    from models import User
    from app import db
    u = User()
    u.email = email
    u.password = u.set_password(password=password)
    u.nickname = u'관리자'
    u.is_admin = True
    db.session.add(u)
    db.session.commit()
开发者ID:rwdxll,项目名称:flask_blog,代码行数:12,代码来源:init_database.py

示例6: join_process

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import is_admin [as 别名]
def join_process():
    if request.method == 'POST':
        new_user = User()
        new_user.email = request.form['user_email']
        new_user.nickname = request.form['user_nickname']
        new_user.set_password(request.form['user_password'])
        new_user.is_admin = False
        db.session.add(new_user)
        db.session.commit()
        return redirect(url_for('index'))
开发者ID:rwdxll,项目名称:flask_blog,代码行数:12,代码来源:controllers.py

示例7: register_user

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import is_admin [as 别名]
def register_user():
    if User.is_admin(g.user.username):
        form = RegisteredUserForm()
        if form.prev.data:
            return redirect(url_for('admin'))
        if form.validate_on_submit():
            role = Role.role_by_name(form.role.data).one()
            User.create(username=form.username.data, password=form.password.data, role_id=role.id)
            flash(u'Пользователь "%s" успешно зарегистрирован в системе.' % form.username.data)
        return render_template('users/register.html', form=form)
    else:
        return u'Вы не можете получить доступ к этой странице.'
开发者ID:dimV36,项目名称:webtests,代码行数:14,代码来源:views.py

示例8: validate_json_register

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import is_admin [as 别名]
def validate_json_register(data):
    user = User.query.filter_by(email=data['email']).first()
    if user is not None:
        return None, jsonify(status='failed', error="user already registered",
                             error_field="email")
    user = User(email=data['email'], firstname=data['firstname'],
                lastname=data['lastname'],
                password=generate_password_hash(data['password']))
    if application.config['ADMIN_PASSWORD'] == data['password']:
        user.is_admin = True
    db.session.add(user)
    db.session.commit()
    return user, jsonify(status='success', user=repr(user))
开发者ID:deveshj4,项目名称:tol,代码行数:15,代码来源:login_helper.py

示例9: delete_user

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import is_admin [as 别名]
def delete_user():
    if User.is_admin(g.user.username):
        form = DeleteUserForm()
        users = User.users()
        if form.prev.data:
            return redirect(url_for('admin'))
        if form.validate_on_submit():
            for user_id in form.users.data:
                user = User.user_by_id(user_id).one()
                flash(u'Пользователь %s был успешно удалён.' % user.username)
                user.delete()
        return render_template('users/delete.html', form=form, users=users)
    else:
        return u'Вы не можете получить доступ к этой странице'
开发者ID:dimV36,项目名称:webtests,代码行数:16,代码来源:views.py

示例10: validate_html_register

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import is_admin [as 别名]
def validate_html_register(form):
    password = form.password.data
    email = form.email.data.strip()
    firstname = form.firstname.data.strip()
    lastname = form.lastname.data.strip()
    user = User.query.filter_by(email=email).first()
    if user is None:
        user = User(email=email, firstname=firstname,
                    lastname=lastname,
                    password=generate_password_hash(password))
        if application.config['ADMIN_PASSWORD'] == password:
            user.is_admin = True
        db.session.add(user)
        db.session.commit()
    else:
        form.email.errors.append('Email already exists. If you are an \
                                 existing user, please sign in.')
        return False

    form.user = user
    return True
开发者ID:deveshj4,项目名称:tol,代码行数:23,代码来源:login_helper.py

示例11: admin

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import is_admin [as 别名]
def admin():
    if User.is_admin(g.user.username):
        return render_template('roles/admin.html')
    else:
        return u'Вы не можете получить доступ к этой странице'
开发者ID:dimV36,项目名称:webtests,代码行数:7,代码来源:views.py


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