Exemplo n.º 1
0
def view_profil(request, user_pk, template_name='accounts/profil_view.html'):
    u = get_object_or_404(User, pk=user_pk)
    p = None
    try:
        p = u.get_profile()
    except Profil.DoesNotExist:
        p = Profil(user=u)
        p.save()

    return render_to_response(template_name, RequestContext(request, {'profil': p, 'p': p,}))
Exemplo n.º 2
0
def create_new_user(request, template_name="accounts/user_create_form.html"):
    form = CustomUserCreationForm()
    # if form was submitted, bind form instance.
    if request.method == "POST":
        form = CustomUserCreationForm(request.POST)
        if form.is_valid():
            user = form.save(commit=False)
            # user must be active for login to work
            user.is_active = True
            user.email = request.POST.get("email")
            user.first_name = request.POST.get("first_name")
            user.last_name = request.POST.get("last_name")
            user.save()
            p = Profil(user=user)
            p.last_known_activity = LogActivity.getDefault()
            p.save()

            from_email = "Les Cannes A L'air <*****@*****.**>"
            text = (
                "Nouvel inscrit chez les CAL : %s %s (%s)<br><br>L'invalidation du compte peut se faire <a href='http://cannesalair.fr/admin/auth/user/%s/'>ici</a>."
                % (user.first_name, user.last_name, user.email, user.id)
            )
            to_users = User.objects.filter(groups__name="Admin")
            from core.mail import internal_sendmail

            internal_sendmail(
                ",".join([u.email for u in to_users]),
                from_email,
                text,
                "[CAL] %s vient de s'inscrire sur le site des CAL" % user.username,
                fail_silently=False,
            )
            return HttpResponseRedirect(reverse("editprofil"))

    for f in form.fields:
        if not f == "captcha":
            form.fields[f].widget.attrs["class"] = "input-medium"
        form.fields[f].help_text = ""
    return render_to_response(template_name, RequestContext(request, {"form": form, "isstandalone": True}))
Exemplo n.º 3
0
    def post(self, request):
        form = ProfilForm(request.POST)

        if form.is_valid():

            data = form.cleaned_data
            email = self.getAttribute("email", data)
            password = self.getAttribute("password", data)
            confirm_password = self.getAttribute("confirm_password", data)
            user_exist = User.objects.filter(username=email)
            profil = Profil.objects.all().filter(email=email)

            if user_exist.count() == 0:
                if password and (password == confirm_password):
                    user = User()
                    user.username = email
                    user.first_name = self.getAttribute("first_name", data)
                    user.last_name = self.getAttribute("last_name", data)

                    user.email = email
                    user.is_active = True
                    user.set_password(password)
                    user.save()

                    if profil.count() == 1:
                        profil = profil[0]
                    else:
                        profil = Profil()
                    profil.user = user
                    profil.first_name = self.getAttribute("first_name", data)
                    profil.last_name = self.getAttribute("last_name", data)

                    profil.type = self.getAttribute("type", data)
                    profil.email = email

                    profil.gender = self.getAttribute("gender", data)

                    token_profil = self.createToken()
                    profil.token = token_profil

                    profil.sendMail({
                        "token": profil.token,
                        "first_name": user.first_name,
                        "last_name": user.last_name
                    })
                    profil.save()

                    photo_base64 = data["photo_base64"]
                    if not photo_base64 == "" and not photo_base64 == "photo":
                        format, imgstr = photo_base64.split(';base64,')
                        ext = format.split('/')[-1]
                        data_file = ContentFile(base64.b64decode(imgstr))
                        file_name = str(profil.id) + "." + ext
                        profil.photo.save(file_name, data_file, save=True)

                    id = str(profil.id)

                    if profil.type == "author":

                        url = "/account/create-author-account/?profil=" + id
                        return redirect(url)

                    return redirect('/account/custom-centres/' + id + "/")
                    #return redirect('/account/complete-profil/')
            else:
                return render(
                    request, self.template_name, {
                        "form": form,
                        "message":
                        "Un profil avec meme adresse email existe deja"
                    })

        return render(request, self.template_name, {"form": form})
