Esempio n. 1
0
def api_createuser(request):
    code = 100
    data = {'code':code, 'error': 'Request Error'}
    
    if request.POST:
        if 'name' in request.POST and 'email' in request.POST and 'password' in request.POST:
            name = request.POST['name']
            email_x = request.POST['email']
            password = request.POST['password']
            
            email = email_x.lower()
            
            if validateEmail(email):
                ck_u = User.objects.filter(email=email)
                if len(ck_u) > 0: 
                    existing_user = True
                    code = 100
                    data = {'code':code, 'error': 'User Already Exists'}
                else:
                    existing_user = False
                    u = User(username=email, password=password, email=email)
                    u.save()
                
                    """create invitation"""
                    store = Store.objects.filter(active=True,city='San Francisco')[0]
                    inv = Invitation(user=u, default_store=store, email=u.username, used=True)
                    inv.save()
                    
                    up = UserProfile(user=u, default_store=store)
                    up.save()
                    
                    """create default subscription"""
                    sub = Subscription(userprofile=up, subscription=False, subscription_type='un-subscribed')
                    sub.save()
                    
                    """Send admin email"""
                    sendSignupAdminEmail(u, 'San Francisco')
                    
                    """Send user email"""
                    sendWelcomeEmail(email,'sanfrancisco', 'San Francisco')
                    
                    """subscribe user to daily email"""
                    LIST_IDS = {'san-francisco':'eaa0a378ba'}
                    l_id = LIST_IDS['san-francisco']
                    
                    ms = MailSnake(settings.MAILCHIMP_API_KEY)
                    success = ms.listSubscribe(id=l_id, email_address=u.email, double_optin=False)
                    
                    d, code = api_auth_helper(u)
                    code = 200
                    data = {'code':code, 'account':d['account']}
            else:
                code = 100
                data = {'code':code, 'error': 'Invalid Email'}
        else:
            code = 100
            data = {'code':code, 'error': 'Invalid Sign-up'}
          
    return HttpResponse(simplejson.dumps(data, cls=MyJSONEncoder),content_type = 'application/javascript; charset=utf8')
Esempio n. 2
0
def invite_friends(request):
    user = getUser(request)

    if request.POST:
        form = FriendInvitationForm(request.POST)
        if form.is_valid():
            c_email = form.cleaned_data["email"]
            email = c_email.lower()
            token = get_rand_token()

            # Check if new invite is already a user
            ck_u = User.objects.filter(email=email)
            if len(ck_u) > 0:
                error_msg = (
                    "Looks like we already have a user signed up with this email.  Do you have any other friends?"
                )
                messages.add_message(request, messages.INFO, error_msg)
            else:
                new_u = User(username=email, password=token, email=email)
                new_u.save()

                exstng_up = UserProfile.objects.get(user=user)
                ds = exstng_up.default_store
                up = UserProfile(user=new_u, default_store=ds)
                up.save()

                c = ds.city.lower()
                city = c.replace(" ", "")

                # Send invite to friend
                send_invite_email(email, token, city, ds, gift=True, gifter=user.email)

                # Notify admin of new invite
                send_admin_new_invite(new_u, user)

                inv = Invitation(user=new_u, default_store=ds, email=new_u.username, token=token, used=False)
                inv.save()

                invfrnd = FriendInvites(user=user, invitation=inv)
                invfrnd.save()

                # assign new user to subscription
                s_type = "1 month unlimited (friend invite)"
                s = Subscription(userprofile=up, subscription=True, subscription_type=s_type)
                s.save()

                msg = "Invite to %s sent! Don't stop now, keep inviting friends." % email
                messages.add_message(request, messages.INFO, msg)
    else:
        form = FriendInvitationForm()

    invites = FriendInvites.objects.filter(user=user)

    template = "profile/invite_friend.html"
    data = {"form": form, "invites": invites}
    return render_to_response(template, data, context_instance=RequestContext(request))
Esempio n. 3
0
def ajax_signup(request):
    if request.POST:
        new_signup = MyUserCreationForm(request.POST)
        if new_signup.is_valid():
            new_signup.save()
            uname = new_signup.cleaned_data["username"]

            """set up so username and email are the same"""
            user = User.objects.get(username=uname)
            user.email = uname
            user.save()

            """create user profile"""
            store_id = request.POST.get("default_store")
            store = Store.objects.get(id=store_id)
            up = UserProfile(user=user, default_store=store)
            up.save()

            """create default subscription"""
            sub = Subscription(userprofile=up, subscription=False, subscription_type="un-subscribed")
            sub.save()

            """email admin of new signup"""
            sendSignupAdminEmail(user, store)

            """email user with signup information"""
            sendSignupEmail(user, store)

            """subscrbe user to daily email"""
            LIST_IDS = {"sflaunch_group": "eaa0a378ba"}
            l_id = LIST_IDS["sflaunch_group"]

            ms = MailSnake(settings.MAILCHIMP_API_KEY)
            success = ms.listSubscribe(id=l_id, email_address=user.email, double_optin=False)

            username = user.username
            password = user.password
            user = authenticate(username=username, password=password)
            if user is not None:
                if user.is_active:
                    login(request, user)

            return HttpResponse("success", status=200)

    return HttpResponse("Username is already taken", status=403)
Esempio n. 4
0
def CreateNewUserHelper(request, c_email, c_city):
    email = c_email.lower()
    token = get_rand_token()

    ck_u = User.objects.filter(email=email)
    if len(ck_u) > 0:
        existing_user = True
    else:
        existing_user = False
        u = User(username=email, password=token, email=email)
        u.save()

        """create invitation"""
        store = Store.objects.filter(active=True, city="San Francisco")[0]
        inv = Invitation(user=u, default_store=store, email=u.username, token=token, used=False)
        inv.save()

        # save in session
        request.session["user"] = base64.b16encode(str(u.id))

        CITY_LIST = {"san-francisco": "San Francisco"}
        cl_city = CITY_LIST[c_city]

        up = UserProfile(user=u, default_store=store)
        up.save()

        """create default subscription"""
        sub = Subscription(userprofile=up, subscription=False, subscription_type="un-subscribed")
        sub.save()

        """Send admin email"""
        sendSignupAdminEmail(u, cl_city)

        """Send welcome email to new user"""
        c = cl_city.lower()
        city = c.replace(" ", "")
        sendWelcomeEmail(email, token, city, cl_city)

        """subscribe user to daily email"""
        LIST_IDS = {"san-francisco": "eaa0a378ba"}
        l_id = LIST_IDS[c_city]

        ms = MailSnake(settings.MAILCHIMP_API_KEY)
        success = ms.listSubscribe(id=l_id, email_address=u.email, double_optin=False)
Esempio n. 5
0
def admin_invite(request):
    if request.POST:
        form = InvitationForm(request.POST)
        if form.is_valid():
            c_email = form.cleaned_data["email"]
            email = c_email.lower()
            token = get_rand_token()

            u = User(username=email, password=token, email=email)
            u.save()

            store = form.cleaned_data["store"]
            up = UserProfile(user=u, default_store=store)
            up.save()

            """create default subscription"""
            sub = Subscription(userprofile=up, subscription=False, subscription_type="un-subscribed")
            sub.save()

            c = store.city.lower()
            city = c.replace(" ", "")
            send_invite_email(email, token, city, store)

            inv = Invitation(user=u, default_store=store, email=u.username, token=token, used=False)
            inv.save()

            """subscrbe user to daily email"""
            LIST_IDS = {"sflaunch_group": "eaa0a378ba"}
            l_id = LIST_IDS["sflaunch_group"]

            ms = MailSnake(settings.MAILCHIMP_API_KEY)
            success = ms.listSubscribe(id=l_id, email_address=u.email, double_optin=False)

    else:
        form = InvitationForm()

    invites = Invitation.objects.all()

    template = "profile/admin/admin_invite.html"
    data = {"form": form, "invites": invites}

    return render_to_response(template, data, context_instance=RequestContext(request))
