本文整理汇总了Python中mongoengine.django.auth.User.is_staff方法的典型用法代码示例。如果您正苦于以下问题:Python User.is_staff方法的具体用法?Python User.is_staff怎么用?Python User.is_staff使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mongoengine.django.auth.User
的用法示例。
在下文中一共展示了User.is_staff方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: authenticate
# 需要导入模块: from mongoengine.django.auth import User [as 别名]
# 或者: from mongoengine.django.auth.User import is_staff [as 别名]
def authenticate(self, pxt_session=None):
pxt = pxt_session.split("x")[0]
space_db = SpacewalkDB()
result = space_db.get_web_user(pxt)
web_user_id = result[0]
if web_user_id == 'None':
_LOG.error('spacewalk session has expired')
return None
result = space_db.get_login(web_user_id)
db_user_login = result[0]
_LOG.info('DB USER: %s' % (db_user_login))
try:
user = User.objects.get(username=db_user_login)
_LOG.info('report server username: %s' % (user.username))
except User.DoesNotExist:
# Create a new user. Note that we can set password
# to anything, because it won't be checked; the password
# Another option is to decode the spacewalk user passwd
_LOG.debug("The user %s does not exist, and will be created" % (db_user_login))
user = User(username=db_user_login, password="default")
user.is_active = True
user.is_staff = False
user.is_superuser = False
user.save()
return user
示例2: handle
# 需要导入模块: from mongoengine.django.auth import User [as 别名]
# 或者: from mongoengine.django.auth.User import is_staff [as 别名]
def handle(self, **kwargs):
while True:
username = self._get_string('Username')
if User.objects(username=username).count() > 0:
print "That username is already in use"
continue
else:
break
while True:
email = self._get_string('Email', required=False)
if User.objects(email=email).count() > 0:
print "That email is already in use"
continue
else:
break
password = self._get_string('Password', getpass.getpass)
first_name = self._get_string('First name')
last_name = self._get_string('Last name')
u = User(username=username)
u.first_name = first_name
u.last_name = last_name
u.email = email
u.set_password(password)
u.is_staff = True
u.is_superuser = False
u.save()
print 'User "%s %s" successfully added' % (first_name, last_name)
示例3: authenticate
# 需要导入模块: from mongoengine.django.auth import User [as 别名]
# 或者: from mongoengine.django.auth.User import is_staff [as 别名]
def authenticate(self, username=None, password=None):
payload = {'username': username, 'password': password}
url = '%s/auth/login/' % (settings.API_BASE_URL,)
r = requests.post(url, data=json.dumps(payload))
if r.status_code == requests.codes.ok:
token = r.headers.get('x-auth-token')
if not token:
return None
try:
user = User.objects.get(username=username)
user.password = token
user.save()
except User.DoesNotExist:
# Create a new user. Note that we can set password
# to anything, because it won't be checked; the password
# from settings.py will.
user = User(username=username, password=token)
user.is_staff = True
user.is_superuser = True
user.save()
return user
elif r.status_code >= requests.codes.internal_server_error:
raise Exception('Server error. ' + str(r.status_code))
return None
示例4: handle
# 需要导入模块: from mongoengine.django.auth import User [as 别名]
# 或者: from mongoengine.django.auth.User import is_staff [as 别名]
def handle(self, **kwargs):
username = self._get_string('Username')
email = self._get_string('Email', required=False)
password = self._get_string('Password', getpass.getpass)
first_name = self._get_string('First name')
last_name = self._get_string('Last name')
user = User(username=username)
user.first_name = first_name
user.last_name = last_name
user.email = email
user.set_password(password)
user.is_staff = True
user.save()
print 'User "%s %s" successfully added' % (first_name, last_name)
示例5: authenticate
# 需要导入模块: from mongoengine.django.auth import User [as 别名]
# 或者: from mongoengine.django.auth.User import is_staff [as 别名]
def authenticate(self, username=None, password=None, domain=None):
base = settings.LDAP_BASE
scope = ldap.SCOPE_SUBTREE
filter = "(&(objectclass=person) (uid=%s))" % username
ret = ['dn']
try:
l = ldap.initialize(settings.LDAP_SERVER);
l.protocol_version = ldap.VERSION3
l.simple_bind_s()
except ldap.LDAPError:
return None
try:
result_id = l.search(base, scope, filter, ret)
result_type, result_data = l.result(result_id, 0)
if (len(result_data) != 1):
return None
l.simple_bind_s(result_data[0][0],password)
u = User.objects(username=username).first()
if u is None:
from random import choice
import string
temp_pass = ""
for i in range(8):
temp_pass = temp_pass + choice(string.letters)
u = User(username=username)
u.email = username + settings.LDAP_EMAIL_DOMAIN
u.set_password(temp_pass)
u.is_staff = True
u.is_superuser = False
u.is_active = True
u.save()
return u
except ldap.INVALID_CREDENTIALS:
return None
示例6: register
# 需要导入模块: from mongoengine.django.auth import User [as 别名]
# 或者: from mongoengine.django.auth.User import is_staff [as 别名]
def register(request):
logger.debug('Register requested from IP %s' % request.META.get('REMOTE_ADDR'))
if request.user.is_authenticated():
return HttpResponseRedirect(reverse('web.index'))
if request.method == 'GET':
ctx = {'user': request.user, 'form': forms.RegisterForm(), }
return render(request, 'pages/register.html', ctx)
if request.method == 'POST':
form = forms.RegisterForm(request.POST)
if not form.is_valid():
ctx = {'form': form, }
return render(request, 'pages/register.html', ctx)
else:
new_user = User()
random_username = ''.join(random.sample(string.ascii_lowercase * 30, 20))
new_user.username = random_username
new_user.email = form.cleaned_data['email']
new_user.is_active = True
new_user.is_staff = False
new_user.is_superuser = False
new_user.set_password(form.cleaned_data['password'])
new_user.save()
user_doc = mongo.db.user.find_one({'username': new_user.username})
user_doc['writing_api_key'] = ''.join(random.sample(string.ascii_lowercase * 30, 20))
user_doc['reading_api_key'] = ''.join(random.sample(string.ascii_lowercase * 30, 20))
del user_doc['_id']
mongo.db.user.update({'username': new_user.username}, {'$set': user_doc})
logger.info('New user registered with email: %s' % new_user.email)
# log in
auth_login(request, authenticate(username=random_username, password=form.cleaned_data.get("password")))
return HttpResponseRedirect(reverse('web.settings'))
示例7: create_user
# 需要导入模块: from mongoengine.django.auth import User [as 别名]
# 或者: from mongoengine.django.auth.User import is_staff [as 别名]
def create_user(username, password, group, telphone = None, email=None, is_staff=True, is_active=True, is_superuser=False):
now = datetime.datetime.now()
if email is not None:
try:
email_name, domain_part = email.strip().split('@', 1)
except ValueError:
pass
else:
email = '@'.join([email_name, domain_part.lower()])
user = User()
user.username = username
user.password = make_password(password)
user.group = group
user.email = email
user.telphone = telphone
user.is_staff = is_staff
user.is_active = is_active
user.is_superuser = is_superuser
user.date_joined = now
user.save()
return user
示例8: MongoUser
# 需要导入模块: from mongoengine.django.auth import User [as 别名]
# 或者: from mongoengine.django.auth.User import is_staff [as 别名]
parser.add_argument('--all', dest='all', action='store_true', help='convert every models')
parser.add_argument('--models', '-m', dest='models', nargs='*', help='convert specified models')
arguments = parser.parse_args()
i = 0
# User
if arguments.all or 'User' in arguments.models:
for sqlRow in DjangoUser.objects.all():
mongoRow = MongoUser()
mongoRow.username = sqlRow.username
mongoRow.first_name = sqlRow.first_name
mongoRow.last_name = sqlRow.last_name
mongoRow.email = sqlRow.email
mongoRow.password = sqlRow.password
mongoRow.is_staff = sqlRow.is_staff
mongoRow.is_active = sqlRow.is_active
mongoRow.is_superuser = sqlRow.is_superuser
mongoRow.last_login = sqlRow.last_login
mongoRow.date_joined = sqlRow.date_joined
mongoRow.save()
i += 1
print "User" + str(i)
i = 0
# EndGame
if arguments.all or 'EndGame' in arguments.models:
for sqlRow in sql.EndGame.objects.all():