Exemplo n.º 1
0
 def get(self, name=False):
     self.response.headers.add_header("Access-Control-Allow-Origin", "*")
     user = auth.getCurrentUser()
     response = {}
     if user:
         try:
             user_data = models.getUser(user)
         except models.UserDoesNotExistError:
             user_data = models.UserData(user=user).save()
         if not name:
             name = "Chrome"
         try:
             device = models.getDevice("%s/%s" % (user.email(), name))
         except models.DeviceDoesNotExistError:
             device = models.DeviceData(user=user_data, name=name).save()
         try:
             channel = channels.Channel(device.address,
                                        override_quota=user_data.immune())
             response['token'] = channel.token
             if channel.cached:
                 response['code'] = 304
             else:
                 response['code'] = 200
         except channels.OverQuotaError:
             response['code'] = 503
             response['token'] = 'overquota'
             response['message'] = "Server is over quota."
     else:
         response['code'] = 401
         response['message'] = 'Not logged in.'
     self.response.out.write(simplejson.dumps(response))
Exemplo n.º 2
0
 def get(self):
     user = auth.getCurrentUser()
     name = "Web"
     if user:
         try:
             user_data = models.getUser(user)
         except models.UserDoesNotExistError:
             user_data = models.UserData(user=user).save()
         try:
             device = models.getDevice("%s/%s" % (user.email(), name))
         except models.DeviceDoesNotExistError:
             device = models.DeviceData(user=user_data, name=name).save()
         over_quota = False
         try:
             channel = channels.Channel(device.address,
                                        override_quota=user_data.immune())
             channel_token = channel.token
         except channels.OverQuotaError:
             over_quota = True
             channel_token = 'overquota'
         template_values = {
             'channel_id': channel_token,
             'device': device.address,
             'device_name': device.name,
             'devices': user_data.getDevices(),
             'over_quota': over_quota
         }
         path = os.path.join(os.path.dirname(__file__),
                             'devlinks_index.html')
         self.response.out.write(template.render(path, template_values))
     else:
         self.redirect(users.create_login_url(self.request.uri))
Exemplo n.º 3
0
    def make_user(self, nickname):
        u = models.UserData(key_name="key_%s" % self.user_count)
        u.user_id = "userid_%s" % self.user_count
        u.update_nickname(nickname)
        u.put()

        self.user_count += 1
        return u
Exemplo n.º 4
0
def user_home(request):
    user_function = users.get_current_user()
    filedir = sys.path.insert(0, os.path.abspath(os.path.dirname(__file__)))
    contributed_list = []
    started_list = []
    paid = 0
    a = models.UserData()
    if user_function:
        username = user_function.nickname()
        email = user_function.email()
        href = users.create_logout_url('/home')

        for i in a.query(a._properties['username'] == username):
            contributed_list.append(i.contributed_to)
        for j in a.query(a._properties['username'] == username):
            started_list.append(i.started)
        for k in a.query(a._properties['username'] == username):
            paid = k.paid

        if (not models.UserData.query(
                models.UserData.username == user_function.nickname(),
                models.UserData.email == user_function.email()).get()):
            query = models.UserData(username=user_function.nickname(),
                                    email=user_function.email())
            query.put()
        else:
            pass
    else:
        username = user_function.nickname()
        email = user_function.email()
        href = users.create_login_url('/home')
    return render(
        request, 'profile.html', {
            'href': href,
            'email': email,
            'username': username,
            'filedir': filedir,
            'contributed_list': contributed_list,
            'started_list': started_list,
            'paid': paid
        })
Exemplo n.º 5
0
def project(request):
    user_function = users.get_current_user()
    b = models.UserData()
    if b.query(b._properties['username'] == username):
        date = b.query(b._properties['username'] == username).date
    for k in a.query(a._properties['username'] == username):
        payment = int(payment) + int(k.paid)
    if b.query(b._properties['username'] == username):
        title = b.query(b._properties['username'] == username).title
    return render(request, 'project.html', {
        'date': date,
        'payment': payment,
        'title': title
    })
Exemplo n.º 6
0
 def post(self):
     user = auth.getCurrentUser()
     response = {}
     if user:
         try:
             user_data = models.getUser(user)
         except models.UserDoesNotExistError:
             user_data = models.UserData(user=user).save()
         payment_data = models.PaymentData(
             date=timestamp.now(),
             user=user_data,
             item=self.request.get("item_id"),
             order_number=self.request.get("order_number"),
             status="unconfirmed")
         payment_data.save()
