Skip to content

Commit

Permalink
[user]edit
Browse files Browse the repository at this point in the history
  • Loading branch information
wzyy2 committed Jan 30, 2015
1 parent 7244c97 commit 6be2570
Show file tree
Hide file tree
Showing 6 changed files with 144 additions and 3 deletions.
4 changes: 2 additions & 2 deletions PiBox/PiHome/PiApp/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ def check_username(request):
return HttpResponse(simplejson.dumps({'msg':'Please enter a valid email format'}))
user = PiUser.objects.get(username = request.GET['username'])
if user is not None:
return HttpResponse(simplejson.dumps({'msg':'Username already exists'}))
return HttpResponse(simplejson.dumps({'msg':'Email already exists'}))
except:
return HttpResponse(simplejson.dumps({'msg':'Username can be used'}))
return HttpResponse(simplejson.dumps({'msg':'Email can be used'}))

def check_login(request):
if request.user.is_authenticated():
Expand Down
2 changes: 1 addition & 1 deletion PiBox/PiHome/PiApp/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class PiUser(AbstractUser):


class PiSettings(models.Model):
ip = models.IPAddressField(default="127.0.0.1")
ip = models.GenericIPAddressField(default="127.0.0.1")
port = models.IntegerField(default=3333)
enable_register = models.BooleanField(default=True)

Expand Down
Binary file added PiBox/PiHome/WebShell/www/Thumbs.db
Binary file not shown.
2 changes: 2 additions & 0 deletions PiBox/PiHome/templates/login.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,11 @@
{% csrf_token %}
<div class="body bg-gray">
<div class="form-group">
<label>email</label>
<input type="text" name="username" class="form-control" placeholder="User ID"/>
</div>
<div class="form-group">
<label>password</label>
<input type="password" name="password" class="form-control" placeholder="Password"/>
</div>
<div class="form-group">
Expand Down
33 changes: 33 additions & 0 deletions PiBox/sh/datapoint_toolsðswitch.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#/bin/env python
# -*-coding:utf8-*-
'''
# Any issues or improvements please contact jacob-chen@iotwrt.com
'''
import urllib
import json

if __name__ == '__main__':

choose = int(raw_input('1.write 2.read '))
domain = raw_input('domain(as 192.168.10.106:8000) : ')
sensor_id = raw_input('sensor_id(int) : ')

if choose == 1:
value = int(raw_input('value(int) : '))
# params = urllib.urlencode()
params = urllib.urlencode({'value': value})
f = urllib.urlopen("http://" + domain + "/API/sensor/" + sensor_id + "/datapoint/?%s" % params)
get = f.read()
print 'ret body:', get

s = json.loads(get)
print 'msg:', s['msg']

elif choose == 2:
# params = urllib.urlencode()
f = urllib.urlopen("http://" + domain + "/API/sensor/" + sensor_id + "/datapoint/get/")
get = f.read()
print 'ret body:', get

s = json.loads(get)
print 'value:', s['value']
106 changes: 106 additions & 0 deletions PiBox/sh/datapoint_tools€pic.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
#/bin/env python
# -*-coding:utf8-*-
'''
# Any issues or improvements please contact jacob-chen@iotwrt.com
'''
import urllib
import urllib2
import sys
import json

try:
from poster.encode import multipart_encode
from poster.streaminghttp import register_openers
except:
print "In order to post file,you should install poster modules!!"
print "sudo pip install poster"

if __name__ == '__main__':

choose = int(raw_input('1.write 2.read 3.edit 4.remove 5.history'))
domain = raw_input('domain(as 192.168.10.106:8000) : ')
sensor_id = raw_input('sensor_id(int) : ')

#write
if choose == 1:
filepath = raw_input('filepath(as ./xxx.jpg) : ')
key = raw_input('key(as 2012-12-12T11:11:11) : ')

# 在 urllib2 上注册 http 流处理句柄
register_openers()

# 开始对文件的 multiart/form-data 编码
# "value" 是参数的名字,一般通过 HTML 中的 <input> 标签的 name 参数设置
# headers 包含必须的 Content-Type 和 Content-Length
# datagen 是一个生成器对象,返回编码过后的参数,这里如果有多个参数的话依次添加即可
datagen, headers = multipart_encode({"value": open(filepath, "rb"), "key" : key})

request = urllib2.Request("http://" + domain + "/API/sensor/" + sensor_id + "/datapoint/", datagen, headers)

get = urllib2.urlopen(request).read()
print 'ret body:', get
s = json.loads(get)
print 'msg:', s['msg']

#read
elif choose == 2:
key = raw_input('key(as 2012-12-12T11:11:11) : ')
params = urllib.urlencode({'key': key})
f = urllib.urlopen("http://" + domain + "/API/sensor/" + sensor_id + "/datapoint/get/?%s" % params)
get = f.read()
print 'ret body:', get
s = json.loads(get)
print 'key:',s['key'],'value:',s['value']

#edit
elif choose == 3:
filepath = raw_input('filepath(as ./xxx.jpg) : ')
key = raw_input('key(as 2012-12-12T11:11:11) : ')

# 在 urllib2 上注册 http 流处理句柄
register_openers()

# 开始对文件的 multiart/form-data 编码
# "value" 是参数的名字,一般通过 HTML 中的 <input> 标签的 name 参数设置
# headers 包含必须的 Content-Type 和 Content-Length
# datagen 是一个生成器对象,返回编码过后的参数,这里如果有多个参数的话依次添加即可
datagen, headers = multipart_encode({"value": open(filepath, "rb"), "key" : key})

request = urllib2.Request("http://" + domain + "/API/sensor/" + sensor_id + "/datapoint/edit/", datagen, headers)

get = urllib2.urlopen(request).read()
print 'ret body:', get
s = json.loads(get)
print 'msg:', s['msg']

#remove
elif choose == 4:
key = raw_input('key(as 2012-12-12T11:11:11) : ')
params = urllib.urlencode({'key': key})
f = urllib.urlopen("http://" + domain + "/API/sensor/" + sensor_id + "/datapoint/remove/?%s" % params)
get = f.read()
print 'ret body:', get
s = json.loads(get)
print 'msg:', s['msg']

#history
elif choose == 5:
ex = raw_input('latest 20?y or n')
if ex == 'y':
f = urllib.urlopen("http://" + domain + "/API/sensor/" + sensor_id + "/datapoint/history/")
get = f.read()
print 'ret body:', get
s = json.loads(get)
for item in s['datapoint']:
print 'key:',item['key'],'value:',item['value']
else:
start = raw_input('start(as 2012-12-12T11:11:11) : ')
end = raw_input('end(as 2012-12-12T11:11:11) : ')
interval = raw_input('interval(int) : ')
params = urllib.urlencode({'start': start, 'end' : end, 'interval' : interval})
f = urllib.urlopen("http://" + domain + "/API/sensor/" + sensor_id + "/datapoint/history/?%s" % params)
get = f.read()
print 'ret body:', get
s = json.loads(get)
for item in s['datapoint']:
print 'key:',item['key'],'value:',item['value']

0 comments on commit 6be2570

Please sign in to comment.