def confirm_email_change(request, confirmation_key): # type: (HttpRequest, str) -> HttpResponse user_profile = request.user if user_profile.realm.email_changes_disabled: raise JsonableError(_("Email address changes are disabled in this organization.")) confirmation_key = confirmation_key.lower() obj = EmailChangeConfirmation.objects.confirm(confirmation_key) confirmed = False new_email = old_email = None # type: Text if obj: confirmed = True assert isinstance(obj, EmailChangeStatus) new_email = obj.new_email old_email = obj.old_email do_change_user_email(obj.user_profile, obj.new_email) context = {'realm': obj.realm, 'new_email': new_email, } send_email('zerver/emails/notify_change_in_email', old_email, from_email=settings.DEFAULT_FROM_EMAIL, context=context) ctx = { 'confirmed': confirmed, 'new_email': new_email, 'old_email': old_email, } return render(request, 'confirmation/confirm_email_change.html', context=ctx)
def confirm_email_change(request: HttpRequest, confirmation_key: str) -> HttpResponse: try: email_change_object = get_object_from_key(confirmation_key, Confirmation.EMAIL_CHANGE) except ConfirmationKeyException as exception: return render_confirmation_key_error(request, exception) new_email = email_change_object.new_email old_email = email_change_object.old_email user_profile = email_change_object.user_profile if user_profile.realm.email_changes_disabled and not user_profile.is_realm_admin: raise JsonableError( _("Email address changes are disabled in this organization.")) do_change_user_email(user_profile, new_email) context = {'realm': user_profile.realm, 'new_email': new_email} send_email('zerver/emails/notify_change_in_email', to_email=old_email, from_name="Zulip Account Security", from_address=FromAddress.SUPPORT, context=context) ctx = { 'new_email': new_email, 'old_email': old_email, } return render(request, 'confirmation/confirm_email_change.html', context=ctx)
def confirm_email_change(request, confirmation_key): # type: (HttpRequest, str) -> HttpResponse user_profile = request.user if user_profile.realm.email_changes_disabled: raise JsonableError(_("Email address changes are disabled in this organization.")) confirmation_key = confirmation_key.lower() try: obj = get_object_from_key(confirmation_key) except ConfirmationKeyException as exception: return render_confirmation_key_error(request, exception) assert isinstance(obj, EmailChangeStatus) new_email = obj.new_email old_email = obj.old_email do_change_user_email(obj.user_profile, obj.new_email) context = {'realm': obj.realm, 'new_email': new_email} send_email('zerver/emails/notify_change_in_email', to_email=old_email, from_name="Zulip Account Security", from_address=FromAddress.SUPPORT, context=context) ctx = { 'new_email': new_email, 'old_email': old_email, } return render(request, 'confirmation/confirm_email_change.html', context=ctx)
def confirm_email_change(request, confirmation_key): # type: (HttpRequest, str) -> HttpResponse confirmation_key = confirmation_key.lower() obj = EmailChangeConfirmation.objects.confirm(confirmation_key) confirmed = False new_email = old_email = None # type: Text if obj: confirmed = True assert isinstance(obj, EmailChangeStatus) new_email = obj.new_email old_email = obj.old_email do_change_user_email(obj.user_profile, obj.new_email) context = {'support_email': settings.ZULIP_ADMINISTRATOR, 'verbose_support_offers': settings.VERBOSE_SUPPORT_OFFERS, 'realm': obj.realm, 'new_email': new_email, } subject = render_to_string( 'confirmation/notify_change_in_email_subject.txt', context) body = render_to_string( 'confirmation/notify_change_in_email_body.txt', context) send_mail(subject, body, settings.DEFAULT_FROM_EMAIL, [old_email]) ctx = { 'confirmed': confirmed, 'support_email': settings.ZULIP_ADMINISTRATOR, 'verbose_support_offers': settings.VERBOSE_SUPPORT_OFFERS, 'new_email': new_email, 'old_email': old_email, } return render(request, 'confirmation/confirm_email_change.html', context=ctx)
def confirm_email_change(request, confirmation_key): # type: (HttpRequest, str) -> HttpResponse user_profile = request.user if user_profile.realm.email_changes_disabled: raise JsonableError(_("Email address changes are disabled in this organization.")) confirmation_key = confirmation_key.lower() obj = EmailChangeConfirmation.objects.confirm(confirmation_key) confirmed = False new_email = old_email = None # type: Text if obj: confirmed = True assert isinstance(obj, EmailChangeStatus) new_email = obj.new_email old_email = obj.old_email do_change_user_email(obj.user_profile, obj.new_email) context = {'realm': obj.realm, 'new_email': new_email, } send_email('zerver/emails/notify_change_in_email', old_email, from_address=FromAddress.SUPPORT, context=context) ctx = { 'confirmed': confirmed, 'new_email': new_email, 'old_email': old_email, } return render(request, 'confirmation/confirm_email_change.html', context=ctx)
def handle(self, *args: Any, **options: str) -> None: old_email = options['old_email'] new_email = options['new_email'] realm = self.get_realm(options) user_profile = self.get_user(old_email, realm) do_change_user_email(user_profile, new_email)
def handle(self, *args, **options): old_email = options['old_email'] new_email = options['new_email'] try: user_profile = get_user_profile_by_email(old_email) except UserProfile.DoesNotExist: print("Old e-mail doesn't exist in the system.") exit(1) do_change_user_email(user_profile, new_email)
def handle(self, *args, **options): old_email = options['old_email'] new_email = options['new_email'] try: user_profile = get_user_profile_by_email(old_email) except UserProfile.DoesNotExist: print "Old e-mail doesn't exist in the system." exit(1) do_change_user_email(user_profile, new_email)
def handle(self, *args, **options): # type: (*Any, **str) -> None old_email = options['old_email'] new_email = options['new_email'] try: user_profile = get_user_for_mgmt(old_email) except UserProfile.DoesNotExist: print("Old e-mail doesn't exist in the system.") sys.exit(1) do_change_user_email(user_profile, new_email)
def test_change_email(self) -> None: now = timezone_now() user = self.example_user('hamlet') email = '*****@*****.**' do_change_user_email(user, email) self.assertEqual(RealmAuditLog.objects.filter(event_type='user_email_changed', event_time__gte=now).count(), 1) self.assertEqual(email, user.email) # Test the RealmAuditLog stringification audit_entry = RealmAuditLog.objects.get(event_type='user_email_changed', event_time__gte=now) self.assertTrue(str(audit_entry).startswith("<RealmAuditLog: <UserProfile: [email protected] <Realm: zulip 1>> user_email_changed "))
def test_change_email(self) -> None: now = timezone_now() user = self.example_user('hamlet') email = '*****@*****.**' do_change_user_email(user, email) self.assertEqual(RealmAuditLog.objects.filter(event_type=RealmAuditLog.USER_EMAIL_CHANGED, event_time__gte=now).count(), 1) self.assertEqual(email, user.email) # Test the RealmAuditLog stringification audit_entry = RealmAuditLog.objects.get(event_type=RealmAuditLog.USER_EMAIL_CHANGED, event_time__gte=now) self.assertTrue(str(audit_entry).startswith("<RealmAuditLog: <UserProfile: [email protected] <Realm: zulip 1>> user_email_changed "))
def confirm_email_change(request, confirmation_key): # type: (HttpRequest, str) -> HttpResponse user_profile = request.user if user_profile.realm.email_changes_disabled: raise JsonableError( _("Email address changes are disabled in this organization.")) confirmation_key = confirmation_key.lower() obj = EmailChangeConfirmation.objects.confirm(confirmation_key) confirmed = False new_email = old_email = None # type: Text if obj: confirmed = True assert isinstance(obj, EmailChangeStatus) new_email = obj.new_email old_email = obj.old_email do_change_user_email(obj.user_profile, obj.new_email) context = { 'support_email': settings.ZULIP_ADMINISTRATOR, 'verbose_support_offers': settings.VERBOSE_SUPPORT_OFFERS, 'realm': obj.realm, 'new_email': new_email, } send_email('zerver/emails/notify_change_in_email', old_email, from_email=settings.DEFAULT_FROM_EMAIL, context=context) ctx = { 'confirmed': confirmed, 'support_email': settings.ZULIP_ADMINISTRATOR, 'verbose_support_offers': settings.VERBOSE_SUPPORT_OFFERS, 'new_email': new_email, 'old_email': old_email, } return render(request, 'confirmation/confirm_email_change.html', context=ctx)
def confirm_email_change(request, confirmation_key): # type: (HttpRequest, str) -> HttpResponse user_profile = request.user if user_profile.realm.email_changes_disabled: raise JsonableError(_("Email address changes are disabled in this organization.")) confirmation_key = confirmation_key.lower() obj = EmailChangeConfirmation.objects.confirm(confirmation_key) confirmed = False new_email = old_email = None # type: Text if obj: confirmed = True assert isinstance(obj, EmailChangeStatus) new_email = obj.new_email old_email = obj.old_email do_change_user_email(obj.user_profile, obj.new_email) context = {'support_email': settings.ZULIP_ADMINISTRATOR, 'verbose_support_offers': settings.VERBOSE_SUPPORT_OFFERS, 'realm': obj.realm, 'new_email': new_email, } subject = render_to_string( 'confirmation/notify_change_in_email_subject.txt', context) body = render_to_string( 'confirmation/notify_change_in_email_body.txt', context) send_mail(subject, body, settings.DEFAULT_FROM_EMAIL, [old_email]) ctx = { 'confirmed': confirmed, 'support_email': settings.ZULIP_ADMINISTRATOR, 'verbose_support_offers': settings.VERBOSE_SUPPORT_OFFERS, 'new_email': new_email, 'old_email': old_email, } return render(request, 'confirmation/confirm_email_change.html', context=ctx)
def confirm_email_change(request: HttpRequest, confirmation_key: str) -> HttpResponse: try: email_change_object = get_object_from_key(confirmation_key, Confirmation.EMAIL_CHANGE) except ConfirmationKeyException as exception: return render_confirmation_key_error(request, exception) new_email = email_change_object.new_email old_email = email_change_object.old_email user_profile = email_change_object.user_profile if user_profile.realm.email_changes_disabled and not user_profile.is_realm_admin: raise JsonableError(_("Email address changes are disabled in this organization.")) do_change_user_email(user_profile, new_email) context = {'realm_name': user_profile.realm.name, 'new_email': new_email} send_email('zerver/emails/notify_change_in_email', to_email=old_email, from_name="Zulip Account Security", from_address=FromAddress.SUPPORT, context=context) ctx = { 'new_email': new_email, 'old_email': old_email, } return render(request, 'confirmation/confirm_email_change.html', context=ctx)