예제 #1
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})
예제 #2
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})