Exemplo n.º 1
0
def facebook_registration(request):
    data = request.POST

    password = "".join(random.choice(string.ascii_lowercase + string.digits) for x in range(6))

    is_user = get_object_or_None(User, email=data["email"])

    if not is_user:
        username = "".join(random.choice(string.ascii_lowercase + string.digits) for x in range(16))
        new_user = User.objects.create_user(
            username=username, first_name=data["name"], email=data["email"], password=password, related_with="salons"
        )
        salon = Salon.objects.create(user=new_user, facebook_id=data["facebook_id"], step=2)
        ReceiverAccount.objects.create(user=new_user, paypal_email=new_user.email)

        hash_name = "".join(random.choice(string.ascii_lowercase + string.digits) for x in range(10))
        path = "/" + MEDIA_FOLDER + "/salons/" + str(salon.id) + "/avatar/" + hash_name + ".jpeg"
        full_path = MEDIA_ROOT + "salons/" + str(salon.id) + "/avatar/" + hash_name + ".jpeg"
        d = os.path.dirname(full_path)
        if not os.path.exists(d):
            os.makedirs(d)
        else:
            shutil.rmtree(d)
            os.makedirs(d)
        urllib.request.urlretrieve(data["avatar"], full_path)

        salon.avatar = path
        salon.save()

        welcome(None, new_user, password)

        login_user(request, new_user)
    else:
        raise Exception(_("Not registered"))
Exemplo n.º 2
0
def sign_up(request):
    if request.GET.get("step") == "2":
        if request.method == "POST":

            form = LocationSalonDetails(request.POST)

            if form.is_valid():
                data = form.cleaned_data
                Salon.objects.filter(user=request.user).update(lat=data["lat"], lng=data["lng"], step=0)
                return HttpResponseRedirect(reverse("salons_profile") + "?show_hint=1")
        else:
            form = LocationSalonDetails()
    else:
        if request.method == "POST":

            request.GET.get("step")
            form = SalonForm(request.POST)

            if form.is_valid():
                data = form.cleaned_data
                form.save()
                user = authenticate(email=data["email"], password=data["password"])
                artist = Salon.objects.create(user=user)
                ReceiverAccount.objects.create(user=user, paypal_email=user.email)

                if user is not None and user.is_active:
                    artist.step = 2
                    artist.save()
                    auth_login(request, user)
                    welcome(None, receiver=user)
                    return HttpResponseRedirect(reverse("salons_sign_up") + "?step=2")
        else:
            form = SalonForm()

    return render(request, "salons/sign_up.html", {"form": form})
Exemplo n.º 3
0
def facebook_registration(request):
    data = request.POST

    password = ''.join(random.choice(string.ascii_lowercase + string.digits) for x in range(6))

    is_user = get_object_or_None(User, email=data['email'])
    if not is_user:
        username = ''.join(random.choice(string.ascii_lowercase + string.digits)for x in range(16))
        new_user = User.objects.create_user(username=username,
                                            first_name=data['name'],
                                            email=data['email'],
                                            password=password,
                                            related_with="profiles")
        profile = Profile.objects.create(user=new_user, facebook_id=data['facebook_id'], is_activated=True)

        hash_name = ''.join(random.choice(string.ascii_lowercase + string.digits)for x in range(10))
        path = '/' + MEDIA_FOLDER + '/users/' + str(profile.id) + '/avatar/' + hash_name + '.jpeg'
        full_path = MEDIA_ROOT + 'users/' + str(profile.id) + '/avatar/' + hash_name + '.jpeg'
        d = os.path.dirname(full_path)
        if not os.path.exists(d):
            os.makedirs(d)
        else:
            shutil.rmtree(d)
            os.makedirs(d)
        urllib.request.urlretrieve(data['avatar'], full_path)

        profile.avatar = path
        profile.save()
        kwargs = {}
        kwargs['password'] = password
        welcome(None, new_user, password)

        login_user(request, new_user)
    else:
        raise Exception("Not registered")
Exemplo n.º 4
0
def forgotten_password(request):
    if request.method == 'POST':
        form = ForgottenPasswordForm(request.POST)
        if form.is_valid():
            data = form.cleaned_data
            email = data.get('email', None)

            user = get_object_or_None(User, email=email)
            if user:
                welcome(None, user)

            return HttpResponseRedirect(reverse('home'))
    else:
        form = ForgottenPasswordForm()

    return render(request, 'user/forgotten_password.html', {'form': form})
Exemplo n.º 5
0
def facebook_registration(request):
    data = request.POST

    password = ''.join(
        random.choice(string.ascii_lowercase + string.digits)
        for x in range(6))

    is_user = get_object_or_None(User, email=data['email'])

    if not is_user:
        username = ''.join(
            random.choice(string.ascii_lowercase + string.digits)
            for x in range(16))
        new_user = User.objects.create_user(username=username,
                                            first_name=data['name'],
                                            email=data['email'],
                                            password=password,
                                            related_with="salons")
        salon = Salon.objects.create(user=new_user,
                                     facebook_id=data['facebook_id'],
                                     step=2)
        ReceiverAccount.objects.create(user=new_user,
                                       paypal_email=new_user.email)

        hash_name = ''.join(
            random.choice(string.ascii_lowercase + string.digits)
            for x in range(10))
        path = '/' + MEDIA_FOLDER + '/salons/' + str(
            salon.id) + '/avatar/' + hash_name + '.jpeg'
        full_path = MEDIA_ROOT + 'salons/' + str(
            salon.id) + '/avatar/' + hash_name + '.jpeg'
        d = os.path.dirname(full_path)
        if not os.path.exists(d):
            os.makedirs(d)
        else:
            shutil.rmtree(d)
            os.makedirs(d)
        urllib.request.urlretrieve(data['avatar'], full_path)

        salon.avatar = path
        salon.save()

        welcome(None, new_user, password)

        login_user(request, new_user)
    else:
        raise Exception(_("Not registered"))
Exemplo n.º 6
0
def sign_up(request):
    if request.GET.get("step") == '2':
        if request.method == "POST":

            form = LocationSalonDetails(request.POST)

            if form.is_valid():
                data = form.cleaned_data
                Salon.objects.filter(user=request.user).update(
                    lat=data["lat"],
                    lng=data["lng"],
                    step=0,
                )
                return HttpResponseRedirect(
                    reverse('salons_profile') + "?show_hint=1")
        else:
            form = LocationSalonDetails()
    else:
        if request.method == "POST":

            request.GET.get("step")
            form = SalonForm(request.POST)

            if form.is_valid():
                data = form.cleaned_data
                form.save()
                user = authenticate(email=data['email'],
                                    password=data['password'])
                artist = Salon.objects.create(user=user)
                ReceiverAccount.objects.create(user=user,
                                               paypal_email=user.email)

                if user is not None and user.is_active:
                    artist.step = 2
                    artist.save()
                    auth_login(request, user)
                    welcome(None, receiver=user)
                    return HttpResponseRedirect(
                        reverse('salons_sign_up') + "?step=2")
        else:
            form = SalonForm()

    return render(request, 'salons/sign_up.html', {'form': form})