Exemple #1
0
        public JObject Send()
        {
            var model = _httpContextProxy.GetRequestBody <NotifyModel>();

            if (model == null)
            {
                return(_responseBuilder.BadRequest());
            }
            var to      = model.To.Split(';').ToList();
            var message = model.Message;

            if (model.Type == "SMS")
            {
                JObject dataresponse = new JObject();
                foreach (var res in _smsService.Send(to, message))
                {
                    dataresponse[res.Key] = res.Value;
                }
                return(_responseBuilder.Success(dataresponse));
            }
            else
            {
                if (_emailService.Send(to, _appSettingService.GetAppSettingData(CommonConst.CommonField.FROM_EMAIL_ID), model.CC.Split(';').ToList(), message, model.Subject))
                {
                    return(_responseBuilder.Success());
                }
                else
                {
                    return(_responseBuilder.ServerError());
                }
            }
        }
Exemple #2
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());
     }
 }
Exemple #3
0
        public JObject InstallRoute()
        {
            var routeObj   = _httpContextProxy.GetRequestBody <JObject>();
            var endpoint   = routeObj[CommonConst.CommonField.MODULE_ENDPOINT];
            var moduleName = routeObj[CommonConst.CommonField.MODULE_NAME];

            if (endpoint == null || moduleName == null)
            {
                _responseBuilder.BadRequest("module_name or module_endpoint missing");
            }
            routeObj.Remove(CommonConst.CommonField.MODULE_ENDPOINT);

            WriteToDB(routeObj, moduleName.ToString(), GATEWAY_ROUTE_COLLECTION, CommonConst.CommonField.KEY);

            var moduleEndPountData = new JObject()
            {
                [CommonConst.CommonField.DISPLAY_ID]      = CommonUtility.GetNewID(),
                [CommonConst.CommonField.MODULE_ENDPOINT] = endpoint,
                [CommonConst.CommonField.MODULE_NAME]     = moduleName,
                [CommonConst.CommonField.ÌS_OVERRIDE]     = false
            };

            WriteToDB(moduleEndPountData, moduleName.ToString(), GATEWAY_MODULE_ENDPOINT, CommonConst.CommonField.MODULE_NAME);

            return(_responseBuilder.Success());
        }
        public JObject InstallModule()
        {
            try
            {
                var request = _httpContextProxy.GetRequestBody <ModuleInstallRequest>();
                if (request == null)
                {
                    return(_responseBuilder.BadRequest());
                }
                if (request.InstallationKey != _moduleInstallationKey)
                {
                    _logger.Error("Installation key validation fail");
                    return(_responseBuilder.Unauthorized());
                }
                if (request.Name != "ZNxt.Net.Core.Module.Gateway")
                {
                    GetAppGatewayConfig().GetAwaiter().GetResult();
                }
                JObject moduleObject = new JObject();
                moduleObject[CommonConst.CommonField.NAME]    = request.Name;
                moduleObject[CommonConst.CommonField.VERSION] = request.Version;
                moduleObject[CommonConst.MODULE_INSTALL_COLLECTIONS_FOLDER] = "collections";// config[CommonConst.MODULE_INSTALL_COLLECTIONS_FOLDER];

                InstallWWWRoot(request);
                InstallCollections(request);
                InstallDlls(request);
                _routing.ReLoadRoutes();
                return(_responseBuilder.Success());
            }
            catch (Exception ex)
            {
                _logger.Error(ex.Message, ex);
                return(_responseBuilder.ServerError());
            }
        }
