public JsonResult Login(string system, string username, string password)
        {
            if (!this.model.IsLoginRequired(system))
            {
                return(this.Json(new { isSuccess = true }));
            }

            try
            {
                if (this.model.Login(system, username, password))
                {
                    var cookie           = this.HttpContext.Request.Cookies.Get("sqleditor");
                    var userKey          = cookie != null ? cookie.Value : string.Empty;
                    var connString       = this.model.GetUserConnectionString(system, username, password).ConnectionString;
                    var cryptoConnString = Crypto.Encrypt(connString, KeyProvider.GetUserSpecificSecretKey(userKey));
                    this.Session.Add(system, cryptoConnString);
                    return(this.Json(new { isSuccess = true }));
                }
            }
            catch (Exception ex)
            {
                return(this.Json(new { isSuccess = false, message = ex.Message }));
            }

            return(this.Json(new { isSuccess = false }));
        }
示例#2
0
        public JsonResult Query(string sql, string system)
        {
            if (!this.userModel.IsLoginRequired(system))
            {
                return(this.Json(this.gridModel.Query(sql, this.config.GetConnectionSettings(system))));
            }

            var session = (byte[])this.Session[system];

            if (session == null)
            {
                return(this.Json(new { isLoginRequired = true }));
            }

            var cookie     = this.Request.Cookies.Get("sqleditor");
            var userKey    = cookie != null ? cookie.Value : string.Empty;
            var connString = Crypto.Decrypt(session, KeyProvider.GetUserSpecificSecretKey(userKey));
            var settings   = new ConnectionStringSettings(
                system,
                connString,
                this.config.GetConnectionSettings(system).ProviderName);

            return(this.Json(this.gridModel.Query(sql, settings)));
        }