def test_contains_correct_email_change_request_count(self): change = EmailActivation() change.user = self.hugo change.save() user_settings = create_user_settings(self.hugo) self.assertEqual(user_settings['emailChangeRequested'], 1) user_settings = create_user_settings(self.hein) self.assertEqual(user_settings['emailChangeRequested'], 0)
def store_settings(request): assert_authentication(request) request_data = json.loads(request.body) user = User.objects.get(id=request.user.id) assert_request_data_parameters(request_data, ["description", "displayName"]) if check_username_sanity(request_data["displayName"]): display_name = request_data["displayName"] else: raise InvalidUsername(request_data["displayName"]) if display_name != user.username: try: u = User.objects.get(username__iexact=display_name) if u != user: raise UsernameNotAvailable(display_name) except User.DoesNotExist: pass user.username = display_name user.profile.description = escape(request_data["description"]) email = request_data["email"] if email != user.email: assert_valid_email(email) eact = EmailActivation.create(user, email) try: confirm_url = settings.FINDECO_BASE_URL + "/confirm_email/" + str(eact.key) send_mail( ugettext("mail_verification_email_subject"), ugettext("mail_verification_email_body{url}").format(url=confirm_url), settings.EMAIL_HOST_USER, [email], fail_silently=False, ) except SMTPException: # This means we can't send mails, so we can't change the mail eact.delete() raise if "wantsMailNotification" in request_data: wants = request_data["wantsMailNotification"] if isinstance(wants, str): wants = wants.lower() == "true" user.profile.wants_mail_notification = wants if "helpEnabled" in request_data: user.profile.help_enabled = request_data["helpEnabled"] if "preferredLanguage" in request_data: user.profile.preferred_language = request_data["preferredLanguage"] user.save() return json_response({"storeSettingsResponse": {}})
def store_settings(request): assert_authentication(request) request_data = json.loads(request.body) user = User.objects.get(id=request.user.id) assert_request_data_parameters(request_data, ['description', 'displayName']) if check_username_sanity(request_data['displayName']): display_name = request_data['displayName'] else: raise InvalidUsername(request_data['displayName']) if display_name != user.username: try: u = User.objects.get(username__iexact=display_name) if u != user: raise UsernameNotAvailable(display_name) except User.DoesNotExist: pass user.username = display_name user.profile.description = escape(request_data['description']) email = request_data['email'] if email != user.email: assert_valid_email(email) eact = EmailActivation.create(user, email) try: confirm_url = settings.FINDECO_BASE_URL + '/confirm_email/' + \ str(eact.key) send_mail(ugettext('mail_verification_email_subject'), ugettext('mail_verification_email_body{url}').format( url=confirm_url), settings.EMAIL_HOST_USER, [email], fail_silently=False) except SMTPException: # This means we can't send mails, so we can't change the mail eact.delete() raise if 'wantsMailNotification' in request_data: wants = request_data['wantsMailNotification'] if isinstance(wants, str): wants = wants.lower() == 'true' user.profile.wants_mail_notification = wants if 'helpEnabled' in request_data: user.profile.help_enabled = request_data['helpEnabled'] if 'preferredLanguage' in request_data: user.profile.preferred_language = request_data['preferredLanguage'] user.save() return json_response({'storeSettingsResponse': {}})