Commit 4e3758ce authored by Adrián Ribao's avatar Adrián Ribao
Browse files

Initial commit

parents
*.pyc
.project
.pydevproject
*.swp
env/
.ropeproject
.sass-cache
.coverage
.noseids
#coding=utf-8
from django.contrib.gis import admin
#from perfiles.models import Activacion
#class ActivacionAdmin(admin.ModelAdmin):
#pass
#admin.site.register(Activacion, ActivacionAdmin)
#coding=utf-8
from django.conf.urls.defaults import *
from django.views.generic.simple import direct_to_template
from perfiles.urls import urlpatterns as baseurlpatterns
from perfiles.backends.confirmationemail.views import Activate, CreateUser
urlpatterns = patterns('',
url(r'^register/$',
CreateUser.as_view(),
name='register'
),
url(r'^activation-sent/$',
direct_to_template,
{'template':'registration/confirmationemail/activation-sent.html',},
name='activation-sent'
),
url(r'^activate/(.+)/$',
Activate.as_view(),
name='activate'
),
)
urlpatterns += patterns('',
url(r'^', include(baseurlpatterns)),
)
# -*- coding: utf-8 -*-
"""
This backend creates a deactivated user, and sends an email with the confirmation code.
"""
from perfiles.views import CreateUserBase
from django.template import Context, loader
#from django.core.signing import TimestampSigner, BadSignature, SignatureExpired
from django.core import signing
from django.contrib.auth.models import User
from django.http import HttpResponseRedirect, Http404
from django.core.urlresolvers import reverse
from django.views.generic.base import TemplateView
from django.shortcuts import get_object_or_404
#from templated_email import send_templated_mail
from django.core.mail import send_mail
from django.contrib.sites.models import Site
import logging
logger = logging.getLogger(__name__)
class CreateUser(CreateUserBase):
signer = signing.TimestampSigner(salt='registerkey')
def _send_activation_email(self, user):
signed_key = self.signer.sign(user.username)
site = Site.objects.get_current()
url = reverse('activate', args=[signed_key,])
full_url = 'http://%s%s' % (site.domain, url)
t = loader.get_template('mails/activation.txt')
data = {
'url': full_url,
'site': site,
}
content = t.render(Context(data))
send_mail('Activation', content, 'from@adrima.es',
['to@example.com'], fail_silently=False)
#context ={
#}
#send_templated_mail(
#template_name='default',
##from_email='from@example.com',
#recipient_list=[user.email,],
#context=context,
#)
#signed_key = self.signer.sign(user.username)
#print signed_key
def response_after_success(self):
"""
Response returned after the object has been saved.
"""
url = reverse('activation-sent')
return HttpResponseRedirect(url)
def save_user(self, form):
data = form.cleaned_data
user = User.objects.create_user(data['username'], data['email'], data['password'])
user.is_active = False
user.first_name = data['first_name']
user.last_name = data['last_name']
user.save()
# Send the activation email
self._send_activation_email(user)
return user
#SignatureExpired
#try:
#... original = signer.unsign(value)
#... except signing.BadSignature:
#... print "Tampering detected!"
class Activate(TemplateView):
signer = signing.TimestampSigner(salt='registerkey')
template_name = 'registration/confirmationemail/activate.html'
def dispatch(self, request, *args, **kwargs):
key = args[0]
try:
username = self.signer.unsign(key, max_age=3600*24*7)
except signing.BadSignature:
logger.critical('Bad signature with the key: %s' % (key, ))
raise Http404
except signing.SignatureExpired:
logger.info('Signature expired for the user %s' % (username, ))
raise Http404
user = get_object_or_404(User, username=username)
user.is_active=True
user.save()
return super(Activate, self).dispatch(request, *args, **kwargs)
#coding=utf-8
from django.conf.urls.defaults import *
from perfiles.urls import urlpatterns as baseurlpatterns
from perfiles.backends.simple.views import CreateUser
urlpatterns = patterns('',
url(r'^register/$',
CreateUser.as_view(),
name='register'
),
)
urlpatterns += patterns('',
url(r'^', include(baseurlpatterns)),
)
# -*- coding: utf-8 -*-
"""
This backend just create the user
"""
from perfiles.views import CreateUserBase
from django.contrib.auth.models import User
class CreateUser(CreateUserBase):
def save_user(self, form):
data = form.cleaned_data
user = User.objects.create_user(data['username'], data['email'], data['password'])
user.is_active = True
user.first_name = data['first_name']
user.last_name = data['last_name']
user.save()
return user
# -*- coding: utf-8 -*-
from django.contrib.auth.models import User
from django import forms
from django.utils.translation import ugettext_lazy as _
class CreateUserForm(forms.ModelForm):
password = forms.CharField(widget=forms.PasswordInput, label=_(u'Password'))
password_confirm = forms.CharField(widget=forms.PasswordInput, label=_(u'Confirm the password'))
class Meta:
model = User
fields = ('username', 'first_name', 'last_name', 'email')
def clean_password_confirm(self):
if self.cleaned_data.get('password') and self.cleaned_data.get('password_confirm') and self.cleaned_data['password'] != self.cleaned_data['password_confirm']:
raise forms.ValidationError(_(u"The passwords don't match"))
return self.cleaned_data
#coding=utf-8
from django.db import models
#from django.contrib.auth.models import User
#class Activacion(models.Model):
#user = models.ForeignKey(User, unique=True)
#uuid = models.CharField(unique=True, db_index=True, max_length=100)
#expires = models.DateTimeField()
# -*- coding: utf-8 -*-
{% extends "index.html" %}
{% load i18n %}
{% block title %}{% trans "Registration" %}{% endblock %}
{% block css %}
{{ block.super }}
{% endblock %}
{% block js %}
{{ block.super }}
{% endblock %}
{% block content %}
{% endblock %}
Activate your account in {{ site.name }} clicking in the following url:
{{ url }}
Regards,
The {{ site.name }} team.
{% extends "base/registration_base.html" %}
{% load i18n %}
{% block title %}{% trans "Activate your account" %}{% endblock %}
{% block content %}
<p>{% trans "Your account has been activated" %}</p>
{% endblock %}
{% extends "base/registration_base.html" %}
{% load i18n %}
{% block title %}{% trans "Activation sent" %}{% endblock %}
{% block content %}
<p>{% trans "The activation email has been sent" %}</p>
{% endblock %}
{% extends "base/registration_base.html" %}
{% load i18n %}
{% block title %}{% trans "Login" %}{% endblock %}
{% block content %}
<div id="socialConnect">
<p class="linkedin"><img src="{{ STATIC_URL }}graphics/icons/aquaticus.social/60X60/linkedin.png" alt="{% trans "Linkedin" %}"/><a href="{% url socialauth_begin 'linkedin' %}">{% trans "Entra con tu cuenta de Linkedin" %}</a></p>
<p class="google"><img src="{{ STATIC_URL }}graphics/icons/aquaticus.social/60X60/google.png" alt="{% trans "Google" %}"/><a href="{% url socialauth_begin 'google' %}">{% trans "Entra con tu cuenta de Google" %}</a></p>
<p class="twitter"><img src="{{ STATIC_URL }}graphics/icons/aquaticus.social/60X60/twitter.png" alt="{% trans "Twitter" %}"/><a href="{% url socialauth_begin 'twitter' %}">{% trans "Entra con tu cuenta de Twitter" %}</a></p>
</div>
<div id="loginForm">
<form method="post" action="{% url auth_login %}">
{% csrf_token %}
<table>
{{ form }}
</table>
{% if next %}
<input type="hidden" name="next" value="{% if next %}{{ next }}{% endif %}" />
{% endif %}
<input type="submit" name="login" value="{% trans "login" %}"/>
</form>
<p class="register"><a href="{% url register %}">{% trans "Regístrate en CossioEmplea" %}</a></p>
</div>
{% endblock %}
{% extends "base/registration_base.html" %}
{% load i18n %}
{% block title %}{% trans "Logout" %}{% endblock %}
{% block content %}
<p>{% trans "You are logged out." %}</p>
<a href="/" class="back">{% trans "Go back to the home page" %}</a>
{% endblock %}
{% extends "base/registration_base.html" %}
{% load i18n %}
{% block title %}{% trans "Register an account" %}{% endblock %}
{% block content %}
<form method="post" action="">
{% csrf_token %}
<table>
{{ form }}
</table>
<input type="submit" name="register" value="{% trans "Send" %}"/>
</form>
{% endblock %}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment