Exemplo n.º 1
0
	def post(self):
		if self.body_json_object is None:
			self.exception_handle(
				'Request data format exception, %s' % self.request.uri)
			return
		tel = self.body_json_object.get('tel')
		if tel is None or len(tel) == 0:
			self.exception_handle('Missing argument \'tel\'')
			return
		if not re.match(r'^[1][0-9]{10}$', tel):
			self.exception_handle('\'tel\' format is not correct')
			return
		code = random.randint(100000, 999999)
		# TODO Send SMS message
		print 'Your auth code is %s' % code
		logger.debug('Your auth code is %s' % code)
		r = common.get_redis_0()
		if r is None:
			self.exception_handle('Invalid Redis connection')
			return
		try:
			r.set(tel, code, ex=config.AuthCode_ExpireTime) # Block ?
		except Exception, e:
			self.exception_handle('The database operation failed (Redis.Set)')
			return
Exemplo n.º 2
0
	def post(self):
		if self.body_json_object is None:
			self.exception_handle(config.json_parameter_error, 
				'Request data format exception, %s' % self.request.uri)
			return
		tel = self.body_json_object.get('tel')
		if tel is None or len(tel) == 0:
			self.exception_handle(config.tel_not_found, 'Missing argument \'tel\'')
			return
		if not re.match(r'^[1][0-9]{10}$', tel):
			self.exception_handle(config.tel_format_not_correct,'\'tel\' format is not correct')
			return
		key = self.body_json_object.get('key')
		if self.check_key(key) == False:
			return
		r = common.get_redis_0()
		if r is None:
			self.exception_handle(config.connect_redis_failed,'Invalid Redis connection')
			return
		xcode = None
		try:
			xcode = r.get(tel)
		except Exception, e:
			self.exception_handle(config.connect_redis_failed,'The database operation failed (Redis.Get)')
			return
Exemplo n.º 3
0
	def post(self):
		if self.body_json_object is None:
			self.exception_handle(config.json_parameter_error,'Request data format exception, %s' % self.request.uri)
			return
		tel = self.body_json_object.get('tel')
		if tel is None or len(tel) == 0:
			self.exception_handle(config.tel_not_found,'Missing argument \'tel\'')
			return
		if not re.match(r'^[1][0-9]{10}$', tel):
			self.exception_handle(config.tel_format_not_correct,'\'tel\' format is not correct')
			return
		request_password = self.body_json_object.get('password')
		if request_password is None or len(request_password) == 0:
			self.exception_handle(config.userid_or_password_wrong,'Missing argument \'password\'')
			return
		password_md5 = hashlib.md5(request_password).hexdigest()
		print "request_password %s" % password_md5
		request_password = password_md5
		code = self.body_json_object.get('key')
		if code is None or len(code) == 0:
			self.exception_handle(config.key_error,'Missing argument \'key\'')
			return
		if len(code) <> 6:
			self.exception_handle(config.key_error,'Auth code format exception, %s' % code)
			return
		r = common.get_redis_0()
		if r is None:
			self.exception_handle(config.connect_redis_failed,'Invalid Redis connection')
			return
		xcode = None
		try:
			xcode = r.get(tel)
		except Exception, e:
			self.exception_handle(config.connect_redis_failed,'The database operation failed (Redis.Get)')
			return
Exemplo n.º 4
0
	def post(self):
		if self.body_json_object is None:
			self.exception_handle(
				'Request data format exception, %s' % self.request.uri)
			return
		tel = self.body_json_object.get('tel')
		if tel is None or len(tel) == 0:
			self.exception_handle('Missing argument \'tel\'')
			return
                if not re.match(r'^[1][0-9]{10}$', tel):
                        self.exception_handle('\'tel\' format is not correct')
                        return
		request_password = self.body_json_object.get('password')
		if request_password is None or len(request_password) == 0:
			self.exception_handle('Missing argument \'password\'')
			return
		code = self.body_json_object.get('code')
		if code is None or len(code) == 0:
			self.exception_handle('Missing argument \'code\'')
			return
                if len(code) <> 6:
                        self.exception_handle('Auth code format exception, %s' % code)
                        return
                r = common.get_redis_0()
                if r is None:
                        self.exception_handle('Invalid Redis connection')
                        return
                xcode = None
                try:
                        xcode = r.get(tel)
                except Exception, e:
                        self.exception_handle('The database operation failed (Redis.Get)')
                        return
Exemplo n.º 5
0
	def post(self):
		if self.body_json_object is None:
			self.exception_handle(config.json_parameter_error, 
				'Request data format exception, %s' % self.request.uri)
			return
		tel = self.body_json_object.get('tel')
		if tel is None or len(tel) == 0:
			self.exception_handle(config.tel_not_found, 'Missing argument \'tel\'')
			return
		if not re.match(r'^[1][0-9]{10}$', tel):
			self.exception_handle(config.tel_format_not_correct,'\'tel\' format is not correct')
			return
		user_type = self.body_json_object.get('type')
		if user_type is None:
			self.exception_handle(config.userid_or_password_wrong, 'Missing argument \'user type\'')
			return
		if int(user_type) == 0:
			user = yield UserSQLHelper.check_profile_by_tel(tel)
			if user == 1:
				self.exception_handle(config.user_exist,'tel is exit')
				return 
		code = random.randint(100000, 999999)
		logger.debug('Your auth code is %s' % code)

		# TODO Send SMS message
		ret = self.sendsns(tel,[code,'2'])
		logger.debug('ret: %s' % ret)
		#if not ret.has_key('statusCode') or cmp(ret['statusCode'],'000000') <> 0:
		#	self.exception_handle('auth SMS send failed')
		#	return
		r = common.get_redis_0()
		if r is None:
			self.exception_handle(config.connect_redis_failed, 'Invalid Redis connection')
			return
		try:
			r.set(tel, code, ex=config.AuthCode_ExpireTime) # Block ?
		except Exception, e:
			self.exception_handle(config.connect_redis_failed, 'The database operation failed (Redis.Set)AuthKeyHandler')
			return