Esempio n. 1
0
 def post(self, request, *args, **kwargs):
     form = SignUpForm(request.POST)
     if form.is_valid():
         UserSignUp.store(request)
         return tojson({'signup':True})
     else:
         return tojson({'signup':False, 
                 'message':'请正确填写表格'})
Esempio n. 2
0
def exists(request):
    """
    Does this user exists?
    args:
        request.POST['username']

    returns:
        json: {'exists':true/false}
    """
    res = {'exists':True}
    username = request.POST.get('username', '')
    if not username:
        return tojson(res)
    else:
        res['exists'] = UserSignUp.exists(username)
    return tojson(res)
Esempio n. 3
0
def logout(request):
    """
    return:
        json: {'logout':true}
    """
    try:
        del request.session['userid']
    except KeyError:
        pass

    try:
        del request.session['username']
    except KeyError:
        pass
    res = {'logout':True}
    return tojson(res)
Esempio n. 4
0
 def post(self, request, *args, **kwargs):
     """
     用户注册
     args:
         username, password
     return:
         json:
         { login: true/false, userid: 2, message:'wrong?'}
     """
     # 提交登陆信息
     username = request.POST.get('name', '')
     password = request.POST.get('password', '')
     res = {'login':False, 'userid':-1, 'username': username}
     if username and password:
         try:
             user = User.objects.get(name=username)
             if user.password == password: 
                 res['login'] = True
                 res['userid'] = user.id
                 request.session['userid'] = res['userid']
                 request.session['username'] = res['username']
         except:
             pass
     return tojson(res)