本文整理汇总了Python中sentry.utils.auth.get_login_redirect函数的典型用法代码示例。如果您正苦于以下问题:Python get_login_redirect函数的具体用法?Python get_login_redirect怎么用?Python get_login_redirect使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_login_redirect函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: handle_basic_auth
def handle_basic_auth(self, request, organization):
can_register = features.has('auth:register') or request.session.get('can_register')
op = request.POST.get('op')
login_form = self.get_login_form(request)
if can_register:
register_form = self.get_register_form(request)
else:
register_form = None
if can_register and register_form.is_valid():
user = register_form.save()
defaults = {
'has_global_access': True,
'type': OrganizationMemberType.MEMBER,
}
organization.member_set.create(
user=user,
**defaults
)
# HACK: grab whatever the first backend is and assume it works
user.backend = settings.AUTHENTICATION_BACKENDS[0]
login(request, user)
# can_register should only allow a single registration
request.session.pop('can_register', None)
request.session.pop('needs_captcha', None)
return self.redirect(get_login_redirect(request))
elif login_form.is_valid():
login(request, login_form.get_user())
request.session.pop('needs_captcha', None)
return self.redirect(get_login_redirect(request))
elif request.POST and not request.session.get('needs_captcha'):
request.session['needs_captcha'] = 1
login_form = self.get_login_form(request)
login_form.errors.pop('captcha', None)
if can_register:
register_form = self.get_register_form(request)
register_form.errors.pop('captcha', None)
request.session.set_test_cookie()
context = {
'op': op or 'login',
'login_form': login_form,
'register_form': register_form,
'organization': organization,
'CAN_REGISTER': can_register,
}
return self.respond('sentry/organization-login.html', context)
开发者ID:Batterfii,项目名称:sentry,代码行数:60,代码来源:auth_organization_login.py
示例2: handle
def handle(self, request):
if request.user.is_authenticated():
return self.redirect(get_login_redirect(request))
form = AuthenticationForm(request, request.POST or None, captcha=bool(request.session.get("needs_captcha")))
if form.is_valid():
login(request, form.get_user())
request.session.pop("needs_captcha", None)
return self.redirect(get_login_redirect(request))
elif request.POST and not request.session.get("needs_captcha"):
request.session["needs_captcha"] = 1
form = AuthenticationForm(request, request.POST or None, captcha=True)
form.errors.pop("captcha", None)
request.session.set_test_cookie()
context = {
"form": form,
"next": request.session.get("_next"),
"CAN_REGISTER": features.has("auth:register") or request.session.get("can_register"),
"AUTH_PROVIDERS": get_auth_providers(),
"SOCIAL_AUTH_CREATE_USERS": features.has("social-auth:register"),
}
return self.respond("sentry/login.html", context)
开发者ID:Juraldinio,项目名称:sentry,代码行数:27,代码来源:auth_login.py
示例3: handle_basic_auth
def handle_basic_auth(self, request):
if request.user.is_authenticated():
return self.redirect(get_login_redirect(request))
form = AuthenticationForm(
request, request.POST or None,
captcha=bool(request.session.get('needs_captcha')),
)
if form.is_valid():
login(request, form.get_user())
request.session.pop('needs_captcha', None)
return self.redirect(get_login_redirect(request))
elif request.POST and not request.session.get('needs_captcha'):
request.session['needs_captcha'] = 1
form = AuthenticationForm(request, request.POST or None, captcha=True)
form.errors.pop('captcha', None)
request.session.set_test_cookie()
context = {
'form': form,
'CAN_REGISTER': features.has('auth:register') or request.session.get('can_register'),
}
return self.respond('sentry/login.html', context)
开发者ID:Crystalnix,项目名称:sentry,代码行数:27,代码来源:auth_login.py
示例4: handle
def handle(self, request):
if request.user.is_authenticated():
return self.redirect(get_login_redirect(request))
form = AuthenticationForm(request, request.POST or None,
captcha=bool(request.session.get('needs_captcha')))
if form.is_valid():
login(request, form.get_user())
request.session.pop('needs_captcha', None)
return self.redirect(get_login_redirect(request))
elif request.POST and not request.session.get('needs_captcha'):
request.session['needs_captcha'] = 1
form = AuthenticationForm(request, request.POST or None, captcha=True)
form.errors.pop('captcha', None)
request.session.set_test_cookie()
context = {
'form': form,
'next': request.session.get('_next'),
'CAN_REGISTER': settings.SENTRY_ALLOW_REGISTRATION or request.session.get('can_register'),
'AUTH_PROVIDERS': get_auth_providers(),
'SOCIAL_AUTH_CREATE_USERS': settings.SOCIAL_AUTH_CREATE_USERS,
}
return self.respond('sentry/login.html', context)
开发者ID:BlueMoebius,项目名称:sentry,代码行数:28,代码来源:auth_login.py
示例5: handle_basic_auth
def handle_basic_auth(self, request):
can_register = features.has('auth:register') or request.session.get('can_register')
op = request.POST.get('op')
# Detect that we are on the register page by url /register/ and
# then activate the register tab by default.
if not op and '/register' in request.path_info and can_register:
op = 'register'
login_form = self.get_login_form(request)
if can_register:
register_form = self.get_register_form(request)
else:
register_form = None
if can_register and register_form.is_valid():
user = register_form.save()
# HACK: grab whatever the first backend is and assume it works
user.backend = settings.AUTHENTICATION_BACKENDS[0]
auth.login(request, user)
# can_register should only allow a single registration
request.session.pop('can_register', None)
request.session.pop('needs_captcha', None)
return self.redirect(auth.get_login_redirect(request))
elif login_form.is_valid():
auth.login(request, login_form.get_user())
request.session.pop('needs_captcha', None)
return self.redirect(auth.get_login_redirect(request))
elif request.POST and not request.session.get('needs_captcha'):
auth.log_auth_failure(request, request.POST.get('username'))
request.session['needs_captcha'] = 1
login_form = self.get_login_form(request)
login_form.errors.pop('captcha', None)
if can_register:
register_form = self.get_register_form(request)
register_form.errors.pop('captcha', None)
request.session.set_test_cookie()
context = {
'op': op or 'login',
'login_form': login_form,
'register_form': register_form,
'CAN_REGISTER': can_register,
}
return self.respond('sentry/login.html', context)
开发者ID:IthacaDream,项目名称:sentry,代码行数:56,代码来源:auth_login.py
示例6: handle_basic_auth
def handle_basic_auth(self, request):
can_register = features.has('auth:register') or request.session.get('can_register')
op = request.POST.get('op')
# Detect that we are on the register page by url /register/ and
# then activate the register tab by default.
if not op and '/register' in request.path_info and can_register:
op = 'register'
login_form = self.get_login_form(request)
if can_register:
register_form = self.get_register_form(request, initial={
'username': request.session.get('invite_email', '')
})
else:
register_form = None
if can_register and register_form.is_valid():
user = register_form.save()
user.send_confirm_emails(is_new_user=True)
# HACK: grab whatever the first backend is and assume it works
user.backend = settings.AUTHENTICATION_BACKENDS[0]
auth.login(request, user)
# can_register should only allow a single registration
request.session.pop('can_register', None)
request.session.pop('invite_email', None)
return self.redirect(auth.get_login_redirect(request))
elif login_form.is_valid():
user = login_form.get_user()
auth.login(request, user)
if not user.is_active:
return self.redirect(reverse('sentry-reactivate-account'))
return self.redirect(auth.get_login_redirect(request))
request.session.set_test_cookie()
context = {
'op': op or 'login',
'server_hostname': get_server_hostname(),
'login_form': login_form,
'register_form': register_form,
'CAN_REGISTER': can_register,
}
return self.respond('sentry/login.html', context)
开发者ID:ForkRepo,项目名称:sentry,代码行数:53,代码来源:auth_login.py
示例7: handle_basic_auth
def handle_basic_auth(self, request):
can_register = features.has("auth:register") or request.session.get("can_register")
op = request.POST.get("op")
# Detect that we are on the register page by url /register/ and
# then activate the register tab by default.
if not op and "/register" in request.path_info and can_register:
op = "register"
login_form = self.get_login_form(request)
if can_register:
register_form = self.get_register_form(
request, initial={"username": request.session.get("invite_email", "")}
)
else:
register_form = None
if can_register and register_form.is_valid():
user = register_form.save()
user.send_confirm_emails(is_new_user=True)
# HACK: grab whatever the first backend is and assume it works
user.backend = settings.AUTHENTICATION_BACKENDS[0]
auth.login(request, user)
# can_register should only allow a single registration
request.session.pop("can_register", None)
request.session.pop("invite_email", None)
return self.redirect(auth.get_login_redirect(request))
elif login_form.is_valid():
user = login_form.get_user()
auth.login(request, user)
if not user.is_active:
return self.redirect(reverse("sentry-reactivate-account"))
return self.redirect(auth.get_login_redirect(request))
context = {
"op": op or "login",
"server_hostname": get_server_hostname(),
"login_form": login_form,
"register_form": register_form,
"CAN_REGISTER": can_register,
}
return self.respond("sentry/login.html", context)
开发者ID:alexm92,项目名称:sentry,代码行数:51,代码来源:auth_login.py
示例8: handle_basic_auth
def handle_basic_auth(self, request, organization):
can_register = features.has('auth:register') or request.session.get('can_register')
op = request.POST.get('op')
login_form = self.get_login_form(request)
if can_register:
register_form = self.get_register_form(request)
else:
register_form = None
if can_register and register_form.is_valid():
user = register_form.save()
user.send_confirm_emails(is_new_user=True)
defaults = {
'role': 'member',
}
organization.member_set.create(
user=user,
**defaults
)
# HACK: grab whatever the first backend is and assume it works
user.backend = settings.AUTHENTICATION_BACKENDS[0]
auth.login(request, user, organization_id=organization.id)
# can_register should only allow a single registration
request.session.pop('can_register', None)
return self.redirect(auth.get_login_redirect(request))
elif login_form.is_valid():
auth.login(request, login_form.get_user(),
organization_id=organization.id)
return self.redirect(auth.get_login_redirect(request))
request.session.set_test_cookie()
context = {
'op': op or 'login',
'login_form': login_form,
'register_form': register_form,
'organization': organization,
'CAN_REGISTER': can_register,
}
return self.respond('sentry/organization-login.html', context)
开发者ID:faulkner,项目名称:sentry,代码行数:49,代码来源:auth_organization_login.py
示例9: _handle_existing_identity
def _handle_existing_identity(self, auth_identity, identity):
# TODO(dcramer): this is very similar to attach
now = timezone.now()
auth_identity.update(
data=identity.get('data', {}),
last_verified=now,
last_synced=now,
)
try:
member = OrganizationMember.objects.get(
user=auth_identity.user,
organization=self.organization,
)
except OrganizationMember.DoesNotExist:
# this is likely the case when someone was removed from the org
# but still has access to rejoin
member = self._handle_new_membership(auth_identity)
else:
if getattr(member.flags, 'sso:invalid') or not getattr(member.flags, 'sso:linked'):
setattr(member.flags, 'sso:invalid', False)
setattr(member.flags, 'sso:linked', True)
member.save()
user = auth_identity.user
user.backend = settings.AUTHENTICATION_BACKENDS[0]
login(self.request, user)
self.clear_session()
return HttpResponseRedirect(get_login_redirect(self.request))
开发者ID:delkyd,项目名称:sentry,代码行数:32,代码来源:helper.py
示例10: _handle_unknown_identity
def _handle_unknown_identity(self, identity):
"""
Flow is activated upon a user logging in to where an AuthIdentity is
not present.
The flow will attempt to answer the following:
- Is there an existing user with the same email address? Should they be
merged?
- Is there an existing user (via authentication) that shoudl be merged?
- Should I create a new user based on this identity?
"""
request = self.request
op = request.POST.get('op')
if not request.user.is_authenticated():
try:
existing_user = find_users(identity['email'])[0]
except IndexError:
existing_user = None
login_form = self._get_login_form(existing_user)
if op == 'confirm' and request.user.is_authenticated():
auth_identity = self._handle_attach_identity(identity)
elif op == 'newuser':
auth_identity = self._handle_new_user(identity)
elif op == 'login' and not request.user.is_authenticated():
# confirm authentication, login
op = None
if login_form.is_valid():
login(request, login_form.get_user())
request.session.pop('needs_captcha', None)
else:
request.session['needs_captcha'] = 1
else:
op = None
if not op:
if request.user.is_authenticated():
return self.respond('sentry/auth-confirm-link.html', {
'identity': identity,
'existing_user': request.user,
})
return self.respond('sentry/auth-confirm-identity.html', {
'existing_user': existing_user,
'identity': identity,
'login_form': login_form,
})
user = auth_identity.user
user.backend = settings.AUTHENTICATION_BACKENDS[0]
login(self.request, user)
self.clear_session()
return HttpResponseRedirect(get_login_redirect(self.request))
开发者ID:delkyd,项目名称:sentry,代码行数:60,代码来源:helper.py
示例11: perform_signin
def perform_signin(self, request, user, interface=None):
auth.login(request, user, passed_2fa=True)
rv = HttpResponseRedirect(auth.get_login_redirect(request))
if interface is not None:
interface.authenticator.mark_used()
if not interface.is_backup_interface:
rv.set_cookie(COOKIE_NAME, str(interface.type),
max_age=COOKIE_MAX_AGE, path='/')
return rv
开发者ID:JJediny,项目名称:sentry,代码行数:9,代码来源:twofactor.py
示例12: handle_existing_identity
def handle_existing_identity(auth_provider, provider, organization,
request, state, auth_identity, identity):
# TODO(dcramer): this is very similar to attach
now = timezone.now()
auth_identity.update(
data=provider.update_identity(
new_data=identity.get('data', {}),
current_data=auth_identity.data,
),
last_verified=now,
last_synced=now,
)
try:
member = OrganizationMember.objects.get(
user=auth_identity.user,
organization=organization,
)
except OrganizationMember.DoesNotExist:
# this is likely the case when someone was removed from the org
# but still has access to rejoin
member = handle_new_membership(auth_provider, organization, request, auth_identity)
else:
if getattr(member.flags, 'sso:invalid') or not getattr(member.flags, 'sso:linked'):
setattr(member.flags, 'sso:invalid', False)
setattr(member.flags, 'sso:linked', True)
member.save()
user = auth_identity.user
user.backend = settings.AUTHENTICATION_BACKENDS[0]
if not auth.login(
request,
user,
after_2fa=request.build_absolute_uri(),
organization_id=organization.id
):
return HttpResponseRedirect(auth.get_login_redirect(request))
state.clear()
metrics.incr('sso.login-success', tags={'provider': provider.key})
return HttpResponseRedirect(auth.get_login_redirect(request))
开发者ID:binlee1990,项目名称:sentry,代码行数:43,代码来源:helper.py
示例13: handle
def handle(self, request):
if not request.user.is_authenticated:
return self.handle_auth_required(request)
if request.POST.get('op') == 'confirm':
request.user.update(is_active=True)
return self.redirect(auth.get_login_redirect(request))
context = {}
return self.respond('sentry/reactivate-account.html', context)
开发者ID:Akashguharoy,项目名称:sentry,代码行数:11,代码来源:reactivate_account.py
示例14: _finish_login_pipeline
def _finish_login_pipeline(self, identity):
auth_provider = self.auth_provider
try:
auth_identity = AuthIdentity.objects.get(auth_provider=auth_provider, ident=identity["id"])
except AuthIdentity.DoesNotExist:
user = User.objects.create(email=identity["email"], first_name=identity.get("name"), is_managed=True)
AuthIdentity.objects.create(auth_provider=auth_provider, user=user, ident=identity["id"])
om = OrganizationMember.objects.create(
organization=self.organization,
type=auth_provider.default_role,
has_global_access=auth_provider.default_global_access,
user=user,
flags=getattr(OrganizationMember.flags, "sso:linked"),
)
default_teams = auth_provider.default_teams.all()
for team in default_teams:
om.teams.add(team)
AuditLogEntry.objects.create(
organization=self.organization,
actor=user,
ip_address=self.request.META["REMOTE_ADDR"],
target_object=om.id,
target_user=om.user,
event=AuditLogEntryEvent.MEMBER_ADD,
data=om.get_audit_log_data(),
)
else:
now = timezone.now()
auth_identity.update(data=identity["data"], last_verified=now, last_synced=now)
om = OrganizationMember.objects.get(user=auth_identity.user, organization=self.organization)
setattr(om.flags, "sso:invalid", False)
setattr(om.flags, "sso:linked", True)
om.save()
user = auth_identity.user
user.backend = settings.AUTHENTICATION_BACKENDS[0]
login(self.request, user)
return HttpResponseRedirect(get_login_redirect(self.request))
开发者ID:Juraldinio,项目名称:sentry,代码行数:46,代码来源:helper.py
示例15: test_no_value_uses_default
def test_no_value_uses_default(self):
result = get_login_redirect(self.make_request())
assert result == reverse('sentry-login')
开发者ID:Kayle009,项目名称:sentry,代码行数:3,代码来源:tests.py
示例16: test_schema_uses_default
def test_schema_uses_default(self):
result = get_login_redirect(self.make_request('http://example.com'))
assert result == reverse('sentry-login')
开发者ID:Kayle009,项目名称:sentry,代码行数:3,代码来源:tests.py
示例17: handle_basic_auth
def handle_basic_auth(self, request):
can_register = features.has('auth:register') or request.session.get('can_register')
op = request.POST.get('op')
# Detect that we are on the register page by url /register/ and
# then activate the register tab by default.
if not op and '/register' in request.path_info and can_register:
op = 'register'
login_form = self.get_login_form(request)
if can_register:
register_form = self.get_register_form(request)
else:
register_form = None
if can_register and register_form.is_valid():
user = register_form.save()
user.send_confirm_emails(is_new_user=True)
# HACK: grab whatever the first backend is and assume it works
user.backend = settings.AUTHENTICATION_BACKENDS[0]
auth.login(request, user)
# can_register should only allow a single registration
request.session.pop('can_register', None)
request.session.pop('needs_captcha', None)
return self.redirect(auth.get_login_redirect(request))
elif login_form.is_valid():
user = login_form.get_user()
auth.login(request, user)
request.session.pop('needs_captcha', None)
if not user.is_active:
return self.redirect(reverse('sentry-reactivate-account'))
return self.redirect(auth.get_login_redirect(request))
elif request.POST and not request.session.get('needs_captcha'):
auth.log_auth_failure(request, request.POST.get('username'))
request.session['needs_captcha'] = 1
login_form = self.get_login_form(request)
login_form.errors.pop('captcha', None)
if can_register:
register_form = self.get_register_form(request)
register_form.errors.pop('captcha', None)
# When the captcha fails, hide any other errors
# to prevent brute force attempts.
if 'captcha' in login_form.errors:
for k in login_form.errors.keys():
if k != 'captcha':
login_form.errors.pop(k)
request.session.set_test_cookie()
context = {
'op': op or 'login',
'server_hostname': get_server_hostname(),
'login_form': login_form,
'register_form': register_form,
'CAN_REGISTER': can_register,
}
return self.respond('sentry/login.html', context)
开发者ID:WhoTrades,项目名称:sentry,代码行数:70,代码来源:auth_login.py
示例18: handle
def handle(self, request):
rv = get_login_redirect(request)
logout(request)
request.user = AnonymousUser()
return self.redirect(rv)
开发者ID:280185386,项目名称:sentry,代码行数:5,代码来源:auth_logout.py
示例19: _handle_unknown_identity
def _handle_unknown_identity(self, identity):
"""
Flow is activated upon a user logging in to where an AuthIdentity is
not present.
The flow will attempt to answer the following:
- Is there an existing user with the same email address? Should they be
merged?
- Is there an existing user (via authentication) that shoudl be merged?
- Should I create a new user based on this identity?
"""
request = self.request
op = request.POST.get('op')
if not request.user.is_authenticated():
# TODO(dcramer): its possible they have multiple accounts and at
# least one is managed (per the check below)
try:
existing_user = auth.find_users(identity['email'], is_active=True)[0]
except IndexError:
existing_user = None
# If they already have an SSO account and the identity provider says
# the email matches we go ahead and let them merge it. This is the
# only way to prevent them having duplicate accounts, and because
# we trust identity providers, its considered safe.
if existing_user and existing_user.is_managed:
# we only allow this flow to happen if the existing user has
# membership, otherwise we short circuit because it might be
# an attempt to hijack membership of another organization
has_membership = OrganizationMember.objects.filter(
user=existing_user,
organization=self.organization,
).exists()
if has_membership:
if not auth.login(request, existing_user,
after_2fa=request.build_absolute_uri()):
return HttpResponseRedirect(auth.get_login_redirect(
self.request))
# assume they've confirmed they want to attach the identity
op = 'confirm'
else:
# force them to create a new account
existing_user = None
login_form = self._get_login_form(existing_user)
elif request.user.is_managed:
# per the above, try to auto merge if the user was originally an
# SSO account but is still logged in
has_membership = OrganizationMember.objects.filter(
user=request.user,
organization=self.organization,
).exists()
if has_membership:
# assume they've confirmed they want to attach the identity
op = 'confirm'
if op == 'confirm' and request.user.is_authenticated():
auth_identity = self._handle_attach_identity(identity)
elif op == 'newuser':
auth_identity = self._handle_new_user(identity)
elif op == 'login' and not request.user.is_authenticated():
# confirm authentication, login
op = None
if login_form.is_valid():
# This flow is special. If we are going through a 2FA
# flow here (login returns False) we want to instruct the
# system to return upon completion of the 2fa flow to the
# current URL and continue with the dialog.
#
# If there is no 2fa we don't need to do this and can just
# go on.
if not auth.login(request, login_form.get_user(),
after_2fa=request.build_absolute_uri()):
return HttpResponseRedirect(auth.get_login_redirect(
self.request))
request.session.pop('needs_captcha', None)
else:
auth.log_auth_failure(request, request.POST.get('username'))
request.session['needs_captcha'] = 1
else:
op = None
if not op:
if request.user.is_authenticated():
return self.respond('sentry/auth-confirm-link.html', {
'identity': identity,
'existing_user': request.user,
'identity_display_name': self._get_display_name(identity),
'identity_identifier': self._get_identifier(identity)
})
return self.respond('sentry/auth-confirm-identity.html', {
'existing_user': existing_user,
'identity': identity,
'login_form': login_form,
'identity_display_name': self._get_display_name(identity),
#.........这里部分代码省略.........
开发者ID:Akashguharoy,项目名称:sentry,代码行数:101,代码来源:helper.py
示例20: login_redirect
def login_redirect(request):
login_url = get_login_redirect(request)
return HttpResponseRedirect(login_url)
开发者ID:280185386,项目名称:sentry,代码行数:3,代码来源:accounts.py
注:本文中的sentry.utils.auth.get_login_redirect函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论