Exemplo n.º 4
0
def edit_profil(request, template_name="accounts/edit_profil_form.html"):
    """
    Simple profile form.
    """
    user = request.user
    p = None
    try:
        p = user.get_profile()
    except Profil.DoesNotExist:
        p = Profil(user=user)
        p.save()

    if request.POST:
        is_valid = False
        new_user_form = UserModificationForm(request.POST, instance=user)
        new_profil_form = ProfilForm(request.POST, instance=p)
        new_avatar_form = AvatarForm(request.POST)
        new_password_form = CustomPasswordChangeForm(user=user, data=request.POST)

        is_valid = (
            new_user_form.is_valid()
            and new_profil_form.is_valid()
            and new_avatar_form.is_valid()
            and new_password_form.is_valid()
        )

        if is_valid:
            new_user = new_user_form.save(commit=False)
            new_user.save()

            new_profil = new_profil_form.save(commit=False)
            new_profil.save()

            new_profil.suivre_les_sorties_partype.clear()
            for activite in Activite.objects.filter(pk__in=request.POST.getlist("suivre_les_sorties_partype")):
                new_profil.suivre_les_sorties_partype.add(activite)

            if (
                request.POST.get("old_password")
                and request.POST.get("new_password1")
                and request.POST.get("new_password1")
            ):
                new_password_form.save()

            p.gravatarurl = new_avatar_form.cleaned_data["gravatarurl"]
            title = "Avatar for user %s" % user.username
            if request.FILES.get("avatar"):
                title_slug = "avatar-%s" % user.username
                filename = "avatars/%s" % str(request.FILES.get("avatar"))
                photos = Photo.objects.filter(image=filename)
                photo = None
                if photos.count() > 0:
                    photo = photos[0]
                if not photo:
                    Photo.objects.filter(title_slug=title_slug).delete()
                    photo = Photo(title=title, title_slug=title_slug, is_public=False, tags="avatar")
                    photo.image.save(filename, ContentFile(request.FILES.get("avatar").read()))
                    photo.save()
                p.avatar = photo
            p.save()
            return HttpResponseRedirect(reverse("editprofil"))
        else:
            userform = new_user_form
            profilform = new_profil_form
            avatarform = new_avatar_form
            passwordform = new_password_form
    else:
        userform = UserModificationForm(instance=user)
        profilform = ProfilForm(instance=p)
        avatarform = AvatarForm(initial={"gravatarurl": p.gravatarurl})
        passwordform = CustomPasswordChangeForm(user=user)

    context = RequestContext(
        request,
        {
            "p": p,
            "profilform": profilform,
            "userform": userform,
            "avatarform": avatarform,
            "passwordform": passwordform,
            "full": True,
        },
    )
    return render_to_response(template_name, context)
Exemplo n.º 5
0
    def post(self, request):
        form = ProfilForm(request.POST)

        if form.is_valid():

            data = form.cleaned_data
            email = self.getAttribute("email", data)
            password = self.getAttribute("password", data)
            confirm_password = self.getAttribute("confirm_password", data)
            user_exist = User.objects.filter(username=email)
            user = User()
            profil = Profil.objects.all().filter(email=email)

            if user_exist.count() == 0:
                if password and (password == confirm_password):
                    user = User()
                    user.username = email
                    user.first_name = self.getAttribute("first_name", data)
                    user.last_name = self.getAttribute("last_name", data)
                    user.email = email
                    user.is_active = True
                    user.set_password(password)
                    user.save()

                    if profil.count() == 1:
                        profil = profil[0]
                    else:
                        profil = Profil()
                    profil.user = user
                    profil.first_name = self.getAttribute("first_name", data)
                    profil.last_name = self.getAttribute("last_name", data)
                    profil.email = email

                    profil.gender = self.getAttribute("gender", data)
                    profil.type = "user"

                    token_profil = self.createToken()
                    profil.token = token_profil
                    profil.sendMail({
                        "token": profil.token,
                        "first_name": user.first_name,
                        "last_name": user.last_name
                    })
                    profil.save()

                    #return redirect('/account/complete-profil/')
                    return redirect('/account/custom-centres/' + profil.id +
                                    "/")
            else:
                return render(
                    request, self.template_name, {
                        "form": form,
                        "message":
                        "Un profil avec meme adresse email existe deja"
                    })

        return render(request, self.template_name, {"form": form})