Exemplo n.º 7
0
 def get(self):
     user = users.User('*****@*****.**')
     try:
         user_data = models.getUser(user)
     except models.UserDoesNotExistError:
         user_data = models.UserData(user=user).save()
     try:
         device = models.getDevice("%s/%s" % (user.email(), "Web"))
     except models.DeviceDoesNotExistError:
         device = models.DeviceData(user=user_data, name="Web").save()
     channel = channels.Channel(device.address, override_quota=True)
     path = os.path.join(os.path.dirname(__file__), 'dashboard.html')
     stats_data = models.StatsData.all().order("-date").fetch(1000)
     template_values = {'channel_id': channel.token, 'stats': {}}
     stats = template_values['stats']
     for datapoint in stats_data:
         datestamp = int(
             time.mktime(datapoint.date.date().timetuple()) * 1000)
         hour = datapoint.date.hour
         if datestamp not in stats:
             stats[datestamp] = {
                 'datestamp': datestamp,
                 'date': datapoint.date,
                 'datapoints': {}
             }
         if datapoint.datapoint not in stats[datestamp]['datapoints']:
             stats[datestamp]['datapoints'][datapoint.datapoint] = {
                 'datapoint': datapoint.datapoint,
                 'values': {}
             }
         point_id = "%s" % hour
         if datapoint.duration == "day":
             point_id = "total"
         dp = datapoint.datapoint
         stats[datestamp]['datapoints'][dp]['values'][point_id] = {
             'datapoint': datapoint.datapoint,
             'datestamp': datestamp,
             'hour': hour,
             'count': int(datapoint.count),
             'duration': datapoint.duration
         }
     template_values['stats'] = stats
     logging.info(template_values)
     self.response.out.write(template.render(path, template_values))
Exemplo n.º 8
0
 def post(self):
     self.response.headers.add_header("Access-Control-Allow-Origin", "*")
     user = auth.getCurrentUser()
     response = {}
     if user:
         try:
             user_data = models.getUser(user)
         except models.UserDoesNotExistError:
             user_data = models.UserData(user=user).save()
         name = self.request.get('name')
         if not name:
             name = "Chrome"
         try:
             device = models.getDevice("%s/%s" % (user.email(), name))
         except models.DeviceDoesNotExistError:
             device = models.DeviceData(name=name, user=user_data).save()
         receiver = None
         if self.request.get("receiver"):
             try:
                 receiver = models.getDevice(
                     "%s/%s" % (user.email(), self.request.get("receiver")))
             except models.DeviceDoesNotExistError:
                 receiver = models.DeviceData(
                     name=self.request.get("receiver"),
                     user=user_data).save()
         if receiver == None:
             receiver = device
         link = models.LinkData(url=self.request.get('link'),
                                sender=device,
                                receiver=receiver).save()
         if models.getQuota().amount >= models.getStats(
                 'channels').count or user_data.immune():
             channel = channels.Channel(receiver.address, False)
             channel.sendLink(link)
             response['code'] = 200
             response['link'] = link.url
         else:
             response['code'] = 503
             response['link'] = link.url
     else:
         response['code'] = 401
         response['link'] = self.request.get('link')
     self.response.out.write(simplejson.dumps(response))
Exemplo n.º 9
0
 def post(self, name="Chrome"):
     self.response.headers.add_header("Access-Control-Allow-Origin", "*")
     user = auth.getCurrentUser()
     device = None
     if user:
         try:
             user_data = models.getUser(user)
         except models.UserDoesNotExistError:
             user_data = models.UserData(user=user).save()
         try:
             device = models.getDevice("%s/%s" % (user.email(), name))
         except:
             device = models.DeviceData(user=user_data, name=name).save()
         last_links = models.getUnreadLinks(device)
         channel = channels.Channel(device.address, False)
         for link in last_links:
             channel.queueLink(link)
         channel.send()
         stats.record("user_connected",
                      simplejson.dumps({"user": user.email()}))
         self.response.out.write(device.address)
Exemplo n.º 10
0
    def post(self):
        status = "ok"
        user = self.user
        if not user:
            self.redirect('/login')
        store_name = self.request.get('choose_market')
        logging.error(store_name)
        address = self.request.get('address')
        telephone = self.request.get('telephone')
        stores_list = list(caching.get_stores())
        t = db.GqlQuery('SELECT * FROM UserData WHERE login = :login',
                        login=user.auth_ids)
        new_user = models.UserData()
        new_user = list(t)[0]
        db.delete(t)
        new_user.store_id = int(store_name)
        new_user.address = address
        if re.match('^\+(?:[0-9] ?){6,14}[0-9]$', telephone):
            new_user.telephone = telephone
        else:
            status = "telephone"
        new_user.put()
        memcache.set('current_store', None)
        memcache.set('current_store' + user.auth_ids[0], None)

        self.render(
            'user_profile_change.html', {
                'm_user': new_user,
                'is_home': 1,
                'first_name': user.name,
                'last_name': user.last_name,
                'stores_list': stores_list,
                'address': new_user.address if new_user.address else "",
                'telephone': new_user.telephone if new_user.telephone else "",
                'status': status
            })