示例#1
0
def saveProjectWith(json_obj, appid, appOwner):
    plantform = 0
    secret = 0
    if json_obj['package']['appPlatform'] == 'ios':
        plantform = 1
    elif json_obj['package']['appPlatform'] == 'android':
        plantform = 2

    if not json_obj['package']['isPublic']:
        secret = 1
    else:
        secret = 2

    project = Projects(appid=appid,
                       description=json_obj['package']['appDesc'],
                       name=json_obj['package']['appName'],
                       icon=CONFIG.PROJECT_ICON_URL,
                       platform=plantform,
                       create_time=getCurrentTime(),
                       edit_time=getCurrentTime(),
                       public=secret,
                       owner=appOwner,
                       path=CONFIG.WRITE_LUA_SCRIPT_FILE_BASE_PATH + appid +
                       '/')
    project.save()
示例#2
0
def saveProjectWith(json_obj,appid,appOwner):
	plantform = 0
	secret = 0
	if json_obj['package']['appPlatform'] == 'ios':
		plantform = 1
	elif json_obj['package']['appPlatform'] == 'android':
		plantform = 2

	if not json_obj['package']['isPublic']:
		secret = 1
	else:
		secret = 2

	project = Projects(appid=appid,
					   description=json_obj['package']['appDesc'],
					   name=json_obj['package']['appName'],
					   icon=CONFIG.PROJECT_ICON_URL,
					   platform=plantform,
					   create_time=getCurrentTime(),
					   edit_time=getCurrentTime(),
					   public=secret,
					   owner=appOwner,
					   path=CONFIG.WRITE_LUA_SCRIPT_FILE_BASE_PATH + appid +'/'
					   )
	project.save()
示例#3
0
def SSOAuthCallBack(request):	
	fromSource = ''
	if request.GET:
		fromSource = request.GET.get('type','')

	resultDic = Package()
	resultDic.clear()
	username = '******'%request.user
	if username == 'AnonymousUser':
		resultDic.status = 1
		resultDic.code = 1002
		resultDic.message = ''
	else:
		
		conn=MySQLdb.connect(host=conf.DB_HOST,user=conf.DB_USERNAEM,passwd=conf.DB_PASSWD,db=conf.DB_NAME,port=conf.DB_PORT,charset='utf8')
		cur=conn.cursor()
		cur.execute("select * from auth_user where username = '******'"%username)
		result =  cur.fetchone(); 
		cur.close()
		conn.close()
		isExist = False
		try:
			user = User.objects.get(email=result[7])
			user.name = result[4]
			user.nickname = result[6].encode('utf8')
			user.save()
			isExist = True
		except (Exception) as e:
			isExist = False
			
		if isExist == False:
			user_pwd = stringToMD5(conf.PASSWD_FIXED_CHARACTER+result[4])
			user = User(name=result[4],
				         email= result[7],
				         nickname=result[6].encode('utf8'),
				         password=user_pwd,
				         create_time=getCurrentTime(),
				         edit_time=getCurrentTime(),
				         last_login_time = getCurrentTime(),
				         login_source = 1,
				         signin_source = 2,
				         signin_ip = '127.0.0.1',
				         userid='000000',
				         is_ctrip = 1,
				         )
			user.save()
		token = stringToMD5(datetime.datetime.now().strftime("%Y%m%d%H%M%S"))
		Token.save_token(token,result[7])
		resultInfo = {}
		resultInfo['token'] = token
		resultInfo['name'] = result[4]
		resultInfo['nickname'] = result[6].encode('utf8')
		resultInfo['email'] = result[7]
		resultDic.setResult(resultInfo)
	if fromSource == 'mobile':
		return resultDic.archiveJson()
	return resultDic.archiveJavaScript()
示例#4
0
def saveProject(info):
    token = info['context']['token']
    resultDic = Package()
    resultDic.clear()
    if not Token.check_token_isvalid(token):
        resultDic.status = 1
        resultDic.code = 8003
        resultDic.message = 'token失效 请重新登录'
        return resultDic

    try:
        appID = info['package']['appID']
        userName = ''
        result = Token.get_token(token)
        userName = result.userName

        project = Projects.objects.get(appid=appID, owner=userName)
        fileName = CONFIG.WRITE_LUA_SCRIPT_FILE_BASE_PATH + appID + '/projectJson.json'
        writeFile(fileName, json.dumps(info['package']))
        project.edit_time = getCurrentTime()
        project.save()
    except (Exception) as e:
        resultDic.status = 1
        resultDic.code = 8004
        resultDic.message = '你不是当前工程的拥有者不能修改'

    return resultDic
