Exemplo n.º 1
0
 def login(self, context={}):
     set_active_user(None)
     data = context["data"]
     db_name = data.get("db_name")
     if not db_name:
         raise Exception("Missing db name")
     database.set_active_db(db_name)
     login = data["login"]
     password = data["password"]
     user_id = get_model("base.user").check_password(login, password)
     if not user_id:
         audit_log("Invalid login (%s)" % login)
         db = database.get_connection()
         db.commit()
         raise Exception("Invalid login")
     try:
         print("login ok", login)
         set_active_user(1)
         user = get_model("base.user").browse(user_id)
         if user.profile_id.prevent_login or not user.active:
             raise Exception("User not allowed to login")
         t = time.strftime("%Y-%m-%d %H:%M:%S")
         user.write({"lastlog": t})
         profile = user.profile_id
         action = profile.home_action or "account_board"
         token = new_token(db_name, user_id)
         db = database.get_connection()
         res = db.get("SELECT * FROM pg_class WHERE relname='settings'")
         settings = get_model("settings").browse(1)
         version = settings.version
         mod_version = get_module_version_name()
         if version != mod_version:
             raise Exception("Database version (%s) is different than modules version (%s), please upgrade database before login." % (
                 version, mod_version))
         company_id = user.company_id.id or profile.login_company_id.id
         if not company_id:
             res = get_model("company").search([["parent_id", "=", None]])
             if not res:
                 raise Exception("No company found")
             company_id = res[0]
         comp = get_model("company").browse(company_id)
         return {
             "cookies": {
                 "dbname": database.get_active_db(),
                 "user_id": user_id,
                 "token": token,
                 "user_name": user.name,
                 "package": settings.package,
                 "company_id": company_id,
                 "company_name": comp.name,
             },
             "next": {
                 "type": "url",
                 "url": "/ui#name=%s" % action,
             },
             "login_action": action,
         }
     finally:
         set_active_user(user_id)
         audit_log("Login")
Exemplo n.º 2
0
 def load_ui_params(self,context={}):
     actions=action.actions_to_json(modules=context.get("modules"))
     layouts=layout.layouts_to_json(modules=context.get("modules"),mobile_only=context.get("mobile_only"))
     models=model.models_to_json()
     return {
         "version_name": get_module_version_name(),
         "version_code": get_module_version_code(),
         "actions": actions,
         "layouts": layouts,
         "models": models,
     }
Exemplo n.º 3
0
def make_ui_params():
    print("building ui_params...")
    data = {}
    data["version"] = netforce.get_module_version_name()
    data["models"] = model.models_to_json()
    data["actions"] = action.actions_to_json()
    data["layouts"] = layout.layouts_to_json()
    data["templates"] = template.templates_to_json()
    if data:
        if not os.path.exists("static"):
            os.makedirs("static")
        print("  => static/ui_params.json")
        s = json.dumps(data, sort_keys=True, indent=4, separators=(',', ': '))
        open("static/ui_params.json", "w").write(s)
Exemplo n.º 4
0
def make_ui_params():
    print("building ui_params...")
    data = {}
    data["version"] = netforce.get_module_version_name()
    data["models"] = model.models_to_json()
    data["actions"] = action.actions_to_json()
    data["layouts"] = layout.layouts_to_json()
    data["templates"] = template.templates_to_json()
    if data:
        if not os.path.exists("static"):
            os.makedirs("static")
        print("  => static/ui_params.json")
        s = json.dumps(data, sort_keys=True, indent=4, separators=(',', ': '))
        open("static/ui_params.json", "w").write(s)
Exemplo n.º 5
0
 def load_ui_params(self, context={}):
     actions = action.actions_to_json(modules=context.get("modules"))
     layouts = layout.layouts_to_json(
         modules=context.get("modules"),
         mobile_only=context.get("mobile_only"))
     models = model.models_to_json()
     templates = template.templates_to_json(modules=context.get("modules"))
     return {
         "version_name": get_module_version_name(),
         "version_code": get_module_version_code(),
         "actions": actions,
         "layouts": layouts,
         "models": models,
         "templates": templates,
     }
Exemplo n.º 6
0
 def get_version(self,context={}):
     return {
         "version_name": get_module_version_name(),
         "version_code": get_module_version_code(),
     }
Exemplo n.º 7
0
 def login(self, context={}):
     set_active_user(None)
     data = context["data"]
     db_name = data.get("db_name")
     if not db_name:
         raise Exception("Missing db name")
     database.set_active_db(db_name)
     login = data["login"]
     password = data["password"]
     user_id = get_model("base.user").check_password(login, password)
     if not user_id:
         audit_log("Invalid login (%s)" % login)
         db = database.get_connection()
         db.commit()
         raise Exception("Invalid login")
     try:
         print("login ok", login)
         set_active_user(1)
         user = get_model("base.user").browse(user_id)
         if user.profile_id.prevent_login or not user.active:
             raise Exception("User not allowed to login")
         t = time.strftime("%Y-%m-%d %H:%M:%S")
         user.write({"lastlog": t})
         profile = user.profile_id
         action = profile.home_action or "account_board"
         token = new_token(db_name, user_id)
         db = database.get_connection()
         res = db.get("SELECT * FROM pg_class WHERE relname='settings'")
         settings = get_model("settings").browse(1)
         version = settings.version
         mod_version = get_module_version_name()
         if version != mod_version:
             raise Exception(
                 "Database version (%s) is different than modules version (%s), please upgrade database before login."
                 % (version, mod_version))
         company_id = user.company_id.id or profile.login_company_id.id
         if not company_id:
             res = get_model("company").search([["parent_id", "=", None]])
             if not res:
                 raise Exception("No company found")
             company_id = res[0]
         comp = get_model("company").browse(company_id)
         return {
             "cookies": {
                 "dbname": database.get_active_db(),
                 "user_id": user_id,
                 "token": token,
                 "user_name": user.name,
                 "package": settings.package,
                 "company_id": company_id,
                 "company_name": comp.name,
             },
             "next": {
                 "type": "url",
                 "url": "/ui#name=%s" % action,
             },
             "login_action": action,
         }
     finally:
         set_active_user(user_id)
         audit_log("Login")
Exemplo n.º 8
0
 def get_version(self, context={}):
     return {
         "version_name": get_module_version_name(),
         "version_code": get_module_version_code(),
     }