예제 #1
0
파일: login.py 프로젝트: cyberhck/netforce
 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()
         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")
예제 #2
0
파일: static.py 프로젝트: jzoldyck/netforce
def make_ui_params():
    print("building ui_params...")
    data = {}
    data["version"] = netforce.get_module_version()
    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)