示例#1
0
文件: views.py 项目: ii0/CNote
def writeNote(request):
    pass
    uid = request.POST.get('uid','');
    content = request.POST.get('content','');
    public = request.POST.get('public','');
    token = request.META.get('HTTP_TOKEN', '');


    if not content:
        return C_Response(-108,'','content is null');
    try:
        r = User.objects.get(token=token);
    except:
        return C_Response(-109, '', 'token is invalid');

    if not public:
        public = False;

    Note.objects.create(uuid=r.uid,content=content,public=public);
    r = Note.objects.get(cid=0);
    c_id = r.id;
    r.cid = c_id;
    r.save();
    query_shell = "SELECT a.id,a.name,b.uuid,b.content,b.cid FROM account_user a JOIN account_note b ON a.uid = b.uuid WHERE b.cid=%s"%c_id;
    rr = Note.objects.raw(query_shell)[0];
    return C_Response(0, {"name": rr.name, "uid": rr.uuid,"content":rr.content,"cid":rr.cid});
示例#2
0
def writeNote(request):

    uid = request.POST.get('uid', '')
    content = request.POST.get('content', '')
    public = request.POST.get('public', '')

    if not uid or not content:
        return C_Response(-108, '', 'uid or content is null')
    try:
        User.objects.get(uid=uid)
    except:
        return C_Response(-109, '', 'uid not found')

    Note.objects.create(uid=uid, content=content, cid=-1, public=public)
    r = Note.objects.get(cid=-1)
    c_id = r.id
    r.cid = c_id
    r.save()
    query_shell = "SELECT a.name,b.uid,b.content,b.cid FROM account_user a JOIN account_note b ON a.uid = b.uid WHERE b.cid=%s" % c_id
    rr = Note.objects.raw(query_shell)[0]
    return C_Response(0, {
        "name": rr.name,
        "uid": rr.uid,
        "content": rr.content
    })
示例#3
0
文件: views.py 项目: ii0/CNote
def readNotes(request):
    method = request.method;
    uid = request.GET.get('uid','');
    token = request.META.get('HTTP_TOKEN','');

    if not uid and not token:
        items = Note.objects.all();
        resp = []
        for item in items:
            if item.public:
                resp.append({"cid:": item.cid, "content": item.content, "public": item.public});
        if resp == []:
            return C_Response(-203, '', 'no content');
        else:
            return C_Response(0,resp)

    if uid:

        try:
            User.objects.get(uid=uid);
        except:
            return C_Response(-201, '', 'uid not found');

        items = Note.objects.filter(uuid=uid);
        resp = [];

        if not items:
            return C_Response(-203, '', 'no content');

        for o in items:
            if not o.public:
                continue;
            resp.append({"cid:": o.cid, "content": o.content,"public":o.public});
        if resp != []:
            return C_Response(0, resp);
        else:
            return C_Response(-203, '', 'no content');

    try:
        rrr = User.objects.get(token=token);
    except:
        return C_Response(-109, '', 'token is invalid');

    items = Note.objects.filter(uuid=rrr.uid);
    resp = [];

    if not items:
        return C_Response(-203,'','no content');

    for o in items:
        resp.append({"cid:":o.cid,"content":o.content,"public":o.public});

    return C_Response(0,resp);
示例#4
0
def signin(request):
    method = request.method
    name = request.POST.get('username', '')
    pwd = request.POST.get('password', '')
    if not name or not pwd:
        return C_Response(-107, '', 'account or password not be null')
    infos = User.objects.filter(name=name)
    if not infos:
        return C_Response(-106, '', 'account not found')
    infos = infos[0]
    if not infos.pwd == pwd:
        return C_Response(-105, '', 'password wrong')
    return C_Response(0, {
        "name": infos.name,
        "phone": infos.phone,
        "uid": infos.uid
    })
示例#5
0
文件: views.py 项目: ii0/CNote
def signup(request):
    method = request.method;
    name = request.POST.get('username','');
    phone = request.POST.get('phone', '');
    pwd = request.POST.get('password', '');
    #一堆异常
    if method == 'GET':
        return C_Response(-1,'','method error,only support get');
    if not name or not phone:
        return C_Response(-100,'','params error,name or phone should not null');
    if not pwd:
        return C_Response(-101,'','password is null')
    if len(pwd) != 32:
        return C_Response(-102,'','password must a 32 MD5 string');
    r = User.objects.raw('SELECT * FROM account_user');
    for item in r:
        if phone == item.phone :
            return C_Response(-103, '', 'phone has been used');
        if name == item.name:
            return C_Response(-104, '', 'username has benn used');

    #创建账户
    User.objects.create(name=name,phone=phone,pwd=pwd);
    m_id = User.objects.get(phone=phone);
    m_id.uid = m_id.id;
    m_id.save();
    #查询并返回数据
    resp = User.objects.get(phone=phone);


    return C_Response(0,{"name":resp.name,"phone":resp.phone,"uid":resp.uid});
示例#6
0
文件: views.py 项目: ii0/CNote
def signin(request):
    method = request.method;
    name = request.POST.get('username', '');
    pwd = request.POST.get('password', '');
    if not name or not pwd:
        return C_Response(-107,'','account or password not be null');
    infos = User.objects.filter(name=name);
    if not infos:
        return C_Response(-106,'','account not found');
    infos = infos[0];
    if not infos.pwd == pwd:
        return C_Response(-105,'','password wrong');

    # 生成认证token
    token = randomTokens();
    infos.token = token;
    infos.save();

    return C_Response(0,{"name":infos.name,"phone":infos.phone,"uid":infos.uid,"token":token});
示例#7
0
def signup(request):
    method = request.method
    name = request.POST.get('username', '')
    phone = request.POST.get('phone', '')
    pwd = request.POST.get('password', '')
    #一堆异常
    if method == 'GET':
        return C_Response(-1, '', 'method error,only support get')
    if not name or not phone:
        return C_Response(-100, '',
                          'params error,name or phone should not null')
    if not pwd:
        return C_Response(-101, '', 'password is null')
    if len(pwd) != 1:
        return C_Response(-102, '', 'password must a MD5 string')
    r = User.objects.raw('SELECT * FROM account_user')
    for item in r:
        if phone == item.phone or name == item.name:
            return C_Response(-103, '', 'account has benn regist!')

    #创建账户
    User.objects.create(name=name, phone=phone, pwd=pwd)
    m_id = User.objects.get(phone=phone)
    m_id.uid = m_id.id
    m_id.save()
    #查询并返回数据
    resp = User.objects.get(phone=phone)
    return C_Response(0, {
        "name": resp.name,
        "phone": resp.phone,
        "uid": resp.uid
    })