Skip to content

Commit

Permalink
Merge pull request #4 from KhaledBousrih/feature-enable-email-registe…
Browse files Browse the repository at this point in the history
…r-subject-in-settings

Feature enable email register subject in settings
  • Loading branch information
lcognat committed Feb 21, 2020
2 parents 75b5bb7 + f821d16 commit d7d2ed6
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

- fixed password change token expiry computation
- fixed register serializer to allow null values of url_format and email_format
- register email subject in settings

### Removed

Expand Down
16 changes: 12 additions & 4 deletions concrete_datastore/api/v1/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,11 @@ class RegisterSerializer(serializers.Serializer):
password1 = serializers.CharField(required=False, allow_null=True)
password2 = serializers.CharField(required=False, allow_null=True)
email_format = serializers.CharField(required=False, allow_null=True)
url_format = serializers.CharField(required=False, allow_null=True)
url_format = serializers.CharField(
required=False,
allow_null=True,
default=settings.DEFAULT_REGISTER_URL_FORMAT,
)

class Meta:
fields = (
Expand All @@ -77,20 +81,24 @@ class Meta:

def validate_url_format(self, value):
if value is None:
return '/#/set-password/{token}/{email}/'
return settings.DEFAULT_REGISTER_URL_FORMAT
return value


class ResetPasswordSerializer(serializers.Serializer):
email = serializers.EmailField()
url_format = serializers.CharField(required=False, allow_null=True)
url_format = serializers.CharField(
required=False,
allow_null=True,
default=settings.DEFAULT_RESET_PASSWORD_URL_FORMAT,
)

class Meta:
fields = ("email", "url_format")

def validate_url_format(self, value):
if value is None:
return '/#/reset-password/{token}/{email}/'
return settings.DEFAULT_RESET_PASSWORD_URL_FORMAT
return value


Expand Down
2 changes: 1 addition & 1 deletion concrete_datastore/api/v1/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -984,7 +984,7 @@ def create_user(self, request, serializer, divider=None):
confirmation.send_link(body=email_body)
else:
Email.objects.create(
subject='Set password',
subject=settings.REGISTER_EMAIL_SUBJECT,
resource_status='to-send',
resource_message='',
body=email_body,
Expand Down
6 changes: 6 additions & 0 deletions concrete_datastore/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@
</html>
""" # nosec

DEFAULT_RESET_PASSWORD_URL_FORMAT = '/#/reset-password/{token}/{email}/'

AUTH_CONFIRM_RESET_PASSWORD_EMAIL_BODY = """
<html>
<body>
Expand Down Expand Up @@ -447,6 +449,10 @@

ALLOW_SEND_EMAIL_ON_REGISTER = True

REGISTER_EMAIL_SUBJECT = "Account created"

DEFAULT_REGISTER_URL_FORMAT = '/#/set-password/{token}/{email}/'

DEFAULT_REGISTER_EMAIL_FORMAT = """
<html>
<body>
Expand Down
4 changes: 2 additions & 2 deletions development/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,10 @@

DISABLED_MODELS = ()

EMAIL_HOST = os.environ.get("EMAIL_HOST", 'localhost')
EMAIL_HOST = os.environ.get("EMAIL_HOST", '')
EMAIL_HOST_USER = os.environ.get("EMAIL_HOST_USER", '')
EMAIL_HOST_PASSWORD = os.environ.get("EMAIL_HOST_PASSWORD", '')
EMAIL_PORT = os.environ.get("EMAIL_PORT", 1025)
EMAIL_PORT = os.environ.get("EMAIL_PORT", 587)
EMAIL_USE_TLS = True
EMAIL_USE_SSL = False
EMAIL_TIMEOUT = None
Expand Down

0 comments on commit d7d2ed6

Please sign in to comment.