Create user and login user forms are now active.
--- a/src/hashcut/templates/bpi_mashup_edit.html Fri Nov 30 17:05:15 2012 +0100
+++ b/src/hashcut/templates/bpi_mashup_edit.html Sat Dec 01 23:48:11 2012 +0100
@@ -275,7 +275,7 @@
return newurl;
};
var hashcut = IriSP.editor({
- creator: "{{creator}}",
+ creator: "{{user.username}}",
csrf_token: "{{csrf_token}}",
filter: {
tags__icontains: "BPI"
--- a/src/hashcut/templates/bpi_mashup_home.html Fri Nov 30 17:05:15 2012 +0100
+++ b/src/hashcut/templates/bpi_mashup_home.html Sat Dec 01 23:48:11 2012 +0100
@@ -65,7 +65,7 @@
<div class="video-item">
{% if m1 %}
<a href="{% url mashup_hashcut branding=branding ldt_id=m1.project.ldt_id %}" class="screenshot">{% thumbnail m1.project.image "302x202" crop="center" format="PNG" as im %}<img src="{{ im.url }}" width="{{ im.width }}" height="{{ im.height }}" alt=""/>{% empty %} {% endthumbnail %}</a>
- <h3><a class="title" href="{% url mashup_hashcut branding=branding ldt_id=m2.project.ldt_id %}">{{ m1.project.title }}</a> par <a class="author" href="{% url mashup_profile branding=branding username=m1.creator %}">{{ m1.creator }}</a> | <span class="duration">02:24</span> </h3>
+ <h3><a class="title" href="{% url mashup_hashcut branding=branding ldt_id=m1.project.ldt_id %}">{{ m1.project.title }}</a> par <a class="author" href="{% url mashup_profile branding=branding username=m1.creator %}">{{ m1.creator }}</a> | <span class="duration">02:24</span> </h3>
{% endif %}
</div>
<div class="video-item">
--- a/src/hashcut/templates/iri_mashup_edit.html Fri Nov 30 17:05:15 2012 +0100
+++ b/src/hashcut/templates/iri_mashup_edit.html Sat Dec 01 23:48:11 2012 +0100
@@ -275,7 +275,7 @@
return newurl;
};
var hashcut = IriSP.editor({
- creator: "{{creator}}",
+ creator: "{{user.username}}",
csrf_token: "{{csrf_token}}",
filter: {
tags__icontains: "BPI"
--- a/src/hashcut/templates/iri_mashup_home.html Fri Nov 30 17:05:15 2012 +0100
+++ b/src/hashcut/templates/iri_mashup_home.html Sat Dec 01 23:48:11 2012 +0100
@@ -64,7 +64,7 @@
<div class="video-item">
{% if m1 %}
<a href="{% url mashup_hashcut branding=branding ldt_id=m1.project.ldt_id %}" class="screenshot">{% thumbnail m1.project.image "302x202" crop="center" format="PNG" as im %}<img src="{{ im.url }}" width="{{ im.width }}" height="{{ im.height }}" alt=""/>{% empty %} {% endthumbnail %}</a>
- <h3><a class="title" href="{% url mashup_hashcut branding=branding ldt_id=m2.project.ldt_id %}">{{ m1.project.title }}</a> par <a class="author" href="{% url mashup_profile branding=branding username=m1.creator %}">{{ m1.creator }}</a> | <span class="duration">02:24</span> </h3>
+ <h3><a class="title" href="{% url mashup_hashcut branding=branding ldt_id=m1.project.ldt_id %}">{{ m1.project.title }}</a> par <a class="author" href="{% url mashup_profile branding=branding username=m1.creator %}">{{ m1.creator }}</a> | <span class="duration">02:24</span> </h3>
{% endif %}
</div>
<div class="video-item">
--- a/src/hashcut/templates/partial/bpi_mashup_popin_user.html Fri Nov 30 17:05:15 2012 +0100
+++ b/src/hashcut/templates/partial/bpi_mashup_popin_user.html Sat Dec 01 23:48:11 2012 +0100
@@ -3,11 +3,13 @@
<div class="popin user info" id="user">
<div class="pointer"></div>
<div class="popin-content">
- <h2>{{creator}}</h2>
+ {% if user.is_authenticated %}
+ <h2>{{user.username}}</h2>
<h3>{{email_creator}}</h3>
- <a href="{% url mashup_profile branding=branding username=creator %}" class="nb-hashcut">{{nb_mashup_creator}} Hashcuts</a>
+ <a href="{% url mashup_profile branding=branding username=user.username %}" class="nb-hashcut">{{nb_mashup_creator}} Hashcuts</a>
+ {% else %}<h2>Vous n'êtes pas identifié. Veuillez vous logguer.</h2>{% endif %}
<p>
- <a href="#" class="change-account button">Changer de compte</a>
+ <a href="#" class="change-account button">{% if user.is_authenticated %}Changer de compte{% else %}Se connecter{% endif %}</a>
</p>
</div>
</div><!-- popin user info-->
@@ -16,22 +18,23 @@
<div class="pointer"></div>
<div class="popin-content">
<h2>Créer un compte :</h2>
- <form action="#" class="signup-form">
+ <form method="post" action="{% url mashup_create_user branding=branding %}" class="signup-form">
+ {% csrf_token %}
<p>
<label for="signup-pseudo">Pseudonyme : </label>
- <input type="text" id="signup-pseudo" name="" />
+ <input type="text" id="signup-pseudo" name="signup-pseudo" />
</p>
<p >
<label for="signup-email">Email : </label>
- <input type="text" id="signup-email" name="" />
+ <input type="text" id="signup-email" name="signup-email" />
</p>
<p >
<label for="signup-password">Mot de passe : </label>
- <input type="password" id="signup-password" name="" />
+ <input type="password" id="signup-password" name="signup-password" />
</p>
<p>
<label for="signup-password">Confirmer le mot de passe : </label>
- <input type="password" id="signup-password" name="" />
+ <input type="password" id="signup-confirm-password" name="signup-confirm-password" />
</p>
<p>
<input class="button" type="submit" value="Créer le compte">
@@ -45,14 +48,15 @@
<div class="pointer"></div>
<div class="popin-content">
<h2>Connexion :</h2>
- <form action="#" class="login-form">
+ <form method="post" action="{% url mashup_identicate_user branding=branding %}" class="login-form">
+ {% csrf_token %}
<p>
- <label for="signup-pseudo">E-mail : </label>
- <input type="text" id="signup-pseudo" name="" />
+ <label for="signup-pseudo">Pseudonyme : </label>
+ <input type="text" id="signup-pseudo" name="signup-pseudo" />
</p>
<p >
- <label for="signup-email">Mot de passe : </label>
- <input type="password" id="signup-email" name="" />
+ <label for="signup-password">Mot de passe : </label>
+ <input type="password" id="signup-password" name="signup-password" />
</p>
<p>
<input class="button" type="submit" value="Se connecter">
--- a/src/hashcut/templates/partial/iri_mashup_popin_user.html Fri Nov 30 17:05:15 2012 +0100
+++ b/src/hashcut/templates/partial/iri_mashup_popin_user.html Sat Dec 01 23:48:11 2012 +0100
@@ -3,11 +3,13 @@
<div class="popin user info" id="user">
<div class="pointer"></div>
<div class="popin-content">
- <h2>{{creator}}</h2>
+ {% if user.is_authenticated %}
+ <h2>{{user.username}}</h2>
<h3>{{email_creator}}</h3>
- <a href="{% url mashup_profile branding=branding username=creator %}" class="nb-hashcut">{{nb_mashup_creator}} Hashcuts</a>
+ <a href="{% url mashup_profile branding=branding username=user.username %}" class="nb-hashcut">{{nb_mashup_creator}} Hashcuts</a>
+ {% else %}<h2>Vous n'êtes pas identifié. Veuillez vous logguer.</h2>{% endif %}
<p>
- <a href="#" class="change-account button">Changer de compte</a>
+ <a href="#" class="change-account button">{% if user.is_authenticated %}Changer de compte{% else %}Se connecter{% endif %}</a>
</p>
</div>
</div><!-- popin user info-->
@@ -16,22 +18,23 @@
<div class="pointer"></div>
<div class="popin-content">
<h2>Créer un compte :</h2>
- <form action="#" class="signup-form">
+ <form method="post" action="{% url mashup_create_user branding=branding %}" class="signup-form">
+ {% csrf_token %}
<p>
<label for="signup-pseudo">Pseudonyme : </label>
- <input type="text" id="signup-pseudo" name="" />
+ <input type="text" id="signup-pseudo" name="signup-pseudo" />
</p>
<p >
<label for="signup-email">Email : </label>
- <input type="text" id="signup-email" name="" />
+ <input type="text" id="signup-email" name="signup-email" />
</p>
<p >
<label for="signup-password">Mot de passe : </label>
- <input type="password" id="signup-password" name="" />
+ <input type="password" id="signup-password" name="signup-password" />
</p>
<p>
<label for="signup-password">Confirmer le mot de passe : </label>
- <input type="password" id="signup-password" name="" />
+ <input type="password" id="signup-confirm-password" name="signup-confirm-password" />
</p>
<p>
<input class="button" type="submit" value="Créer le compte">
@@ -45,14 +48,15 @@
<div class="pointer"></div>
<div class="popin-content">
<h2>Connexion :</h2>
- <form action="#" class="login-form">
+ <form method="post" action="{% url mashup_identicate_user branding=branding %}" class="login-form">
+ {% csrf_token %}
<p>
- <label for="signup-pseudo">E-mail : </label>
- <input type="text" id="signup-pseudo" name="" />
+ <label for="signup-pseudo">Pseudonyme : </label>
+ <input type="text" id="signup-pseudo" name="signup-pseudo" />
</p>
<p >
- <label for="signup-email">Mot de passe : </label>
- <input type="password" id="signup-email" name="" />
+ <label for="signup-password">Mot de passe : </label>
+ <input type="password" id="signup-password" name="signup-password" />
</p>
<p>
<input class="button" type="submit" value="Se connecter">
--- a/src/hashcut/urls.py Fri Nov 30 17:05:15 2012 +0100
+++ b/src/hashcut/urls.py Sat Dec 01 23:48:11 2012 +0100
@@ -1,5 +1,6 @@
from django.conf.urls.defaults import patterns, url
-from hashcut.views import MashupHome, MashupEdit, MashupHashcut, MashupContent, MashupProfile, MashupAllMashups
+from hashcut.views import MashupHome, MashupEdit, MashupHashcut, MashupContent, MashupProfile, MashupAllMashups,\
+ MashupCreateUser, MashupIdenticateUser
urlpatterns = patterns('',
url(r'^(?P<branding>.*)/edit/$', MashupEdit.as_view(), name="mashup_edit"),
@@ -8,6 +9,8 @@
url(r'^(?P<branding>.*)/media/(?P<ctt_id>.*)/$', MashupContent.as_view(), name="mashup_content"),
url(r'^(?P<branding>.*)/profile/(?P<username>.*)/$', MashupProfile.as_view(), name="mashup_profile"),
url(r'^(?P<branding>.*)/all/$', MashupAllMashups.as_view(), name="mashup_all"),
+ url(r'^(?P<branding>.*)/createuser/$', MashupCreateUser.as_view(), name="mashup_create_user"),
+ url(r'^(?P<branding>.*)/iduser/$', MashupIdenticateUser.as_view(), name="mashup_identicate_user"),
url(r'^(?P<branding>.*)/$', MashupHome.as_view(), name="mashup_home"),
url(r'^$', MashupHome.as_view()),
)
--- a/src/hashcut/views.py Fri Nov 30 17:05:15 2012 +0100
+++ b/src/hashcut/views.py Sat Dec 01 23:48:11 2012 +0100
@@ -1,13 +1,15 @@
from django.conf import settings
+from django.contrib.auth import authenticate, login
from django.core.exceptions import ImproperlyConfigured, ObjectDoesNotExist
from django.core.paginator import Paginator, InvalidPage, EmptyPage
-from django.http import HttpResponseNotFound
+from django.http import HttpResponseNotFound, HttpResponse
from django.views.generic.base import View, TemplateResponseMixin
from ldt.api.ldt.resources import ProjectResource
from ldt.ldt_utils.models import Project, Content
import logging
from hashcut.models import Mashup, Branding
from django.contrib.auth.models import User
+from django.shortcuts import redirect
class MashupContextView(View):
@@ -16,10 +18,8 @@
def get_context_dict(self, request):
context = {}
context["branding"] = self.branding
- context["creator"] = ""
- context["nb_mashup_creator"] = ""
- if request and request.user:
- context["creator"] = request.user.username
+ context["nb_mashup_creator"] = "0"
+ if request and request.user and isinstance(request.user, User):
if not self.branding or self.branding=="":
self.branding = "iri"
brd = Branding.objects.get(name=self.branding)
@@ -281,5 +281,57 @@
context = self.get_context_dict(request)
context.update({"results":results})
return self.render_to_response(context)
+
+
+
+class MashupCreateUser(MashupHome):
+
+ def get(self, request, branding="iri", **kwargs):
+ return redirect('mashup_home', branding=branding)
+
+ def post(self, request, branding="iri", **kwargs):
+ if request.method == "POST":
+ u_username = request.POST["signup-pseudo"]
+ u_email = request.POST["signup-email"]
+ u_pwd1 = request.POST["signup-password"]
+ u_pwd2 = request.POST["signup-confirm-password"]
+ if u_pwd1 == "" or u_pwd1 != u_pwd2:
+ return HttpResponse("Password don't match.")
+ u = None
+ try:
+ u = User.objects.get(username=u_username)
+ except User.DoesNotExist:
+ pass
+ if u:
+ return HttpResponse("Username already exists.")
+ u = User.objects.create_user(u_username, u_email, u_pwd1)
+ u.save()
+ u_auth = authenticate(username=u.username, password=u_pwd1)
+ if u_auth:
+ login(request, u_auth)
+ else:
+ return HttpResponse("Problem in authentication. User and password don't match.")
+ return redirect('mashup_home', branding=branding)
+
+
+
+class MashupIdenticateUser(MashupHome):
+
+ def get(self, request, branding="iri", **kwargs):
+ return redirect('mashup_home', branding=branding)
+
+ def post(self, request, branding="iri", **kwargs):
+ if request.method == "POST":
+ u_username = request.POST["signup-pseudo"]
+ u_pwd = request.POST["signup-password"]
+ if u_username == "" or u_pwd == "":
+ return HttpResponse("User and password don't match.")
+ u_auth = authenticate(username=u_username, password=u_pwd)
+ if u_auth:
+ login(request, u_auth)
+ else:
+ return HttpResponse("Problem in authentication. User and password don't match.")
+ return redirect('mashup_home', branding=branding)
+
\ No newline at end of file