Esempio n. 6
0
def signup(request, city):
    LOCATIONS = {'sanfrancisco':'San Francisco'}
    STATE = {'sanfrancisco':'CA'}
    
    store_city = LOCATIONS[city]
    store_state = STATE[city]
    
    store_all = Store.objects.filter(city=store_city, active=True)
    
    if request.POST:
        new_signup = MyUserCreationForm(request.POST)
        if new_signup.is_valid():
            new_signup.save()
            uname = new_signup.cleaned_data['username']
            
            """set up so username and email are the same"""
            user = User.objects.get(username=uname)
            user.email = uname
            user.save()
            
            """create user profile"""
            store_id = request.POST.get('default_store')
            store = Store.objects.get(id=store_id)
            
            up = UserProfile(user=user, default_store=store)
            up.save()
            
            """create default subscription"""
            sub = Subscription(userprofile=up, subscription=False, subscription_type='un-subscribed')
            sub.save()
            
            """email admin of new signup"""
            sendSignupAdminEmail(user, store)
            
            """email user with signup information"""
            sendSignupEmail(user, store)
            
            """subscrbe user to daily email"""
            LIST_IDS = {'sflaunch_group':'eaa0a378ba'}
            l_id = LIST_IDS['sflaunch_group']
      
            ms = MailSnake(settings.MAILCHIMP_API_KEY)
            success = ms.listSubscribe(id=l_id, email_address=user.email, double_optin=False)
            
            username = user.username
            password = user.password
            user = authenticate(username=username, password=password)
            if user is not None:
                if user.is_active:
                    login(request, user)
            
            request.session['user'] = base64.b16encode(str(up.user.id))
            
            return HttpResponseRedirect('/profile/subscribe/sanfrancisco')
    
    new_signup = MyUserCreationForm()
    location_form = UserProfileForm()
    
    mapForm = createMapMulti(store_all, store_city, store_state, largeMap=True, zoomControl=True, panControl=True)
        
    template = 'profile/signup.html'
    data = {'new_signup':new_signup, 'store_all':store_all, 'city':city,
                'store_city':store_city, 'location_form':location_form, 'map':mapForm}
    
    return render_to_response(template, data,context_instance=RequestContext(request))
Esempio n. 7
0
def gift_subscription(request):
    init = {'country':'US'}
    
    if request.POST:
        gift = GiftForm(request.POST)
        if gift.is_valid():
            randtoken = get_rand_token()
            
            message = gift.cleaned_data['message']
            givername = gift.cleaned_data['givername']
            giveremail = gift.cleaned_data['giveremail']
            receivername = gift.cleaned_data['receivername']
            receiveremail = gift.cleaned_data['receiveremail']
            
            gs = GiftSubscription(givername=givername,giveremail=giveremail,message=message,
                             receivername=receivername, receiveremail=receiveremail, gifttoken=randtoken)
            gs.save()
            
            #create new user or check if user exists
            email = receiveremail.lower()
            
            #Check if new invite is already a user
            ck_u = User.objects.filter(email=email)
            if len(ck_u) > 0: 
                new_u = ck_u[0]
                up = new_u.get_profile()
            else:    
                new_u = User(username=email, password=randtoken, email=email)
                new_u.save()
                
                store = Store.objects.filter(city='San Francisco')[0]
                up = UserProfile(user=new_u, default_store=store)
                up.save()
                
            gs.giftuser = new_u
            gs.save()
            
            
            #subscribe user with profile
            address_line1 = ''
            address_line2 = ''
            address_city = ''
            address_state = ''
            address_zip = ''

            up_dict = {'name':receivername,
           'address_line1':address_line1,
           'address_line2':address_line2,
           'address_city': address_city,
           'address_state': address_state,
           'address_zip': address_zip }

            stripe.api_key = settings.STRIPE_API_KEY
            
            try:  
                """Check for saved version"""
                user_profile = new_u.get_profile()
                customer_id = user_profile.stripeprofile
                if customer_id:
                    customer = stripe.Customer.retrieve(customer_id)
                else:
                    customer = createStripeCustomer(request, new_u, up_dict, up_exists = True)
            except UserProfile.DoesNotExist:
                """Create new and save """
                customer = createStripeCustomer(request, new_u, up_dict, up_exists = False)
            
            #send gift subscription email
            token = request.POST.get('stripeToken')
            
            descrip = "Gift from %s" % givername
            
            try:
                stripe.Charge.create(
                                    amount=4999,
                                    currency="usd",
                                    card=token, # obtained with stripe.js
                                    description= descrip
                )
                valid=True
                
                """create default subscription"""
                sub = Subscription(userprofile=up, subscription=False, subscription_type='un-subscribed')
                sub.save()
                
                """email gifter & receiver"""
                gifter_receiver_email(giveremail, receiveremail, message, givername, receivername, randtoken)
                
                """email admin"""
                gift_admin_email(givername, giveremail, receivername, receiveremail)
                
                template = 'gifts/gift_subscription_thanks.html'

                data = {'receivername':receivername, 'receiveremail':receiveremail}
                return render_to_response(template, data,context_instance=RequestContext(request))
                
            except stripe.CardError, e: 
                messages.add_message(request, messages.ERROR, e)
                valid = False 
            except stripe.InvalidRequestError, e:
                messages.add_message(request, messages.ERROR, e)
                valid = False
