def modifyUserInfo(request): httpResultResponse = HttpResultResponse() if request.method == 'POST': username = request.POST.get('username') password = request.POST.get('password') gender = request.POST.get('gender') birthday = request.POST.get('birthday') nickname = request.POST.get('nickname') userid = request.POST.get('userid') longProfile = request.POST.get('longProfile') simpleProfile = request.POST.get('simpleProfile') if password and gender and birthday and nickname: user = User.objects.get(pk = userid) if user: user.username = username user.password = password user.gender = gender user.birthday = birthday user.nickname = nickname user.longProfile = longProfile user.simpleProfile = simpleProfile user.save() httpResultResponse.resultData = SQLUtils.SelectUserByUsernamePassword(username = username, password = password) httpResultResponse.errorMessage = ErrorMessage.MODIFY_USER_INFO_SUCCESS httpResultResponse.status = '0' else: httpResultResponse.errorMessage = ErrorMessage.NO_SUCH_USER_OR_PASSWORD_IS_INVALID httpResultResponse.status = '8005' else: httpResultResponse.errorMessage = ErrorMessage.NO_SUCH_USER_OR_PASSWORD_IS_INVALID httpResultResponse.status = '8003' else: httpResultResponse.errorMessage = ErrorMessage.POST_FAILED httpResultResponse.status = '8001' return HttpResponse(httpResultResponse.getJsonResult())
def checkUserIsExist(request): httpResultResponse = HttpResultResponse() if request.method == 'POST': username = request.POST.get('username') if username: user = User.objects.get(username = username) if user: httpResultResponse.status = '0' httpResultResponse.errorMessage = ErrorMessage.USER_IS_EXIST else: httpResultResponse.status = '8003' httpResultResponse.errorMessage = ErrorMessage.USER_IS_NOT_EXIST else: httpResultResponse.errorMessage = ErrorMessage.USERNAME_IS_NULL httpResultResponse.status = '8001' httpResultResponse.resultData = "null" return HttpResponse(httpResultResponse.getJsonResult()) else: httpResultResponse.errorMessage = ErrorMessage.POST_FAILED httpResultResponse.status = '8001' return HttpResponse(httpResultResponse.getJsonResult())
def login(request): httpResultResponse = HttpResultResponse() if request.method == 'POST': username = request.POST.get('username') password = request.POST.get('password') gender = request.POST.get('gender') pushKey = request.POST.get('pushKey') user = User.objects.get(username = username, password = password) if user: httpResultResponse.errorMessage = ErrorMessage.LOGIN_SUCCESS httpResultResponse.errorMessage = "0" httpResultResponse.resultData = SQLUtils.SelectUserByUsernamePassword(username = username, password = password) user.pushKey = pushKey user.save() else: httpResultResponse.errorMessage = ErrorMessage.NO_SUCH_USER_OR_PASSWORD_IS_INVALID httpResultResponse.status = "8003" json = httpResultResponse.getJsonResult() return HttpResponse(json) else: httpResultResponse.errorMessage = ErrorMessage.POST_FAILED httpResultResponse.status = "8003" json = httpResultResponse.getJsonResult() return HttpResponse(ErrorMessage.POST_FAILED)
def uploadAvatar(request): httpResultResponse = HttpResultResponse() if request.method == 'POST': username = request.POST.get('username') headImg = request.FILES.get('file') if username: user = User.objects.get(username = username) if headImg: user.avatar = headImg user.save() httpResultResponse.errorMessage = ErrorMessage.UPDATE_AVATAR_SUCCESS httpResultResponse.status = '0' else: httpResultResponse.errorMessage = ErrorMessage.AVATAR_IS_INVALID httpResultResponse.status = '8004' else: httpResultResponse.errorMessage = ErrorMessage.USERNAME_IS_NULL httpResultResponse.status = '8005' return HttpResponse(httpResultResponse.getJsonResult()) else: httpResultResponse.errorMessage = ErrorMessage.POST_FAILED httpResultResponse.status = '8001' return HttpResponse(httpResultResponse.getJsonResult())