Пример #1
0
 public JObject ForgetUsername()
 {
     try
     {
         var email = _httpContextProxy.GetQueryString(CommonConst.CommonField.EMAIL);
         if (email == null)
         {
             return(_responseBuilder.BadRequest());
         }
         var users = _znxtUserService.GetUsersByEmail(email);
         if (users.Any())
         {
             if (_userNotifierService.SendForgetUsernamesEmailAsync(users).GetAwaiter().GetResult())
             {
                 return(_responseBuilder.Success());
             }
         }
         else
         {
             _logger.Error($"No user found for email : {email}");
         }
         return(_responseBuilder.Success());
     }
     catch (Exception ex)
     {
         _logger.Error(ex.Message, ex);
         return(_responseBuilder.ServerError());
     }
 }
Пример #2
0
 public JObject GetOAuthClientById()
 {
     try
     {
         string  clientid = _httpContextProxy.GetQueryString("client_id");
         JObject filter   = new JObject()
         {
             ["client_id"]  = clientid,
             ["is_enabled"] = true
         };
         var data = _rDBService.Get <OAuthClientModelDbo>(OAUTH_CLIENT_TABLE, 1, 0, filter);
         if (data.Any())
         {
             var client = data.First();
             OAuthClientModelDto clientDto = GetDto(client, GetOAuthClientRoles(client), GetOAuthClientIPs(client));
             return(_responseBuilder.Success(clientDto.ToJObject()));
         }
         else
         {
             return(_responseBuilder.NotFound());
         }
     }
     catch (Exception ex)
     {
         _logger.Error(ex.Message, ex);
         return(_responseBuilder.ServerError());
     }
 }
Пример #3
0
        public JObject GetImage()
        {
            var    imageid = _httpContextProxy.GetQueryString("id");
            string filter  = "{" + CommonConst.CommonField.DISPLAY_ID + ":'" + imageid + "'}";
            JArray data    = _dBService.Get(collection, new RawQuery(filter));

            if (data.Count == 0)
            {
                return(_responseBuilder.NotFound());
            }
            return(_responseBuilder.Success(data.First() as JObject));
        }
Пример #4
0
        public string GetJS()
        {
            try
            {
                _logger.Debug("Calling Get JS ");
                var path = _httpContextProxy.GetQueryString("path");
                if (string.IsNullOrEmpty(path))
                {
                    _logger.Error("Path is missing in the query string");
                    return(null);
                }
                var filterQuery = "{" + CommonConst.CommonField.FILE_PATH + ":/.js$/i,'override_by' :'none'}";
                var data        = _dBService.Get(CommonConst.Collection.STATIC_CONTECT, new RawQuery(filterQuery), new List <string> {
                    CommonConst.CommonField.FILE_PATH, CommonConst.CommonField.DISPLAY_ID
                });
                _logger.Debug("Fetch value from Get JS");

                var listOfArrays = new StringBuilder();
                var queryRecords = data.Select(l => new
                {
                    length    = l[CommonConst.CommonField.FILE_PATH].ToString().Length,
                    file_path = l[CommonConst.CommonField.FILE_PATH].ToString(),
                    id        = l[CommonConst.CommonField.DISPLAY_ID].ToString()
                }).OrderBy(o => o.length).ToList();

                _logger.Debug("Apply by Order by Get JS");
                foreach (var item in queryRecords)
                {
                    if (!string.IsNullOrEmpty(item.file_path) && item.file_path.IndexOf(path) == 0)
                    {
                        string jspath = item.file_path;
                        listOfArrays.AppendLine(string.Empty);
                        listOfArrays.AppendLine(string.Format("/***** File: {0}   ******/", item.file_path));
                        var content = _staticContentHandler.GetStringContentAsync(item.file_path).GetAwaiter().GetResult();
                        if (!string.IsNullOrEmpty(content))
                        {
                            listOfArrays.AppendLine(string.Empty);
                            listOfArrays.Append($"/* */{content.Remove(0,1)}/* */");
                        }
                    }
                }

                return(listOfArrays.ToString());
            }
            catch (Exception ex)
            {
                _logger.Error(string.Format("Error in GetJs {0}", ex.Message), ex);
                return($"/****Error {ex.Message} , {ex.StackTrace }****/");
            }
        }