Exemple #5
0
        public JObject InstallPage()
        {
            try
            {
                var request = _httpContextProxy.GetRequestBody <JObject>();
                if (request == null)
                {
                    return(_responseBuilder.BadRequest());
                }
                var id         = request[CommonConst.CommonField.DISPLAY_ID].ToString();
                var moduleName = request[CommonConst.CommonField.MODULE_NAME].ToString();
                var path       = request[CommonConst.CommonField.FILE_PATH].ToString();

                var data = request[CommonConst.CommonField.DATA].ToString();

                string cleanupWWWRootFilter = "{ " + CommonConst.CommonField.MODULE_NAME + ":'" + moduleName + "', " + CommonConst.CommonField.FILE_PATH + ": '" + path + "'}";
                foreach (var item in _dbService.Get(CommonConst.Collection.STATIC_CONTECT, new RawQuery(cleanupWWWRootFilter)))
                {
                    _keyValueStorage.Delete(CommonConst.Collection.STATIC_CONTECT, item[CommonConst.CommonField.DISPLAY_ID].ToString());
                }

                _keyValueStorage.Put <string>(CommonConst.Collection.STATIC_CONTECT, id, data);
                request.Remove(CommonConst.CommonField.DATA);
                WriteToDB(request, moduleName, CommonConst.Collection.STATIC_CONTECT, CommonConst.CommonField.FILE_PATH);
                return(_responseBuilder.Success());
            }
            catch (Exception ex)
            {
                _logger.Error(ex.Message, ex);
                return(_responseBuilder.ServerError());
            }
        }
Exemple #6
0
 public JObject AcceptMobileAuthTnC()
 {
     try
     {
         var request = _httpContextProxy.GetRequestBody <MobileAuthAcceptTnCRequestModel>();
         request.device_address = _httpContextProxy.GetHeader("device_address");
         var results = new Dictionary <string, string>();
         if (request.IsValidModel(out results))
         {
             JObject tncResponse = new JObject()
             {
                 ["security_code"] = "dummy_security_code"
             };
             return(_responseBuilder.Success(null, tncResponse));
         }
         else
         {
             _logger.Debug("Model validation fail");
             JObject errors = new JObject();
             foreach (var error in results)
             {
                 errors[error.Key] = error.Value;
             }
             return(_responseBuilder.BadRequest(errors));
         }
     }
     catch (Exception ex)
     {
         _logger.Error(ex.Message, ex);
         return(_responseBuilder.ServerError());
     }
 }
Exemple #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());
            }
        }
Exemple #8
0
        public JObject Process()
        {
            try
            {
                var request = _httpContextProxy.GetRequestBody <JObject>();
                if (request != null && request["key"] != null)
                {
                    var data = _dbService.Get(_collection, new RawQuery("{'key':'" + request["key"].ToString() + "','override_by':'none'}"));
                    if (data.Count == 1 && data.First()["data"] != null)
                    {
                        var template = data.First()["data"].ToString();
                        var subject  = data.First()["subject"] != null?data.First()["subject"].ToString() : "";

                        request.Remove("key");
                        foreach (var item in request)
                        {
                            subject  = subject.Replace("{{" + item.Key.ToString() + "}}", item.Value.ToString());
                            template = template.Replace("{{" + item.Key.ToString() + "}}", item.Value.ToString());
                        }

                        JObject response = new JObject();
                        response["data"]    = template;
                        response["subject"] = subject;
                        var apiresponse = _responseBuilder.Success(response);
                        _logger.Debug("templete process response", apiresponse);
                        return(apiresponse);
                    }
                    else
                    {
                        _logger.Error($"key not found {request["key"]}");
                        return(_responseBuilder.NotFound());;
                    }
                }
                else
                {
                    _logger.Error("Bad request");
                    return(_responseBuilder.BadRequest());;
                }
            }
            catch (Exception ex)
            {
                _logger.Error(ex.Message, ex);
                return(_responseBuilder.ServerError());
            }
        }
        public JObject Install()
        {
            var data = _httpContextProxy.GetRequestBody <AppIntallModel>();

            if (data.Password.Length == 0 && data.Email.Length == 0)
            {
                return(_responseBuilder.BadRequest());
            }
            ApplicationConfig.AppInstallStatus = AppInstallStatus.Inprogress;
            var db = _serviceResolver.Resolve <IDBService>();
            var userAccontHelper = _serviceResolver.Resolve <UserAccontHelper>();

            if (db.IsConnected)
            {
                var appSetting   = _serviceResolver.Resolve <IAppSettingService>();
                var customConfig = userAccontHelper.CreateNewUserObject(data.Email, data.Email, data.Email, data.Password, UserIDType.Email);
                userAccontHelper.AddClaim(customConfig, CommonConst.CommonField.ROLE_CLAIM_TYPE, CommonConst.CommonField.SYS_ADMIN_ROLE);
                if (db.Write(CommonConst.Collection.USERS, customConfig))
                {
                    ApplicationConfig.AppInstallStatus = AppInstallStatus.Finish;
                    appSetting.SetAppSetting(CommonConst.CommonValue.APPINSTALLSTATUS, AppInstallStatus.Finish.ToString());
                    return(_responseBuilder.Success());
                }
                else
                {
                    ApplicationConfig.AppInstallStatus = AppInstallStatus.Init;
                    return(_responseBuilder.ServerError());
                }
            }
            else
            {
                ApplicationConfig.AppInstallStatus = AppInstallStatus.DBNotSet;
                return(_responseBuilder.ServerError(new JObject
                {
                    [CommonConst.CommonField.ERR_MESSAGE] = "DB Connection error"
                }));
            }
        }
