本文整理汇总了Python中sentry.models.User.set_password方法的典型用法代码示例。如果您正苦于以下问题:Python User.set_password方法的具体用法?Python User.set_password怎么用?Python User.set_password使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sentry.models.User
的用法示例。
在下文中一共展示了User.set_password方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: owner
# 需要导入模块: from sentry.models import User [as 别名]
# 或者: from sentry.models.User import set_password [as 别名]
def owner(self):
user = User(username="owner", email="[email protected]")
user.set_password('owner')
user.save()
Team.objects.create(owner=user, name='foo', slug='foo')
return user
示例2: create_user
# 需要导入模块: from sentry.models import User [as 别名]
# 或者: from sentry.models.User import set_password [as 别名]
def create_user(self, email, **kwargs):
kwargs.setdefault("username", email)
kwargs.setdefault("is_staff", True)
kwargs.setdefault("is_superuser", True)
user = User(email=email, **kwargs)
user.set_password("admin")
user.save()
return user
示例3: createuser
# 需要导入模块: from sentry.models import User [as 别名]
# 或者: from sentry.models.User import set_password [as 别名]
def createuser(email, password, superuser, no_password, no_input):
"Create a new user."
if not no_input:
if not email:
email = _get_email()
if not (password or no_password):
password = _get_password()
if superuser is None:
superuser = _get_superuser()
if superuser is None:
superuser = False
if not email:
raise click.ClickException('Invalid or missing email address.')
# TODO(mattrobenolt): Accept password over stdin?
if not no_password and not password:
raise click.ClickException('No password set and --no-password not passed.')
from sentry import roles
from sentry.models import User
from django.conf import settings
user = User(
email=email,
username=email,
is_superuser=superuser,
is_staff=superuser,
is_active=True,
)
if password:
user.set_password(password)
user.save()
click.echo('User created: %s' % (email,))
# TODO(dcramer): kill this when we improve flows
if settings.SENTRY_SINGLE_ORGANIZATION:
from sentry.models import Organization, OrganizationMember
org = Organization.get_default()
if superuser:
role = roles.get_top_dog().id
else:
role = org.default_role
OrganizationMember.objects.create(
organization=org,
user=user,
role=role,
)
click.echo('Added to organization: %s' % (org.slug,))
示例4: member
# 需要导入模块: from sentry.models import User [as 别名]
# 或者: from sentry.models.User import set_password [as 别名]
def member(self):
user = User(username="member", email="[email protected]")
user.set_password('member')
user.save()
TeamMember.objects.create(
user=user,
team=self.team,
type=MEMBER_USER,
)
return user
示例5: member
# 需要导入模块: from sentry.models import User [as 别名]
# 或者: from sentry.models.User import set_password [as 别名]
def member(self):
user = User(username="member", email="[email protected]")
user.set_password('member')
user.save()
om = self.create_member(
organization=self.team.organization,
user=user,
type=MEMBER_USER,
teams=[self.team],
)
return user
示例6: member
# 需要导入模块: from sentry.models import User [as 别名]
# 或者: from sentry.models.User import set_password [as 别名]
def member(self):
user = User(username="member", email="[email protected]")
user.set_password('member')
user.save()
om = OrganizationMember.objects.create(
organization=self.team.organization,
user=user,
type=MEMBER_USER,
)
om.teams.add(self.team)
return user
示例7: create_user
# 需要导入模块: from sentry.models import User [as 别名]
# 或者: from sentry.models.User import set_password [as 别名]
def create_user(self, email=None, **kwargs):
if not email:
email = uuid4().hex + '@example.com'
kwargs.setdefault('username', email)
kwargs.setdefault('is_staff', True)
kwargs.setdefault('is_superuser', False)
user = User(email=email, **kwargs)
user.set_password('admin')
user.save()
return user
示例8: handle
# 需要导入模块: from sentry.models import User [as 别名]
# 或者: from sentry.models.User import set_password [as 别名]
def handle(self, **options):
email = options['email']
is_superuser = options['is_superuser']
password = options['password']
if not options['noinput']:
try:
if not email:
email = self.get_email()
if not (password or options['nopassword']):
password = self.get_password()
if is_superuser is None:
is_superuser = self.get_superuser()
except KeyboardInterrupt:
self.stderr.write("\nOperation cancelled.")
sys.exit(1)
if not email:
raise CommandError('Invalid or missing email address')
if not options['nopassword'] and not password:
raise CommandError('No password set and --no-password not passed')
user = User(
email=email,
username=email,
is_superuser=is_superuser,
is_staff=is_superuser,
is_active=True,
)
if password:
user.set_password(password)
user.save()
self.stdout.write('User created: %s' % (email,))
# TODO(dcramer): kill this when we improve flows
if settings.SENTRY_SINGLE_ORGANIZATION:
org = Organization.objects.all()[0]
OrganizationMember.objects.create(
organization=org,
user=user,
type=OrganizationMemberType.OWNER,
has_global_access=user.is_superuser,
)
self.stdout.write('Added to organization: %s' % (org.slug,))
示例9: create_user
# 需要导入模块: from sentry.models import User [as 别名]
# 或者: from sentry.models.User import set_password [as 别名]
def create_user(self, email=None, **kwargs):
if not email:
email = uuid4().hex + '@example.com'
kwargs.setdefault('username', email)
kwargs.setdefault('is_staff', True)
kwargs.setdefault('is_active', True)
kwargs.setdefault('is_superuser', False)
user = User(email=email, **kwargs)
user.set_password('admin')
user.save()
# UserEmail is created by a signal
UserEmail.objects.filter(
user=user,
email=email,
).update(is_verified=True)
return user
示例10: handle
# 需要导入模块: from sentry.models import User [as 别名]
# 或者: from sentry.models.User import set_password [as 别名]
def handle(self, **options):
email = options['email']
is_superuser = options['is_superuser']
if not options['noinput']:
try:
if not email:
email = self.get_email()
if not options['nopassword']:
password = self.get_password()
if is_superuser is None:
is_superuser = self.get_superuser()
except KeyboardInterrupt:
self.stderr.write("\nOperation cancelled.")
sys.exit(1)
else:
password = None
if not email:
raise CommandError('Invalid or missing email address')
if not options['nopassword'] and not password:
raise CommandError('No password set and --no-password not passed')
user = User(
email=email,
username=email,
is_superuser=is_superuser,
is_staff=is_superuser,
is_active=True,
)
if password:
user.set_password(password)
user.save()
self.stdout.write('User created: %s' % (email,))
示例11: EmailAuthBackendTest
# 需要导入模块: from sentry.models import User [as 别名]
# 或者: from sentry.models.User import set_password [as 别名]
class EmailAuthBackendTest(TestCase):
def setUp(self):
self.user = User(username="foo", email="[email protected]")
self.user.set_password("bar")
self.user.save()
@property
def backend(self):
return EmailAuthBackend()
def test_can_authenticate_with_username(self):
result = self.backend.authenticate(username='foo', password='bar')
self.assertEquals(result, self.user)
def test_can_authenticate_with_email(self):
result = self.backend.authenticate(username='[email protected]', password='bar')
self.assertEquals(result, self.user)
def test_does_not_authenticate_with_invalid_password(self):
result = self.backend.authenticate(username='foo', password='pizza')
self.assertEquals(result, None)
示例12: owner
# 需要导入模块: from sentry.models import User [as 别名]
# 或者: from sentry.models.User import set_password [as 别名]
def owner(self):
user = User(username="owner", email="[email protected]")
user.set_password('owner')
user.save()
return user
示例13: configure
# 需要导入模块: from sentry.models import User [as 别名]
# 或者: from sentry.models.User import set_password [as 别名]
#!/srv/sentry/application/current/bin/python
{% from "sentry/map.jinja" import sentry with context %}
from sentry.utils.runner import configure
configure()
from sentry.models import Team, Project, ProjectKey, User, Organization
user = User()
user.username = '{{sentry.bootstrap.username}}'
user.email = '{{sentry.bootstrap.email}}'
user.is_superuser = True
user.set_password('{{sentry.bootstrap.password}}')
user.save()
organization = Organization()
organization.name = '{{sentry.bootstrap.organization}}'
organization.owner = user
organization.save()
team = Team()
team.organization = organization
team.name = '{{sentry.bootstrap.team}}'
team.owner = user
team.save()
project = Project()
project.organization = organization
project.team = team
project.owner = user
project.name = '{{sentry.bootstrap.project}}'
示例14: configure
# 需要导入模块: from sentry.models import User [as 别名]
# 或者: from sentry.models.User import set_password [as 别名]
# Bootstrap the Sentry environment
from sentry.models import Organization, OrganizationMember, \
OrganizationMemberTeam, Project, ProjectKey, Team, User
from sentry.utils.runner import configure
configure()
# Make an assumption that if 'admin' -User exists Sentry has been initialized
if not User.objects.filter(username='admin').exists():
user = User()
user.username = 'admin'
user.email = '[email protected]'
user.is_superuser = True
user.set_password('admin')
user.save()
organization = Organization.objects.filter(slug='sentry')[0]
team = Team()
team.name = 'COD'
team.organization = organization
team.save()
project = Project()
project.team = team
project.add_team(team)
project.name = 'Cern Open Data Portal'
project.organization = organization
project.save()
示例15: test_requires_password_on_valid_accounts
# 需要导入模块: from sentry.models import User [as 别名]
# 或者: from sentry.models.User import set_password [as 别名]
def test_requires_password_on_valid_accounts(self):
user = User()
user.set_password('foo')
form = RemoveProjectForm(user=user, project_list=[])
self.assertIn('password', form.fields)