Skip to content

Saleor Core: the high performance, composable, headless commerce API.

Add base for registration usage

Marek Brzóska7e620c0ea7f8
diff --git a/saleor/settings.py b/saleor/settings.py
index 2417a80d34..0aedd960aa 100644
--- a/saleor/settings.py
+++ b/saleor/settings.py
@@ -92,6 +92,7 @@ INSTALLED_APPS = [
'south',
'django_prices',
'mptt',
+ 'registration',
# Local apps
'saleor',
@@ -149,3 +150,5 @@ AUTH_USER_MODEL = 'userprofile.User'
WARN_ABOUT_INVALID_HTML5_OUTPUT = True
SATCHLESS_DEFAULT_CURRENCY = 'USD'
+
+ACCOUNT_ACTIVATION_DAYS = 3
diff --git a/saleor/templates/registration/activate.html b/saleor/templates/registration/activate.html
new file mode 100644
index 0000000000..b9a929ce56
--- /dev/null
+++ b/saleor/templates/registration/activate.html
@@ -0,0 +1,10 @@
+{% extends "registration/registration_base.html" %}
+{% block title %}{% if account %}Activation complete{% else %}Activation problem{% endif %}{% endblock %}
+{% block content %}
+{% if account %}
+Thanks {{ account }}, activation complete! You may now <a href='{% url 'auth_login' %}'>login</a> using the username and password you set at registration.
+{% else %}
+Oops &ndash; it seems that your activation key is invalid. Please check the url again.
+{% endif %}
+{% endblock %}
+
diff --git a/saleor/templates/registration/activation_complete.html b/saleor/templates/registration/activation_complete.html
new file mode 100644
index 0000000000..4a6c61aa6b
--- /dev/null
+++ b/saleor/templates/registration/activation_complete.html
@@ -0,0 +1,7 @@
+{% extends "registration/registration_base.html" %}
+{% block title %}Activation complete{% endblock %}
+{% block content %}
+Thanks, activation complete! You may now <a href='{% url 'auth_login' %}'>login</a> using the username and password you set at registration.
+{% endblock %}
+
+
diff --git a/saleor/templates/registration/activation_email.txt b/saleor/templates/registration/activation_email.txt
new file mode 100644
index 0000000000..7234f33807
--- /dev/null
+++ b/saleor/templates/registration/activation_email.txt
@@ -0,0 +1,11 @@
+You (or someone pretending to be you) have asked to register an account at
+{{ site.name }}. If this wasn't you, please ignore this email
+and your address will be removed from our records.
+
+To activate this account, please click the following link within the next
+{{ expiration_days }} days:
+
+http://{{site.domain}}{% url 'registration:registration_activate' activation_key %}
+
+Sincerely,
+{{ site.name }} Management
diff --git a/saleor/templates/registration/activation_email_subject.txt b/saleor/templates/registration/activation_email_subject.txt
new file mode 100644
index 0000000000..13912aafdd
--- /dev/null
+++ b/saleor/templates/registration/activation_email_subject.txt
@@ -0,0 +1 @@
+Account registration for {{ site.name }}
diff --git a/saleor/templates/registration/login.html b/saleor/templates/registration/login.html
new file mode 100644
index 0000000000..80b79dd56e
--- /dev/null
+++ b/saleor/templates/registration/login.html
@@ -0,0 +1,26 @@
+{% extends "registration/registration_base.html" %}
+{% block title %}Login{% endblock %}
+{% block content %}
+
+{% if form.errors %}
+<p>Your username and password didn't match. Please try again.</p>
+{% endif %}
+
+<form method="post" action="{% url 'auth_login' %}">{% csrf_token %}
+<table>
+<tr>
+ <td>{{ form.username.label_tag }}</td>
+ <td>{{ form.username }}</td>
+</tr>
+<tr>
+ <td>{{ form.password.label_tag }}</td>
+ <td>{{ form.password }}</td>
+</tr>
+</table>
+<p><a href="{% url 'auth_password_reset' %}">Forgot</a> your password? <a href="{% url 'registration_register' %}">Need an account</a>?</p>
+
+<input type="submit" value="login" />
+<input type="hidden" name="next" value="{{ next }}" />
+</form>
+
+{% endblock %}
diff --git a/saleor/templates/registration/logout.html b/saleor/templates/registration/logout.html
new file mode 100644
index 0000000000..39a6e99af1
--- /dev/null
+++ b/saleor/templates/registration/logout.html
@@ -0,0 +1,5 @@
+{% extends "registration/registration_base.html" %}
+{% block title %}Logged out{% endblock %}
+{% block content %}
+Successfully logged out!
+{% endblock %}
diff --git a/saleor/templates/registration/password_change_done.html b/saleor/templates/registration/password_change_done.html
new file mode 100644
index 0000000000..c83650412d
--- /dev/null
+++ b/saleor/templates/registration/password_change_done.html
@@ -0,0 +1,6 @@
+{% extends "registration/registration_base.html" %}
+{% block title %}Password changed{% endblock %}
+{% block content %}
+Password successfully changed!
+{% endblock %}
+
diff --git a/saleor/templates/registration/password_change_form.html b/saleor/templates/registration/password_change_form.html
new file mode 100644
index 0000000000..95939d160a
--- /dev/null
+++ b/saleor/templates/registration/password_change_form.html
@@ -0,0 +1,10 @@
+{% extends "registration/registration_base.html" %}
+{% block title %}Change password{% endblock %}
+{% block content %}
+<form method='post' action=''>{% csrf_token %}
+<table>
+ {{ form }}
+ <tr><td></td><td><input type='submit' value="Change password" /></td></tr>
+</table>
+</form>
+{% endblock %}
diff --git a/saleor/templates/registration/password_reset_complete.html b/saleor/templates/registration/password_reset_complete.html
new file mode 100644
index 0000000000..0457b20873
--- /dev/null
+++ b/saleor/templates/registration/password_reset_complete.html
@@ -0,0 +1,5 @@
+{% extends "registration/registration_base.html" %}
+{% block title %}Password reset complete{% endblock %}
+{% block content %}
+Your password has been reset! You may now <a href="{{ login_url }}">log in</a>.
+{% endblock %}
diff --git a/saleor/templates/registration/password_reset_confirm.html b/saleor/templates/registration/password_reset_confirm.html
new file mode 100644
index 0000000000..6c4e150398
--- /dev/null
+++ b/saleor/templates/registration/password_reset_confirm.html
@@ -0,0 +1,11 @@
+{% extends "registration/registration_base.html" %}
+{% block title %}Confirm password reset{% endblock %}
+{% block content %}
+Enter your new password below to reset your password:
+<form method="post" action="">{% csrf_token %}
+<table>
+ {{ form.as_table }}
+ <tr><td></ td><td><input type="submit" value="Set password" /></td></tr>
+</table>
+</form>
+{% endblock %}
diff --git a/saleor/templates/registration/password_reset_done.html b/saleor/templates/registration/password_reset_done.html
new file mode 100644
index 0000000000..47a8c49ef6
--- /dev/null
+++ b/saleor/templates/registration/password_reset_done.html
@@ -0,0 +1,8 @@
+{% extends "registration/registration_base.html" %}
+{% block title %}Password reset{% endblock %}
+{% block content %}
+<p>
+We have sent you an email with a link to reset your password. Please check
+your email and click the link to continue.
+</p>
+{% endblock %}
diff --git a/saleor/templates/registration/password_reset_email.html b/saleor/templates/registration/password_reset_email.html
new file mode 100644
index 0000000000..62977c2b01
--- /dev/null
+++ b/saleor/templates/registration/password_reset_email.html
@@ -0,0 +1,16 @@
+Greetings {% if user.get_full_name %}{{ user.get_full_name }}{% else %}{{ user }}{% endif %},
+
+You are receiving this email because you (or someone pretending to be you)
+requested that your password be reset on the {{ domain }} site. If you do not
+wish to reset your password, please ignore this message.
+
+To reset your password, please click the following link, or copy and paste it
+into your web browser:
+
+{{ protocol }}://{{ domain }}{% url 'auth_password_reset_confirm' uid token %}
+
+Your username, in case you've forgotten: {{ user.username }}
+
+
+Best regards,
+{{ site_name }} Management
diff --git a/saleor/templates/registration/password_reset_form.html b/saleor/templates/registration/password_reset_form.html
new file mode 100644
index 0000000000..3bf1f99a12
--- /dev/null
+++ b/saleor/templates/registration/password_reset_form.html
@@ -0,0 +1,12 @@
+{% extends "registration/registration_base.html" %}
+{% block title %}Reset password{% endblock %}
+{% block content %}
+Forgot your password? Enter your email in the form below and we'll send you
+instructions for creating a new one.
+<form method='post' action=''>{% csrf_token %}
+<table>
+ {{ form }}
+ <tr><td></td><td><input type='submit' value="Reset password" /></td></tr>
+</table>
+</form>
+{% endblock %}
diff --git a/saleor/templates/registration/registration_base.html b/saleor/templates/registration/registration_base.html
new file mode 100644
index 0000000000..94d9808cc7
--- /dev/null
+++ b/saleor/templates/registration/registration_base.html
@@ -0,0 +1 @@
+{% extends "base.html" %}
diff --git a/saleor/templates/registration/registration_complete.html b/saleor/templates/registration/registration_complete.html
new file mode 100644
index 0000000000..0e3ceaa9ff
--- /dev/null
+++ b/saleor/templates/registration/registration_complete.html
@@ -0,0 +1,6 @@
+{% extends "registration/registration_base.html" %}
+{% block title %}Activation email sent{% endblock %}
+{% block content %}
+An activation email has been sent. Please check your email and click on the link to activate your account.
+{% endblock %}
+
diff --git a/saleor/templates/registration/registration_form.html b/saleor/templates/registration/registration_form.html
new file mode 100644
index 0000000000..1f16a80571
--- /dev/null
+++ b/saleor/templates/registration/registration_form.html
@@ -0,0 +1,10 @@
+{% extends "registration/registration_base.html" %}
+{% block title %}Register for an account{% endblock %}
+{% block content %}
+<table>
+ <form method='post' action=''>{% csrf_token %}
+ {{ form }}
+ <tr><td></td><td><input type="submit" value="Send activation email" /></td>
+ </form>
+</table>
+{% endblock %}
diff --git a/saleor/urls.py b/saleor/urls.py
index 89d9e665dd..4d90ccd717 100644
--- a/saleor/urls.py
+++ b/saleor/urls.py
@@ -4,10 +4,12 @@ from django.contrib import admin
admin.autodiscover()
-urlpatterns = patterns('',
+urlpatterns = patterns(
+ '',
url(r'^admin/', include(admin.site.urls)),
url(r'^$', 'saleor.views.home', name='home'),
url(r'^products/', include('product.urls', namespace='product')),
url(r'^order/', include('order.urls', namespace='order')),
url(r'^cart/', include('cart.urls', namespace='cart')),
+ url(r'^account/', include('registration.backends.default.urls')),
)
diff --git a/setup.py b/setup.py
index f751634992..deaacef0d4 100755
--- a/setup.py
+++ b/setup.py
@@ -40,12 +40,14 @@ setup(
'django-prices>=2013.1',
'satchless>=2013.2a',
'South>=0.7.6',
- 'unidecode'],
+ 'unidecode',
+ 'django-registration==0.8'],
extras_require={
'lint': ['pylint==0.26.0', 'django-lint==dev']},
dependency_links=[
'http://github.com/mirumee/satchless/tarball/django-removal#egg=satchless-2013.2a',
- 'http://github.com/lamby/django-lint/tarball/master#egg=django-lint-dev'],
+ 'http://github.com/lamby/django-lint/tarball/master#egg=django-lint-dev',
+ 'https://bitbucket.org/LinnTroll/django-registration-1.5/get/c71d5b8e2735.zip#egg=django-registration-0.8'],
entry_points={
'console_scripts': ['saleor = saleor:manage']},
cmdclass={
diff --git a/userprofile/models.py b/userprofile/models.py
index eaae50bbce..62acc77870 100644
--- a/userprofile/models.py
+++ b/userprofile/models.py
@@ -1,3 +1,4 @@
+from django.core.mail import send_mail
from django.contrib.auth.hashers import (check_password, make_password,
is_password_usable)
from django.contrib.auth.models import BaseUserManager
@@ -9,9 +10,9 @@ from saleor.countries import COUNTRY_CHOICES
class Address(models.Model):
user = models.ForeignKey('User', related_name='addressbook')
- alias = models.CharField(_('short alias'), max_length=30,
- default=_('Home'),
- help_text=_('User-defined alias which identifies this address'))
+ alias = models.CharField(
+ _('short alias'), max_length=30, default=_('Home'),
+ help_text=_('User-defined alias which identifies this address'))
first_name = models.CharField(_('first name'),
max_length=256, blank=True)
last_name = models.CharField(_('last name'),
@@ -29,7 +30,6 @@ class Address(models.Model):
max_length=128)
phone = models.CharField(_('phone number'), max_length=30, blank=True)
-
class Meta:
unique_together = ('user', 'alias')
@@ -123,3 +123,9 @@ class User(models.Model):
def has_usable_password(self):
return is_password_usable(self.password)
+
+ def email_user(self, subject, message, from_email=None):
+ """
+ Sends an email to this User.
+ """
+ send_mail(subject, message, from_email, [self.email])