Exemple #10
0
        public async Task <JObject> Login()
        {
            try
            {
                JObject response = null;
                var     data     = _httpContextProxy.GetRequestBody <UserLoginModel>();
                if (data == null)
                {
                    response = _responseBuilder.BadRequest();
                }
                var userAccontHelper = _serviceResolver.Resolve <UserAccontHelper>();
                var user             = userAccontHelper.GetUser(data.UserName);
                if (user == null)
                {
                    response = _responseBuilder.Unauthorized();
                }
                if (userAccontHelper.ValidateUser(user, data.Password))
                {
                    ClaimsIdentity  identity  = new ClaimsIdentity(this.GetUserClaims(user), CookieAuthenticationDefaults.AuthenticationScheme);
                    ClaimsPrincipal principal = new ClaimsPrincipal(identity);

                    await _serviceResolver.Resolve <IHttpContextAccessor>().HttpContext.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme, principal);

                    response = _responseBuilder.Success();
                }
                else
                {
                    response = _responseBuilder.Unauthorized();
                }
                return(await Task.FromResult <JObject>(response));
            }
            catch (Exception ex)
            {
                _logger.Error(ex.Message, ex);
                return(await Task.FromResult <JObject>(_responseBuilder.ServerError()));
            }
        }
        public JObject AdminAddUser()
        {
            try
            {
                var request = _httpContextProxy.GetRequestBody <AdminAddUserModel>();
                _logger.Debug("Validation model");
                var results = new Dictionary <string, string>();
                if (request.IsValidModel(out results))
                {
                    _logger.Debug("Getting user service");

                    _logger.Debug("Calling GetUserByEmail");

                    if (_ZNxtUserService.GetUserByUsername(request.user_name) == null)
                    {
                        var userModel = new UserModel()
                        {
                            email       = request.email,
                            user_id     = long.Parse($"{CommonUtility.GetUnixTimestamp(DateTime.UtcNow)}{CommonUtility.RandomNumber(4)}").ToString(),
                            user_name   = request.user_name,
                            first_name  = request.first_name,
                            middle_name = request.middle_name,
                            last_name   = request.last_name,
                            salt        = CommonUtility.GetNewID(),
                            is_enabled  = true,
                            user_type   = "user_pass",
                            //dob = request.dob,
                            id    = CommonUtility.GetNewID(),
                            roles = new List <string> {
                                "init_login_email_otp"
                            }
                        };
                        _logger.Debug("Calling CreateUser");
                        var response = _ZNxtUserService.CreateUser(userModel, false);
                        if (response)
                        {
                            JObject userInfo = new JObject();
                            userInfo["mobile_number"]          = request.mobile_number;
                            userInfo["whatsapp_mobile_number"] = request.whatsapp_mobile_number;
                            userInfo["gender"] = request.gender;
                            if (_ZNxtUserService.UpdateUserProfile(userModel.user_id, userInfo))
                            {
                                _userNotifierService.SendWelcomeEmailWithOTPLoginAsync(userModel).GetAwaiter().GetResult();
                                var resonseData = new JObject()
                                {
                                    [CommonConst.CommonField.USER_ID] = userModel.user_id
                                };
                                return(_responseBuilder.Success(resonseData));
                            }
                            else
                            {
                                _logger.Error($"Error while updating user profile {userModel.user_id}", null, userInfo);
                                return(_responseBuilder.ServerError());
                            }
                        }
                        else
                        {
                            return(_responseBuilder.ServerError());
                        }
                    }
                    else
                    {
                        JObject errors = new JObject();
                        errors["error"] = $"User id already registered : {request.user_name}";
                        return(_responseBuilder.BadRequest(errors));
                    }
                }
                else
                {
                    _logger.Debug("Model validation fail");
                    JObject errors = new JObject();
                    foreach (var error in results)
                    {
                        errors[error.Key] = error.Value;
                    }
                    return(_responseBuilder.BadRequest(errors));
                }
            }
            catch (Exception ex)
            {
                _logger.Error(ex.Message, ex);
                return(_responseBuilder.ServerError());
            }
        }
        public JObject UploadImage()
        {
            try
            {
                //_httpContextProxy.GetQueryString("galleryname");
                var files = _httpFileUploader.GetFiles();
                if (files.Any())
                {
                    _logger.Debug($"getting file {files.First() }");
                    var filePrefix = CommonUtility.RandomString(5).ToUpper();
                    var request    = new JObject();
                    request[CommonConst.CommonField.DISPLAY_ID] = request[CommonConst.CommonField.KEY] = CommonUtility.GetNewID();
                    request["images"]      = new JArray();
                    request["file_name"]   = files.First();
                    request["is_override"] = false;

                    var fileData = _httpFileUploader.GetFileData(files.First());
                    request["file_size"] = fileData.Length;

                    _logger.Debug($"getting thumbnails");
                    var rawImage    = new MemoryStream(fileData);
                    var smallImage  = new MemoryStream(Convert.FromBase64String(ImageUtility.GetCropedImage(fileData, 50, 50)));
                    var mediumImage = new MemoryStream(Convert.FromBase64String(ImageUtility.GetCropedImage(fileData, 120, 120)));
                    var largeImage  = new MemoryStream(Convert.FromBase64String(ImageUtility.GetCropedImage(fileData, 200, 200)));

                    _logger.Debug($"UploadingImageToS3 Raw");
                    var pathRaw = UploadImageToS3(rawImage, filePrefix);

                    (request["images"] as JArray).Add(new JObject()
                    {
                        ["image"]     = pathRaw,
                        ["type"]      = "raw",
                        ["meta_data"] = new JObject()
                        {
                            ["size"] = pathRaw.Length
                        }
                    });

                    _logger.Debug($"UploadingImageToS3 Small");
                    var pathsmall = UploadImageToS3(smallImage, filePrefix);
                    (request["images"] as JArray).Add(new JObject()
                    {
                        ["image"]     = pathsmall,
                        ["type"]      = "thumbnail_s",
                        ["meta_data"] = new JObject()
                        {
                            ["size"] = pathsmall.Length
                        }
                    });
                    _logger.Debug($"UploadingImageToS3 M");
                    var pathM = UploadImageToS3(mediumImage, filePrefix);
                    (request["images"] as JArray).Add(new JObject()
                    {
                        ["image"]     = pathM,
                        ["type"]      = "thumbnail_m",
                        ["meta_data"] = new JObject()
                        {
                            ["size"] = pathM.Length
                        }
                    });
                    _logger.Debug($"UploadingImageToS3 L");
                    var pathLarge = UploadImageToS3(largeImage, filePrefix);
                    (request["images"] as JArray).Add(new JObject()
                    {
                        ["image"]     = pathLarge,
                        ["type"]      = "thumbnail_l",
                        ["meta_data"] = new JObject()
                        {
                            ["size"] = pathLarge.Length
                        }
                    });
                    _logger.Debug($"add to db", request);
                    _dBService.Write("gallery", request);

                    return(_responseBuilder.Success(request));
                }
                else
                {
                    return(_responseBuilder.BadRequest());
                }
            }
            catch (Exception ex)
            {
                _logger.Error(ex.Message, ex);
                return(_responseBuilder.ServerError());
            }
        }