Esempio n. 8
0
def redeem_now(request):
    user = None
    
    token = request.POST.get('token')
    if not token:
        token = request.GET.get('token')
    
    city = 'sanfrancisco'
    #if 'city' in request.GET:
    #    city = request.GET.get('city')
         
    try:
        gift = GiftSubscription.objects.get(gifttoken=token)
        user = gift.giftuser
        request.session['user'] = base64.b16encode(str(user.id))
    except GiftSubscription.DoesNotExist:
        raise Http404
    except:
        raise Http404
    
    if user:        
        if request.POST:
            form = SetPasswordForm(user, request.POST)
            if form.is_valid():
                form.save()
                
                """Get users default city"""
                up = UserProfile.objects.filter(user=user)
                if up:
                    store = up[0].default_store
                    c = store.city
                    city = c.lower().replace(' ','')
                
                """update to gift subscription"""
                gift.giftused = True
                gift.save() 
                
                """update to gift subscription"""
                s_type = "4 month unlimited (gift subscription)"
                sub = Subscription.objects.filter(userprofile=up[0])
                
                if len(sub) > 0:
                    s = sub[0]
                    s.subscription_type = s_type
                    s.subscription = True 
                    s.save()
                else:
                    s = Subscription(userprofile=up, subscription=True, subscription_type=s_type)
                    s.save()
                    
                """subscribe user to daily email"""
                LIST_IDS = {'sflaunch_group':'eaa0a378ba'}
                l_id = LIST_IDS['sflaunch_group']
          
                ms = MailSnake(settings.MAILCHIMP_API_KEY)
                success = ms.listSubscribe(id=l_id, email_address=user.email, double_optin=False)
                
                data = {'user':user, 'city':city}
                template = "gifts/thanks_gift_redeemed.html"
                return render_to_response(template, data,context_instance=RequestContext(request))
        
        else:
            form = SetPasswordForm(user) 
        
        data = {'form':form, 'user':user, 'token':token, 'city':city}
        template = 'gifts/gift_redeem.html'
        
        return render_to_response(template, data, context_instance=RequestContext(request))    
Esempio n. 9
0
def createStripe_Subscription(request):
    user = getUser(request)
    valid = False

    first = request.POST.get("first_name")
    last = request.POST.get("last_name")

    name = ""
    if first and last:
        name = first + " " + last

    address_line1 = request.POST.get("street1")
    address_line2 = request.POST.get("street2")
    address_city = request.POST.get("city")
    address_state = request.POST.get("state")
    address_zip = request.POST.get("postal_code")

    up_dict = {
        "name": name,
        "address_line1": address_line1,
        "address_line2": address_line2,
        "address_city": address_city,
        "address_state": address_state,
        "address_zip": address_zip,
    }

    stripe.api_key = settings.STRIPE_API_KEY

    # check if stripe user exists
    # if not create one and get id / if so get id
    try:
        """Check for saved version"""
        user_profile = user.get_profile()
        customer_id = user_profile.stripeprofile
        if customer_id:
            customer = stripe.Customer.retrieve(customer_id)
        else:
            customer = createStripeCustomer(request, user, up_dict, up_exists=True)
    except UserProfile.DoesNotExist:
        """Create new and save """
        customer = createStripeCustomer(request, user, up_dict, up_exists=False)

    # associate user with plan
    token = request.POST.get("stripeToken")

    """update stripe customer"""
    if "change_card" in request.GET:
        customer = stripe.Customer.retrieve(customer.id)
        customer.card = token
        customer.save()

    try:
        customer.update_subscription(plan="unlimited")

        # get userprofile and associate user profile with subscription type
        subscrip_details = Subscription.objects.filter(userprofile=user_profile)
        if len(subscrip_details) == 0:
            subscrip_details = Subscription(userprofile=user_profile, subscription=True, subscription_type="unlimited")
        else:
            subscrip_details = subscrip_details[0]
            subscrip_details.subscription = True
            subscrip_details.subscription_type = "unlimited"
        subscrip_details.save()

        valid = True
    except stripe.CardError, e:
        messages.add_message(request, messages.ERROR, e)
        valid = False