Пример #5
0
 private async Task BuildRequestUrl(HttpRequestMessage request, string method, string route, string querystring, string baseUrl)
 {
     if (string.IsNullOrEmpty(baseUrl))
     {
         baseUrl = await GetBaseUrl(method, route);
     }
     request.Method = new HttpMethod(method);
     if (string.IsNullOrEmpty(querystring))
     {
         querystring = _httpContextProxy.GetQueryString();
     }
     if (!string.IsNullOrEmpty(querystring) && querystring.IndexOf("?") != 0)
     {
         querystring = $"?{querystring}";
     }
     if (route.IndexOf("~/") == 0)
     {
         request.RequestUri = new Uri($"{baseUrl}{route.Remove(0, 1)}{querystring}");
     }
     else
     {
         request.RequestUri = new Uri($"{baseUrl}/api{route}{querystring}");
     }
 }
Пример #6
0
 public void Error(string message, Exception ex)
 {
     if (LogLevels.Contains("Error"))
     {
         JObject logData = null;
         if (_httpContextProxy != null)
         {
             logData = new JObject()
             {
                 ["RequestBody"]        = _httpContextProxy.GetRequestBody(),
                 ["RequestUrl"]         = _httpContextProxy.GetURIAbsolutePath(),
                 ["RequestQueryString"] = _httpContextProxy.GetQueryString()
             };
             logData["RequestHeader"] = string.Join(";", _httpContextProxy.GetHeaders().Select(f => string.Format("{0}:{1}", f.Key, f.Value)));
         }
         Error(message, ex, logData);
     }
 }
Пример #7
0
        public JObject IsOTPLoginRequired()
        {
            try
            {
                var user_name = _httpContextProxy.GetQueryString("user_name");
                if (!string.IsNullOrEmpty(user_name))
                {
                    var data = _ZNxtUserService.GetUserByUsername(user_name);
                    if (data != null)
                    {
                        if (data.roles.Where(f => f == "init_login_email_otp").Any())
                        {
                            return(_responseBuilder.Success());
                        }
                        else
                        {
                            return(_responseBuilder.BadRequest());
                        }
                    }
                    else
                    {
                        return(_responseBuilder.BadRequest());
                    }
                }
                else
                {
                    return(_responseBuilder.BadRequest());
                }
            }

            catch (Exception ex)
            {
                _logger.Error(ex.Message, ex);
                return(_responseBuilder.ServerError());
            }
        }
