示例#1
0
def Login(email='', passwd=''):
    '''
	用户登录

	param email 登录用户名
	param passwd   用户密码(MD5加密)
	'''
    resultDic = Package()
    resultDic.clear()
    try:
        newPasswd = stringToMD5(conf.PASSWD_FIXED_CHARACTER + passwd)
        user = User.objects.get(email=email, password=newPasswd)
        resultDic.status = 0
        result = {}
        token = stringToMD5(datetime.datetime.now().strftime("%Y%m%d%H%M%S"))
        Token.save_token(token, user.email)
        result['token'] = token
        result['email'] = user.email
        result['name'] = user.name
        result['nickname'] = user.nickname
        resultDic.setResult(result)

    except (Exception) as e:
        resultDic.status = 1
        resultDic.code = 1002
        resultDic.message = '用户名或密码错误'

    return resultDic
示例#2
0
def Login(email='',passwd=''):
	'''
	用户登录

	param email 登录用户名
	param passwd   用户密码(MD5加密)
	'''
	resultDic = Package()
	resultDic.clear()
	try:
		newPasswd = stringToMD5(conf.PASSWD_FIXED_CHARACTER+passwd)
		user = User.objects.get(email=email,password=newPasswd)
		resultDic.status = 0
		result = {}
		token = stringToMD5(datetime.datetime.now().strftime("%Y%m%d%H%M%S"))
		Token.save_token(token,user.email)
		result['token'] = token;
		result['email'] = user.email;
		result['name'] = user.name;
		result['nickname'] = user.nickname;
		resultDic.setResult(result)
			
	except (Exception) as e:
		resultDic.status = 1
		resultDic.code = 1002
		resultDic.message = '用户名或密码错误'

	return resultDic
示例#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 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
示例#5
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()