本文整理汇总了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"
示例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()
示例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"))
示例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()
示例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()
示例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'))
示例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'Вы не можете получить доступ к этой странице.'
示例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))
示例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'Вы не можете получить доступ к этой странице'
示例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
示例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'Вы не можете получить доступ к этой странице'