def register(request): dict = {} resultData = {} if request.method == 'POST': username = request.POST.get('username') password = request.POST.get('password') gender = request.POST.get('gender') pushKey = request.POST.get('pushKey') birthday = request.POST.get('birthday') nickname = request.POST.get('nickname') if username and password: cur = connection.cursor() query = 'select * from here_user where username = %s' cur.execute(query, [username]) userResult = cur.fetchall() if userResult: dict['errorMessage'] = "username_is_exist" dict['status'] = "8002" else: dict['errorMessage'] = "register_success" dict['status'] = "0" # 将用户数据存入数据库 cursor = connection.cursor() query = "insert into here_user(username,password,gender,pushkey,birthday,nickname) values(%s,%s,%s,%s,%s,%s)" cursor.execute( query, [username, password, gender, pushKey, birthday, nickname]) # 注册环信账号 newCursor = connection.cursor() newQuery = "select * from here_user where username = %s" newCursor.execute(newQuery, [username]) newRes = newCursor.fetchall() userid = newRes[0][0] util.registerEMChat(userid, password) # 返回客户端用户数据 resultData['username'] = username resultData['password'] = password resultData['pushKey'] = pushKey resultData['gender'] = gender resultData['birthday'] = birthday resultData['nickname'] = nickname dict['resultData'] = resultData else: dict['errorMessage'] = "username_or_password_invalid" dict['status'] = "8001" json = simplejson.dumps(dict) return HttpResponse(json) else: dict['errorMessage'] = "POST_FAILED" dict['status'] = "8001" json = simplejson.dumps(dict) return HttpResponse("POST failed")
def register(request): dict = {} resultData = {} if request.method == 'POST': username = request.POST.get('username') password = request.POST.get('password') gender = request.POST.get('gender') pushKey = request.POST.get('pushKey') birthday = request.POST.get('birthday') nickname = request.POST.get('nickname') if username and password : cur = connection.cursor() query = 'select * from here_user where username = %s' cur.execute(query,[username]) userResult = cur.fetchall() if userResult: dict['errorMessage'] = "username_is_exist" dict['status'] = "8002" else: dict['errorMessage'] = "register_success" dict['status'] = "0" # 将用户数据存入数据库 cursor = connection.cursor() query = "insert into here_user(username,password,gender,pushkey,birthday,nickname) values(%s,%s,%s,%s,%s,%s)" cursor.execute(query,[username,password,gender,pushKey,birthday,nickname]) # 注册环信账号 newCursor = connection.cursor() newQuery = "select * from here_user where username = %s" newCursor.execute(newQuery,[username]) newRes = newCursor.fetchall() userid = newRes[0][0] util.registerEMChat(userid,password) # 返回客户端用户数据 resultData['username'] = username resultData['password'] = password resultData['pushKey'] = pushKey resultData['gender'] = gender resultData['birthday'] = birthday resultData['nickname'] = nickname dict['resultData'] = resultData else: dict['errorMessage'] = "username_or_password_invalid" dict['status'] = "8001" json = simplejson.dumps(dict) return HttpResponse(json) else: dict['errorMessage'] = "POST_FAILED" dict['status'] = "8001" json = simplejson.dumps(dict) return HttpResponse("POST failed")
def register(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') birthday = request.POST.get('birthday') nickname = request.POST.get('nickname') if username and password : try: user = User.objects.get(username = username,password = password) except User.DoesNotExist: user = None if user: httpResultResponse.errorMessage = ErrorMessage.USERNAME_IS_EXIST httpResultResponse.status = "8002" else: httpResultResponse.errorMessage = ErrorMessage.REGISTER_SUCCESS httpResultResponse.status = "0" # 将用户数据存入数据库 newUser = User.objects.create(username=username, password=password, gender=gender, pushKey=pushKey, birthday=birthday, nickname=nickname) # 注册环信账号 newCursor = connection.cursor() newQuery = "select * from here_user where username = %s" newCursor.execute(newQuery,[username]) newRes = newCursor.fetchall() userid = newRes[0][0] util.registerEMChat(userid,password) # 返回客户端用户数据 useJson = serializers.serialize("json",newUser) httpResultResponse.resultData = useJson else: httpResultResponse.errorMessage = ErrorMessage.USERNAME_OR_PASSWORD_INVALID httpResultResponse.status = "8001"