def UpdeteInfo(token='', username='', nickname=''):
    resultDic = Package()
    resultDic.clear()
    if Token.check_token_isvalid(token):
        try:
            userName = ''
            result = Token.get_token(token)
            userName = result.userName
            user = User.objects.get(email=userName)
            user.name = username
            user.nickname = nickname
            user.edit_time = getCurrentTime()
            user.save()
            resultDic.status = 0
        except (Exception) as e:
            resultDic.status = 1
            resultDic.code = 5003
            resultDic.message = '服务器内部错误'

    else:
        resultDic.status = 1
        resultDic.code = 5002
        resultDic.message = 'token无效 请重新登录'

    return resultDic
示例#6
0
def saveProject(info):
	token = info['context']['token']
	resultDic = Package()
	resultDic.clear()
	if not Token.check_token_isvalid(token):
		resultDic.status = 1
		resultDic.code = 8003
		resultDic.message = 'token失效 请重新登录'
		return resultDic

	try:
		appID = info['package']['appID']
		userName = ''
		result = Token.get_token(token)
		userName = result.userName

		project = Projects.objects.get(appid=appID,owner=userName)
		fileName = CONFIG.WRITE_LUA_SCRIPT_FILE_BASE_PATH+appID+'/projectJson.json'
		writeFile(fileName,json.dumps(info['package']))
		project.edit_time = getCurrentTime()
		project.save()
	except (Exception) as e:
		resultDic.status = 1
		resultDic.code = 8004
		resultDic.message = '你不是当前工程的拥有者不能修改'

	return resultDic
示例#7
0
def UpdeteInfo(token = '' ,username ='',nickname = ''):
	resultDic = Package()
	resultDic.clear()
	if Token.check_token_isvalid(token):
		try:
			userName = ''
			result = Token.get_token(token)
			userName = result.userName
			user = User.objects.get(email=userName)
			user.name = username
			user.nickname = nickname
			user.edit_time = getCurrentTime()
			user.save()
			resultDic.status = 0
		except (Exception) as e:
			resultDic.status = 1
			resultDic.code = 5003
			resultDic.message = '服务器内部错误'

	else:
		resultDic.status = 1
		resultDic.code = 5002
		resultDic.message = 'token无效 请重新登录'

	return resultDic
示例#8
0
def optionDB(owner='', appid='', user='', option='', pre=1):
    resultDic = Package()
    resultDic.clear()
    if user == owner:
        resultDic.status = 0
        resultDic.code = 11007
        resultDic.message = '不能给自己分享'
        return resultDic

    hasShare = ShareProject.objects.filter(share_ower=owner,
                                           share_user=user,
                                           appid=appid)
    if len(hasShare) > 0 and option != '2':
        resultDic.status = 1
        resultDic.code = 11005
        resultDic.message = '已经分享过啦'
        return resultDic
    try:
        User.objects.get(email=user)
    except (Exception) as e:
        resultDic.status = 1
        resultDic.code = 11004
        resultDic.message = '分享的用户不存在'
        return resultDic

    if option == '1':
        sharepro = ShareProject(appid=appid,
                                share_user=user,
                                share_time=getCurrentTime(),
                                share_ower=owner,
                                permission=pre)
        sharepro.save()
    elif option == '2':
        sharepro = ShareProject.objects.filter(appid=appid,
                                               share_user=user,
                                               share_ower=owner)
        sharepro.delete()
    else:
        resultDic.status = 1
        resultDic.code = 11006
        resultDic.message = '未知操作'
        return resultDic

    shares = ShareProject.objects.filter(share_ower=owner)
    shareList = []
    for x in range(len(shares)):
        share = shares[x]
        users = User.objects.filter(email=share.share_user)
        for x in range(len(users)):
            user = users[x]
            userDic = {}
            userDic['email'] = '%s' % user.email
            userDic['nickname'] = '%s' % user.nickname
            shareList.append(userDic)

    resultDic.setResult(shareList)

    return resultDic
