def __init__(self): user = AppInfo.system_credentials() self.session_id = AppInfo.login(user['username'], user['password']) if self.session_id == None: create_logger(__name__).info( "username / password wrong or user is disaled") context = AppInfo.create_context(self.session_id) context.get_session_values()['timer_interval'] = 0 context.get_session_values()['timer_unit'] = 'm' AppInfo.save_context(context)
def before_request(): g.context=None if AppInfo.get_current_config('instance','enable_swagger_doc',0)==0: if request.endpoint=='doc': abort(404, "Not enabled") logger.info(f"Endpoint: {request.endpoint}") if request.endpoint!='api.login' and request.endpoint!='ui.login': if 'session_id' in session: try: g.context=AppInfo.create_context(session['session_id']) except NameError as err: abort(400, f"Session_id found in session context: error raised: {err}") pass else: #do not set session['session_id'] because the #guest session will be automaticly deactivated. username="" password="" if 'restapi_username' in request.headers: username=request.headers['restapi-username'] password=request.headers['restapi-password'] elif 'username' in request.headers: username=request.headers['username'] password=request.headers['password'] else: guest=AppInfo.guest_credentials() username=guest['username'] password=guest['password'] session_id=AppInfo.login(username,password) if session_id==None: print(f"try to login with username: {username}") abort(400,'Wrong username or password') g.context=AppInfo.create_context(session_id, auto_logoff=True) for arg in request.args: g.context.set_arg(arg, request.args[arg])
def post(self): username = "" password = "" next = HTTPRequest.redirect(request) if 'username' in request.headers: username = request.headers.get("username") password = request.headers.get("password") elif 'username' in request.form: username = request.form.get("username") password = request.form.get("password") elif 'restapi_username' in request.form: username = request.form.get("restapi_username") password = request.form.get("restapi_password") log.create_logger(__name__).info(f"{username} {password}") session_id = AppInfo.login(username, password) log.create_logger(__name__).info(f"{request.accept_mimetypes}") if session_id == None: if next == None: abort(400, 'wrong username or password') else: return redirect( f"/ui/login?redirect={next}&msg=Wrong username or password", code=302) else: session['session_id'] = session_id g.context = AppInfo.create_context(session_id) if next == None: response = make_response({ "session_id": session_id, "status": "logged_on" }) response.headers['content-type'] = 'text/json' return response else: return redirect(next, code=302)
def setUp(self): AppInfo.init(__name__, CONFIG['default']) session_id = AppInfo.login("root", "password") self.context = AppInfo.create_context(session_id)
logger=create_logger(__name__) parser = argparse.ArgumentParser(description='Build the metadata cache.') parser.add_argument('--user','-u', type=str, help='restapi user') parser.add_argument('--password','-p', type=str, help='restapi password') args = parser.parse_args() user=args.user password=args.password AppInfo.init(__name__, CONFIG['default']) print(f"Host............:{AppInfo.get_current_config('mysql','host')}") print(f"Database........:{AppInfo.get_current_config('mysql','database')}") print(f"User............:{AppInfo.get_current_config('mysql','user')}") session_id=AppInfo.login(args.user,args.password) if session_id==None: print(f"connot log in") sys.exit(-1) print(f"Session.........:{session_id}") context=AppInfo.create_context(session_id) build_table_fields_meta(context) AppInfo.save_context(context, True) AppInfo.logoff(context)