Esempio n. 1
0
def change_password(request):
    if request.method=='POST': 
        username = request.user.username
        oldPassword = request.POST.get("oldPassword")
        newPassword = request.POST.get("newPassword")
        user= auth.authenticate(username=username,password=oldPassword)
        if not user:
            return  commonLib.statusJson(status=400, message="密码输入有误")
        u = User.objects.get(username=username)
        u.set_password(newPassword)
        u.save()  
        return commonLib.statusJson()
Esempio n. 2
0
def userDelete(request):
    try:
        if request.user.is_superuser:
            id = request.POST.get("id")
            u = User.objects.get(id=int(id))
            if u.username == request.user.username:
                return commonLib.statusJson(status=400, message="别闹!")
            u.delete()
            return commonLib.statusJson()
        return commonLib.statusJson(status=400, message="已通知管理员")
    except Exception,e:
        return commonLib.statusJson(status=400, message=str(e))
Esempio n. 3
0
def userActive(request):
    if request.user.is_superuser:
        id = request.POST.get("id")
        u = User.objects.get(id=id)
        if u.username == request.user.username:
            return commonLib.statusJson(status=400, message="别闹!")
        if u.is_active == 1:
            u.is_active = 0
        else:
            u.is_active = 1
        u.save()
        return commonLib.statusJson()
    return commonLib.statusJson(status=400, message="已通知管理员")    
Esempio n. 4
0
def userQuery(request):
    if request.user.is_superuser:
        user=User.objects.all().values()
    else:
        user=User.objects.exclude(is_superuser=1).values()
    userList = list(user)
    return commonLib.statusJson(body=userList)
Esempio n. 5
0
def userRegister(request):     
    if  not request.user.is_superuser:
        return commonLib.statusJson(status=400,message="请通知管理员注册")
    try:  
        if request.method=='POST':  
            username=request.POST.get('username','')  
            password=request.POST.get('password','')
            name = request.POST.get('name','')
            email=request.POST.get('email','')  
            if not username or not password or not name:
                return commonLib.statusJson(status=400,message="必填项不能为空")
            user = User.objects.create_user(username, email,password)
            user.last_name = name
            user.save() 
            return commonLib.statusJson()
    except Exception,e:  
        return commonLib.statusJson(status=400,message=str(e))