示例#9
0
def Register(userInfo):
	resultDic = Package()
	resultDic.clear()
	try:
		user = User.objects.get(email=userInfo['user_email'])
		resultDic.status = 1
		resultDic.code = 2002
		resultDic.message = '您注册的用户已存在'
	except (Exception) as e:
		try:
			user_pwd = stringToMD5(conf.PASSWD_FIXED_CHARACTER+userInfo['user_pwd'])
			user = User(name=userInfo['user_name'],
				         email= userInfo['user_email'],
				         nickname=userInfo['user_nick'],
				         password=user_pwd,
				         create_time=getCurrentTime(),
				         edit_time=getCurrentTime(),
				         last_login_time = getCurrentTime(),
				         login_source = 1,
				         signin_source = 2,
				         signin_ip = userInfo['ip'],
				         userid='000000',
				         is_ctrip = 1,
				         )
			user.save()
			token = stringToMD5(datetime.datetime.now().strftime("%Y%m%d%H%M%S"))
			Token.save_token(token,userInfo['user_email'])
			resultInfo = {}
			resultInfo['token'] = token
			resultInfo['name'] = userInfo['user_name']
			resultInfo['nickname'] = userInfo['user_nick']
			resultInfo['email'] = userInfo['user_email']
			resultDic.setResult(resultInfo)

		except (Exception) as e:
			resultDic.status = 1
			resultDic.code = 2003
			resultDic.message = '服务器内部错误'


	return resultDic
示例#10
0
def optionDB(owner = '',appid='',user='',option='',pre = 1):
	resultDic = Package()
	resultDic.clear()
	if user == owner:
		resultDic.status = 0
		resultDic.code = 11007
		resultDic.message = '不能给自己分享'
		return resultDic

	hasShare = ShareProject.objects.filter(share_ower=owner,share_user=user,appid=appid)
	if len(hasShare)>0 and option != '2':
		resultDic.status = 1
		resultDic.code = 11005
		resultDic.message = '已经分享过啦'
		return resultDic
	try:
		User.objects.get(email=user)
	except (Exception) as e:
		resultDic.status = 1
		resultDic.code = 11004
		resultDic.message = '分享的用户不存在'
		return resultDic
	
	if option == '1':
		sharepro = ShareProject(appid=appid,share_user=user,share_time=getCurrentTime(),share_ower=owner,permission=pre)
		sharepro.save()
	elif option == '2':
		sharepro = ShareProject.objects.filter(appid=appid,share_user=user,share_ower=owner)
		sharepro.delete()
	else:
		resultDic.status = 1
		resultDic.code = 11006
		resultDic.message = '未知操作'
		return resultDic


	shares = ShareProject.objects.filter(share_ower=owner)
	shareList = []
	for x in range(len(shares)):
		share = shares[x]
		users = User.objects.filter(email=share.share_user)
		for x in range(len(users)):
			user = users[x]
			userDic = {}
			userDic['email'] = '%s'%user.email
			userDic['nickname'] = '%s'%user.nickname
			shareList.append(userDic)

	resultDic.setResult(shareList)

	return resultDic
示例#11
0
def FeedBack(token = '',email = '',content = '',source = ''):
	resultDic = Package()
	resultDic.clear()
	if content == '' or content == None:
		resultDic.status = 1
		resultDic.code = 13003
		resultDic.message = '内容为空'
		return resultDic
	if source == '' or source == None:
		resultDic.status = 1
		resultDic.code = 13004
		resultDic.message = '来源为空'
		return resultDic

	user = ''
	if token == '' or token == None:
		if email == '' or email == None:
			resultDic.status = 1
			resultDic.code = 13006
			resultDic.message = '邮箱为空'
			return resultDic
		user = email
	else :
		if not Token.check_token_isvalid(token):
			resultDic.status = 1
			resultDic.code = 13002
			resultDic.message = 'toke无效 请重新登录'
			return resultDic
		else :
			result = Token.get_token(token)
			user = result.userName
        	
	try:
		feedback = Feedback(user_name=user,
							   content = content,
							   create_time = getCurrentTime() ,
							   source = source,
		)
		feedback.save()
	except (Exception) as e:
		resultDic.status = 1
		resultDic.code = 13005
		resultDic.message = '服务器内部异常'
	return resultDic
