def request_loader(request): if not request.form: return if not UserService.authenticate(request.form): return user = User user.id = request.form["username"] user.is_authenticated = True return user
def main(): try: transport = TSocket.TSocket('localhost', 9090) transport = TTransport.TBufferedTransport(transport) protocol = TBinaryProtocol.TBinaryProtocol(transport) client = UserService.Client(protocol) # Connect transport.open() # request req = UserListReq() req.uidList = [1, 2] result = client.userList(req) print result # Close transport.close() except Thrift.TException as e: print e except ApiErrorException as e: print e
def user_loader(username): if not UserService.isUser(username): return user = User user.id = username return user
from flask_cors import CORS from bson.objectid import ObjectId from Controllers.UserController import UserController from Controllers.PropertyController import PropertyController from Services.UserService import UserService from Models.User import User app = Flask(__name__) CORS(app) app.secret_key = "air bnb lite" app.config['MONGO_DBNAME'] = 'airbnblite' app.config['MONGO_URI'] = 'mongodb://localhost:27017/airbnblite' mongo = PyMongo(app) UserService = UserService() User = User() UserController = UserController() PropertyController = PropertyController() SessionService = LoginManager() SessionService.init_app(app) #Authentication setup @SessionService.user_loader def user_loader(username): if not UserService.isUser(username): return user = User user.id = username return user
def getUserDetails(userid): userService = UserService() return jsonify(userService.getUserDetails(userid))
def validateUser(): username_password = request.get_json(force=True) userService = UserService() return jsonify(userService.validateUsernamePassword(username_password))
def submitUserDetails(): userService = UserService() jsonRequest = request.get_json() return jsonify(userService.submitUserDetails(jsonRequest))
uid_list = req.uidList if not uid_list: raise Exception('参数错误', ErrCodeEnum.PARAM_ERROR) user_list_all = self.get_user_by_uid_list(uid_list) if not user_list_all: raise Exception('服务器错误', ErrCodeEnum.SERVER_ERROR) user_list_resp = UserListResp(user_list_all) return user_list_resp except Exception as e: print e raise ApiErrorException(e.getCode(), e.getMessage()) if __name__ == '__main__': handler = UserInfoHandler() processor = UserService.Processor(handler) transport = TSocket.TServerSocket(host='127.0.0.1', port=9090) tfactory = TTransport.TBufferedTransportFactory() pfactory = TBinaryProtocol.TBinaryProtocolFactory() # 简单服务器模式 server = TServer.TSimpleServer(processor, transport, tfactory, pfactory) # 线程模式 # server = TServer.TThreadedServer( # processor, transport, tfactory, pfactory) print "Starting thrift server in python..." server.serve() print "done!"
from Services.UserService import UserService from Services.TrainingService import TrainingService from Services.LtasService import LtasService from Services.SpectrumService import SpectrumService from Repositories.RepositoryProvider import * user_service = UserService(user_repository, training_repository) training_service = TrainingService(training_repository, user_repository, lecture_repository, sound_repository) ltas_service = LtasService(ltas_repository, sound_repository) spectrum_service = SpectrumService(spectrum_repository, sound_repository)