fixed new user registration
This commit is contained in:
parent
ff9a6e1b2b
commit
6319515bb4
6 changed files with 68 additions and 17 deletions
|
@ -18,10 +18,10 @@ urlpatterns = [
|
||||||
|
|
||||||
# note the django CMS URLs included via i18n_patterns
|
# note the django CMS URLs included via i18n_patterns
|
||||||
urlpatterns += i18n_patterns('',
|
urlpatterns += i18n_patterns('',
|
||||||
url(r'^login',include(membership_urls)),
|
url(r'^login/',include(membership_urls)),
|
||||||
url(r'^admin/', include(admin.site.urls)),
|
url(r'^admin/', include(admin.site.urls)),
|
||||||
url(r'^digitalglarus/', include('digitalglarus.urls',
|
url(r'^digitalglarus/', include('digitalglarus.urls',
|
||||||
namespace="digitalglarus")),
|
namespace="digitalglarus"),name='digitalglarus'),
|
||||||
url(r'^', include('cms.urls')),
|
url(r'^', include('cms.urls')),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -1,13 +1,13 @@
|
||||||
from django.db import models
|
from django.db import models
|
||||||
from django.utils.translation import ugettext_lazy as _
|
from django.utils.translation import ugettext_lazy as _
|
||||||
from django.contrib.auth.models import User, AbstractBaseUser, BaseUserManager
|
from django.contrib.auth.models import User, AbstractBaseUser, BaseUserManager,AbstractUser
|
||||||
from django.contrib.auth.hashers import make_password
|
from django.contrib.auth.hashers import make_password
|
||||||
from django.core.mail import send_mail
|
from django.core.mail import send_mail
|
||||||
from django.core.validators import RegexValidator
|
from django.core.validators import RegexValidator
|
||||||
from django.contrib.auth.models import User
|
from django.contrib.auth.models import User
|
||||||
|
|
||||||
REGISTRATION_MESSAGE = {'subject': "Validation mail",
|
REGISTRATION_MESSAGE = {'subject': "Validation mail",
|
||||||
'message': 'Please validate Your account under this link http://localhost:8000/en-us/validate/{}',
|
'message': 'Please validate Your account under this link http://localhost:8000/en-us/login/validate/{}',
|
||||||
'from': 'test@test.com'}
|
'from': 'test@test.com'}
|
||||||
|
|
||||||
|
|
||||||
|
@ -21,10 +21,10 @@ class MyUserManager(BaseUserManager):
|
||||||
|
|
||||||
user = self.model(
|
user = self.model(
|
||||||
email=self.normalize_email(email),
|
email=self.normalize_email(email),
|
||||||
name=name
|
name=name,
|
||||||
|
password=password,
|
||||||
|
validation_slug=make_password(None)
|
||||||
)
|
)
|
||||||
|
|
||||||
user.set_password(password)
|
|
||||||
user.save(using=self._db)
|
user.save(using=self._db)
|
||||||
return user
|
return user
|
||||||
|
|
||||||
|
@ -32,9 +32,11 @@ class MyUserManager(BaseUserManager):
|
||||||
"""
|
"""
|
||||||
Creates and saves a superuser with the given email, name and password.
|
Creates and saves a superuser with the given email, name and password.
|
||||||
"""
|
"""
|
||||||
|
import ipdb;ipdb.set_trace()
|
||||||
user = self.create_user(email,
|
user = self.create_user(email,
|
||||||
password=password,
|
password=password,
|
||||||
name=name
|
name=name,
|
||||||
|
validation_slug=make_password(None)
|
||||||
)
|
)
|
||||||
user.is_admin = True
|
user.is_admin = True
|
||||||
user.save(using=self._db)
|
user.save(using=self._db)
|
||||||
|
@ -48,6 +50,11 @@ class CustomUser(AbstractBaseUser):
|
||||||
|
|
||||||
validated = models.IntegerField(choices=VALIDATED_CHOICES, default=0)
|
validated = models.IntegerField(choices=VALIDATED_CHOICES, default=0)
|
||||||
validation_slug = models.CharField(db_index=True, unique=True, max_length=50)
|
validation_slug = models.CharField(db_index=True, unique=True, max_length=50)
|
||||||
|
is_staff = models.BooleanField(
|
||||||
|
_('staff status'),
|
||||||
|
default=False,
|
||||||
|
help_text=_('Designates whether the user can log into this admin site.'),
|
||||||
|
)
|
||||||
|
|
||||||
objects = MyUserManager()
|
objects = MyUserManager()
|
||||||
|
|
||||||
|
@ -58,9 +65,8 @@ class CustomUser(AbstractBaseUser):
|
||||||
def register(cls, name, password, email):
|
def register(cls, name, password, email):
|
||||||
user = cls.objects.filter(email=email).first()
|
user = cls.objects.filter(email=email).first()
|
||||||
if not user:
|
if not user:
|
||||||
user = cls.objects.create_user(username=name, email=email, password=password)
|
user = cls.objects.create_user(name=name, email=email, password=password)
|
||||||
if user:
|
if user:
|
||||||
user.validation_slug = make_password(None)
|
|
||||||
send_mail(REGISTRATION_MESSAGE['subject'],
|
send_mail(REGISTRATION_MESSAGE['subject'],
|
||||||
REGISTRATION_MESSAGE['message'].format(user.validation_slug),
|
REGISTRATION_MESSAGE['message'].format(user.validation_slug),
|
||||||
REGISTRATION_MESSAGE['from'], [user.email], fail_silently=False)
|
REGISTRATION_MESSAGE['from'], [user.email], fail_silently=False)
|
||||||
|
@ -75,11 +81,12 @@ class CustomUser(AbstractBaseUser):
|
||||||
user = cls.objects.filter(validation_slug=validation_slug).first()
|
user = cls.objects.filter(validation_slug=validation_slug).first()
|
||||||
if user:
|
if user:
|
||||||
user.validated = 1
|
user.validated = 1
|
||||||
|
user.save()
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def is_superuser(self):
|
def is_superuser(self):
|
||||||
return True
|
return False
|
||||||
|
|
||||||
def is_admin(self):
|
def is_admin(self):
|
||||||
return True
|
return True
|
||||||
|
@ -96,6 +103,7 @@ class CustomUser(AbstractBaseUser):
|
||||||
return self.email
|
return self.email
|
||||||
|
|
||||||
def has_perm(self, perm, obj=None):
|
def has_perm(self, perm, obj=None):
|
||||||
|
print(perm)
|
||||||
"Does the user have a specific permission?"
|
"Does the user have a specific permission?"
|
||||||
# Simplest possible answer: Yes, always
|
# Simplest possible answer: Yes, always
|
||||||
return True
|
return True
|
||||||
|
|
|
@ -23,12 +23,11 @@
|
||||||
</div>
|
</div>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-md-12">
|
<div class="col-md-12">
|
||||||
<p class="text-center">Your last action was not complete.
|
<p class="text-center">Your last action was not complete. {{ msg }}
|
||||||
<br>Have problems? contact us at
|
<br>Have problems? contact us at
|
||||||
<a href="">help@digitalglarus.ch</a>
|
<a href="">help@digitalglarus.ch</a>
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<p>{{ msg }}</p>
|
|
||||||
|
|
||||||
<p></p>
|
<p></p>
|
||||||
</div>
|
</div>
|
||||||
|
@ -37,7 +36,7 @@
|
||||||
</div>
|
</div>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-md-12 text-center">
|
<div class="col-md-12 text-center">
|
||||||
<a class="btn btn-primary">Back</a>
|
<a class="btn btn-primary" href="{% url 'login' %}">Back</a>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<a hrefhelp@digitalglarus.ch<="" p="">
|
<a hrefhelp@digitalglarus.ch<="" p="">
|
||||||
|
|
|
@ -15,8 +15,13 @@
|
||||||
</div>
|
</div>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-md-12">
|
<div class="col-md-12">
|
||||||
<p class="text-center text-muted">Your password is sent to your email!
|
<p class="text-center text-muted">
|
||||||
<br>Check your email to activate your account.</p>
|
<br>Check your email to activate your account.</p>
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-md-12 text-center">
|
||||||
|
<a class="btn btn-primary" href="{% url 'login' %}">Back</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
39
membership/templates/validated_email.html
Normal file
39
membership/templates/validated_email.html
Normal file
|
@ -0,0 +1,39 @@
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||||
|
<script type="text/javascript" src="http://cdnjs.cloudflare.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>
|
||||||
|
<script type="text/javascript" src="http://netdna.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js"></script>
|
||||||
|
<link href="http://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.3.0/css/font-awesome.min.css" rel="stylesheet"
|
||||||
|
type="text/css">
|
||||||
|
<link href="http://pingendo.github.io/pingendo-bootstrap/themes/default/bootstrap.css" rel="stylesheet"
|
||||||
|
type="text/css">
|
||||||
|
{% if request.session.next == None %}
|
||||||
|
<script>
|
||||||
|
type = "text/javascript" >
|
||||||
|
setTimeout(function () {
|
||||||
|
window.location.href = "/";
|
||||||
|
}, 5000);
|
||||||
|
</script>
|
||||||
|
{% endif %}
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div class="section">
|
||||||
|
<div class="container">
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-md-12">
|
||||||
|
<h3 class="text-center text-muted">
|
||||||
|
{% if msg %}
|
||||||
|
Email verified!<br> <p>redirecting...</p>
|
||||||
|
{% else %}
|
||||||
|
<p>Email not verfied!</p>
|
||||||
|
{% endif %}
|
||||||
|
</h3>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
</body>
|
||||||
|
</html>
|
|
@ -13,9 +13,9 @@ from .payment import StripePayment
|
||||||
def validate_email(request, validate_slug):
|
def validate_email(request, validate_slug):
|
||||||
validated = CustomUser.validate_url(validate_slug)
|
validated = CustomUser.validate_url(validate_slug)
|
||||||
if validated:
|
if validated:
|
||||||
return render(request, 'templates/validated.html')
|
return render(request, 'templates/validated_email.html',{'msg':True})
|
||||||
else:
|
else:
|
||||||
return render(request, 'templates/error.html')
|
return render(request, 'templates/error.html',{'msg':'Validation failed.'})
|
||||||
|
|
||||||
def reset(request,time):
|
def reset(request,time):
|
||||||
request.session['next']=0
|
request.session['next']=0
|
||||||
|
|
Loading…
Reference in a new issue