示例#12
0
def FeedBack(token = '',email = '',content = '',source = ''):
	resultDic = Package()
	resultDic.clear()
	if content == '' or content == None:
		resultDic.status = 1
		resultDic.code = 13003
		resultDic.message = '内容为空'
		return resultDic
	if source == '' or source == None:
		resultDic.status = 1
		resultDic.code = 13004
		resultDic.message = '来源为空'
		return resultDic

	user = ''
	if token == '' or token == None:
		if email == '' or email == None:
			resultDic.status = 1
			resultDic.code = 13006
			resultDic.message = '邮箱为空'
			return resultDic
		user = email
	else :
		if not Token.check_token_isvalid(token):
			resultDic.status = 1
			resultDic.code = 13002
			resultDic.message = 'toke无效 请重新登录'
			return resultDic
		else :
			result = Token.get_token(token)
			user = result[0]
        	
	try:
		feedback = Feedback(user_name=user,
							   content = content,
							   create_time = getCurrentTime() ,
							   source = source,
		)
		feedback.save()
	except (Exception) as e:
		resultDic.status = 1
		resultDic.code = 13005
		resultDic.message = '服务器内部异常'
	return resultDic
示例#13
0
def registToken(request):
    from ProtoShop.models.ProtoShop.models import DeviceToken
    resultDic = Package()
    resultDic.clear()
    if request.POST:
        token = request.POST.get('token','')
        devicetoken = request.POST.get('devicetoken','')
        if devicetoken == '':
            resultDic.status = 1
            resultDic.code = 14002
            resultDic.message = 'deviceToken为空'
        else:
            import ProtoShop.utils.token as Token
            from ProtoShop.utils.views import getCurrentTime,getIP
            if Token.check_token_isvalid(token):
                try:
                    userName = ''
                    result = Token.get_token(token)
                    userName = result.userName
                    device = DeviceToken(user_name=userName,device_token=devicetoken,device_ip=getIP(request),last_time=getCurrentTime())
                    device.save()
                except (Exception) as e:
                    resultDic.status = 1
                    resultDic.code = 14003
                    resultDic.message = '服务器内部错误'
            
    else :
        resultDic.status = 1
        resultDic.code = 14001
        resultDic.message = '请求方式不正确'

    return resultDic.archiveJson()
示例#14
0
def SSOAuthCallBack(request):
    fromSource = ''
    if request.GET:
        fromSource = request.GET.get('type', '')

    resultDic = Package()
    resultDic.clear()
    username = '******' % request.user
    if username == 'AnonymousUser':
        resultDic.status = 1
        resultDic.code = 1002
        resultDic.message = ''
    else:

        conn = MySQLdb.connect(host=conf.DB_HOST,
                               user=conf.DB_USERNAEM,
                               passwd=conf.DB_PASSWD,
                               db=conf.DB_NAME,
                               port=conf.DB_PORT,
                               charset='utf8')
        cur = conn.cursor()
        cur.execute("select * from auth_user where username = '******'" % username)
        result = cur.fetchone()
        cur.close()
        conn.close()
        isExist = False
        try:
            user = User.objects.get(email=result[7])
            user.name = result[4]
            user.nickname = result[6].encode('utf8')
            user.save()
            isExist = True
        except (Exception) as e:
            isExist = False

        if isExist == False:
            user_pwd = stringToMD5(conf.PASSWD_FIXED_CHARACTER + result[4])
            user = User(
                name=result[4],
                email=result[7],
                nickname=result[6].encode('utf8'),
                password=user_pwd,
                create_time=getCurrentTime(),
                edit_time=getCurrentTime(),
                last_login_time=getCurrentTime(),
                login_source=1,
                signin_source=2,
                signin_ip='127.0.0.1',
                userid='000000',
                is_ctrip=1,
            )
            user.save()
        token = stringToMD5(datetime.datetime.now().strftime("%Y%m%d%H%M%S"))
        Token.save_token(token, result[7])
        resultInfo = {}
        resultInfo['token'] = token
        resultInfo['name'] = result[4]
        resultInfo['nickname'] = result[6].encode('utf8')
        resultInfo['email'] = result[7]
        resultDic.setResult(resultInfo)
    if fromSource == 'mobile':
        return resultDic.archiveJson()
    return resultDic.archiveJavaScript()