Пример #8
0
        private static Dictionary <string, dynamic> SetDefaultModel(IDBService dbProxy, IHttpContextProxy httpProxy, ILogger logger, IViewEngine viewEngine, IActionExecuter actionExecuter, Dictionary <string, dynamic> model, string folderPath = null)
        {
            ISessionProvider sessionProvider = new SessionProvider(httpProxy, dbProxy, logger);

            if (model == null)
            {
                model = new Dictionary <string, dynamic>();
            }
            model[CommonConst.CommonValue.METHODS] = new Dictionary <string, dynamic>();

            Func <string, string, JArray> getData =
                (string collection, string filter) =>
            {
                return(dbProxy.Get(collection, filter));
            };
            Func <string, string> getAppSetting =
                (string key) =>
            {
                var response = AppSettingService.Instance.GetAppSettingData(key);
                if (string.IsNullOrEmpty(response))
                {
                    response = ConfigurationManager.AppSettings[key];
                }
                return(response);
            };
            Func <string, JObject> getSessionValue =
                (string key) =>
            {
                return(sessionProvider.GetValue <JObject>(key));
            };
            Func <string, string> includeTemplete = (string templatePath) =>
            {
                FileInfo fi   = new FileInfo(string.Format("c:\\{0}{1}", folderPath, templatePath));
                string   path = fi.FullName.Replace("c:", "");
                model[CommonConst.CommonValue.PAGE_TEMPLATE_PATH] = path;
                return(string.Empty);
            };
            Func <string, bool> authorized = (string authGroups) =>
            {
                var sessionUser = sessionProvider.GetValue <UserModel>(CommonConst.CommonValue.SESSION_USER_KEY);
                if (sessionUser == null)
                {
                    return(false);
                }

                if (!authGroups.Split(',').Where(i => sessionUser.groups.Contains(i)).Any())
                {
                    return(false);
                }
                else
                {
                    return(true);
                }
            };
            Func <string, JObject, JObject> ActionExecute =
                (string actionPath, JObject data) =>
            {
                var param = ActionExecuterHelper.CreateParamContainer(null, httpProxy, logger, actionExecuter);

                if (data != null)
                {
                    foreach (var item in data)
                    {
                        Func <dynamic> funcValue = () => { return(item.Value); };
                        param.AddKey(item.Key, funcValue);
                    }
                }
                return(actionExecuter.Exec <JObject>(actionPath, dbProxy, param));
            };

            Func <string, JObject, Dictionary <string, dynamic> > IncludeModel =
                (string includeModelPath, JObject data) =>
            {
                try
                {
                    var param = ActionExecuterHelper.CreateParamContainer(null, httpProxy, logger, actionExecuter);

                    Dictionary <string, dynamic> modelData = new Dictionary <string, dynamic>();

                    if (data != null)
                    {
                        foreach (var item in data)
                        {
                            Func <dynamic> funcValue = () => { return(item.Value); };
                            param.AddKey(item.Key, funcValue);
                        }
                    }

                    object response = actionExecuter.Exec(includeModelPath, dbProxy, param);
                    if (response is Dictionary <string, dynamic> )
                    {
                        return(response as Dictionary <string, dynamic>);
                    }
                    else
                    {
                        throw new InvalidCastException(string.Format("Invalid respone from {0}", includeModelPath));
                    }
                }
                catch (UnauthorizedAccessException ex)
                {
                    logger.Error(string.Format("Error While executing Route : {0}, Error : {1}", includeModelPath, ex.Message), ex);
                    throw;
                }
            };

            model[CommonConst.CommonValue.METHODS]["IncludeModel"] = IncludeModel;

            model[CommonConst.CommonValue.METHODS]["ExecuteAction"] = ActionExecute;

            model[CommonConst.CommonValue.METHODS]["InclueTemplate"] = includeTemplete;

            model[CommonConst.CommonValue.METHODS]["GetData"] = getData;

            Func <JObject> requestBody = () => httpProxy.GetRequestBody <JObject>();

            model[CommonConst.CommonValue.METHODS]["RequestBody"] = requestBody;

            Func <string, string> queryString = (string key) => httpProxy.GetQueryString(key);

            model[CommonConst.CommonValue.METHODS]["QueryString"] = queryString;

            model[CommonConst.CommonValue.METHODS]["AppSetting"] = getAppSetting;

            model[CommonConst.CommonValue.METHODS]["GetSessionData"] = getSessionValue;

            model[CommonConst.CommonValue.METHODS]["Authorized"] = authorized;

            Func <string, JObject, string> includeBlock =
                (string blockPath, JObject blockModel) =>
            {
                var inputBlockModel = new Dictionary <string, dynamic>();
                if (blockModel != null)
                {
                    foreach (var item in blockModel)
                    {
                        inputBlockModel[item.Key] = item.Value;
                    }
                }
                if (model != null)
                {
                    foreach (var item in model)
                    {
                        inputBlockModel[item.Key] = item.Value;
                    }
                }
                FileInfo fi   = new FileInfo(string.Format("c:\\{0}{1}", folderPath, blockPath));
                string   path = fi.FullName.Replace("c:", "");
                var      data = StaticContentHandler.GetStringContent(dbProxy, logger, path);
                data = viewEngine.Compile(data, path, ServerPageModelHelper.SetDefaultModel(dbProxy, httpProxy, logger, viewEngine, actionExecuter, inputBlockModel, path.Replace(fi.Name, "")));
                return(data);
            };

            model[CommonConst.CommonValue.METHODS]["Include"] = includeBlock;

            Func <string> randerBody = () =>
            {
                if (model.ContainsKey(CommonConst.CommonValue.RENDERBODY_DATA))
                {
                    return(model[CommonConst.CommonValue.RENDERBODY_DATA]);
                }
                else
                {
                    return(string.Empty);
                }
            };

            model[CommonConst.CommonValue.METHODS]["RenderBody"] = randerBody;

            return(model);
        }
Пример #9
0
        public virtual async Task <JObject> CallRemoteRouteCalls(HttpContext context, RoutingModel route)
        {
            var appToken = "route-call";

            _logger.Debug(string.Format("Executing remote route:{0}:{1}", route.Method, route.Route));
            var headers = new Dictionary <string, string>();

            headers[CommonConst.CommonField.API_AUTH_TOKEN] = appToken;
            var response = await _apiGatewayService.CallAsync(_httpContextProxy.GetHttpMethod(), _httpContextProxy.GetURIAbsolutePath(), _httpContextProxy.GetQueryString(), _httpContextProxy.GetRequestBody <JObject>(), headers);

            return(response);
        }
Пример #10
0
        protected JObject GetPaggedData(string collection, JArray joins = null, string overrideFilters = null, Dictionary <string, int> sortColumns = null, List <string> fields = null)
        {
            int pageSize = 10, pageSizeData = 0;
            int currentPage = 1, currentPageData = 0;

            if (int.TryParse(HttpProxy.GetQueryString("pagesize"), out pageSizeData))
            {
                pageSize = pageSizeData;
            }

            if (int.TryParse(HttpProxy.GetQueryString("currentpage"), out currentPageData))
            {
                currentPage = currentPageData;
            }
            string filterQuery = HttpProxy.GetQueryString("filter");

            if (string.IsNullOrEmpty(filterQuery))
            {
                filterQuery = CommonConst.EMPTY_JSON_OBJECT;
            }
            if (!string.IsNullOrEmpty(overrideFilters))
            {
                filterQuery = overrideFilters;
            }

            var sortData = HttpProxy.GetQueryString("sort");

            if (sortData != null)
            {
                sortColumns = (Dictionary <string, int>)JsonConvert.DeserializeObject <Dictionary <string, int> >(sortData);
            }
            if (sortColumns == null)
            {
                sortColumns = new Dictionary <string, int>();
                sortColumns[CommonConst.CommonField.CREATED_DATA_DATE_TIME] = -1;
            }

            if (fields == null)
            {
                fields = new List <string>();
            }
            if (HttpProxy.GetQueryString("fields") != null)
            {
                fields = new List <string>();
                fields.AddRange(HttpProxy.GetQueryString("fields").Split(','));
            }
            DBQuery query = new DBQuery();

            foreach (var field in fields)
            {
                query.Fields.Add(new Field(field));
            }
            foreach (var sort in sortColumns)
            {
                query.SortBy.Add(new SortField(sort.Key, (SortType)sort.Value));
            }

            var data = GetPagedData(collection, query, filterQuery, pageSize, currentPage);

            if (data[CommonConst.CommonField.DATA] != null && (data[CommonConst.CommonField.DATA] as JArray).Count > 0)
            {
                DoJoins(data, collection, joins);
            }
            return(data);
        }