public WebDomain GetWebDomain(int id)
        {
            WebDomain            domain   = new WebDomain();
            int                  domainid = GetValueInt("domainid");
            IList <TextAndValue> tv       = new List <TextAndValue>();

            tv.Add(new TextAndValue("@domainid", domainid.ToString()));

            DataSet dsDomain = KinProxyData.GetDataSet(tv, dbname + ".dbo.GetWebDomain");

            domain = (from d in dsDomain.Tables[0].AsEnumerable()
                      select new WebDomain()
            {
                //id,url,descript,imgurl
                id = d.Field <int?>("id") ?? 0,
                url = d.Field <string>("url"),
                descript = d.Field <string>("descript"),
                imgurl = d.Field <string>("imgurl"),
                qq = d.Field <string>("qq"),
                third_party_url = d.Field <string>("third_party_url")
            }).FirstOrDefault();


            return(domain);
        }
        private Email GetEmail(Tenant tenant, WebDomain domain, Page page, FormElementSettings settings, EmailContent content)
        {
            // Get to recipients
            IEnumerable <EmailAddress> toAddresses = GetEmailAddresses(new string[] { "\r\n", "\n" }, settings.RecipientEmail);
            IEnumerable <EmailAddress> configurationToAddresses = _emailService.ListToEmailAddresses();

            if (configurationToAddresses != null)
            {
                toAddresses.Concat(configurationToAddresses);
            }

            // Get from (and reply to) email address
            string       host             = GetHost(domain.Url);
            EmailAddress fromEmailAddress = new EmailAddress
            {
                Email       = $"donotreply@{host}",
                DisplayName = tenant.Name
            };

            // Return email to send
            return(new Email
            {
                BccAddresses = _emailService.ListBccEmailAddresses(),
                Content = content,
                FromAddress = fromEmailAddress,
                ReplyToAddress = fromEmailAddress,
                ToAddresses = toAddresses,
            });
        }
        public async Task <FormElementActionResponse> PerformElementActionAsync(long tenantId, long elementId, FormElementActionRequest request, IPageContext context)
        {
            // Get form settings, domain and current page details
            FormElementSettings settings = await _elementRepository.ReadElementSettingsAsync(tenantId, elementId);

            Page page = await _pageService.ReadPageAsync(tenantId, context.PageId);

            WebDomain domain = await _domainService.ReadDomainByRedirectUrlAsync(tenantId, null);

            Tenant tenant = await _tenantService.ReadTenantAsync(tenantId);

            // Construct email
            IEnumerable <FormFieldLabelValue> labelValues = GetFormFieldLabelValues(settings, request);
            EmailContent content = GetEmailContent(page, labelValues);
            Email        email   = GetEmail(tenant, domain, page, settings, content);

            // Send finished email
            _emailService.Send(email);

            // Return response
            return(new FormElementActionResponse
            {
                Message = settings.SubmittedMessage
            });
        }
            public async Task OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next)
            {
                // Gets "root URL" of current request. For example, the URI "http://localhost:7823/pages/100" has root URI "http://localhost:7823".
                string rootUrl = string.Format("{0}://{1}", context.HttpContext.Request.Scheme, context.HttpContext.Request.Host);

                // Lookup the domain associated with the root URL
                WebDomain domain = await _domainService.ReadDomainByUrlAsync(rootUrl);

                // Throw error if no domain
                if (domain == null)
                {
                    throw new MultiTenantDomainException("Request executed on invalid domain");
                }

                // Throw error if request executed on wrong domain
                if (domain.RedirectUrl != null)
                {
                    ProcessInvalidDomain(context.HttpContext, rootUrl, domain.RedirectUrl);
                }

                // Put domain into http context items, where it can be accessed later by controllers
                context.RouteData.Values["tenantId"] = domain.TenantId;

                // Execute action
                await next();
            }
Beispiel #5
0
        public object Get(RolesGrantGetRequest request)
        {
            List <WebRoleGrant> result = new List <WebRoleGrant> ();
            var context = TepWebContext.GetWebContext(PagePrivileges.AdminOnly);

            try {
                context.Open();
                context.LogInfo(this, string.Format("/role/grant GET"));

                Domain            domain    = Domain.FromId(context, request.DomainId);
                var               webdomain = new WebDomain(domain);
                EntityList <Role> roles     = new EntityList <Role> (context);
                roles.Load();

                foreach (var role in roles)
                {
                    var webrole = new WebRole(role);
                    //get users
                    var usrs = role.GetUsers(domain.Id);
                    foreach (var usrid in usrs)
                    {
                        var webuser = new WebUser(User.FromId(context, usrid));
                        result.Add(new WebRoleGrant {
                            Domain = webdomain,
                            Role   = webrole,
                            User   = webuser
                        });
                    }
                    //get groups
                    var grps = role.GetGroups(domain.Id);
                    foreach (var grpid in grps)
                    {
                        var webgroup = new WebGroup(Group.FromId(context, grpid));
                        result.Add(new WebRoleGrant {
                            Domain = webdomain,
                            Role   = webrole,
                            Group  = webgroup
                        });
                    }
                }

                context.Close();
            } catch (Exception e) {
                context.LogError(this, e.Message, e);
                context.Close();
                throw e;
            }
            return(result);
        }
        public async Task <IActionResult> ReadDomainByUrlAsync([FromQuery] string url, [FromQuery] string redirectUrl)
        {
            WebDomain domain = null;

            if (url != null)
            {
                domain = await _domainService.ReadDomainByUrlAsync(url);
            }
            else if (redirectUrl != null)
            {
                domain = await _domainService.ReadDomainByRedirectUrlAsync(TenantId, redirectUrl);
            }
            if (domain == null)
            {
                return(NotFound());
            }
            return(Ok(domain));
        }
Beispiel #7
0
        /// <summary>
        /// Get the specified request.
        /// </summary>
        /// <param name="request">Request.</param>
        public object Get(DomainGetRequest request)
        {
            WebDomain result;

            var context = TepWebContext.GetWebContext(PagePrivileges.AdminOnly);

            try {
                context.Open();
                context.LogInfo(this, string.Format("/domain/{{Id}} GET Id='{0}'", request.Id));
                Domain domain = Domain.FromId(context, request.Id);
                result = new WebDomain(domain);

                context.Close();
            } catch (Exception e) {
                context.LogError(this, e.Message, e);
                context.Close();
                throw e;
            }
            return(result);
        }
Beispiel #8
0
        /// <summary>
        /// Put the specified request.
        /// </summary>
        /// <param name="request">Request.</param>
        public object Put(DomainUpdateRequest request)
        {
            var       context = TepWebContext.GetWebContext(PagePrivileges.AdminOnly);
            WebDomain result;

            try {
                context.Open();
                context.LogInfo(this, string.Format("/domain PUT Id='{0}'", request.Id));
                Domain domain = (request.Id == 0 ? null : Domain.FromId(context, request.Id));
                domain = request.ToEntity(context, domain);
                domain.Store();
                context.LogDebug(this, string.Format("Domain {0} updated by user {1}", domain.Identifier, User.FromId(context, context.UserId).Username));
                result = new WebDomain(domain);
                context.Close();
            } catch (Exception e) {
                context.LogError(this, e.Message, e);
                context.Close();
                throw e;
            }
            return(result);
        }
Beispiel #9
0
        /// <summary>
        /// Post the specified request.
        /// </summary>
        /// <param name="request">Request.</param>
        public object Post(CreateDomainOwnerRequest request)
        {
            var       context = TepWebContext.GetWebContext(PagePrivileges.AdminOnly);
            WebDomain result;

            try {
                context.Open();
                context.LogInfo(this, string.Format("/domain/{{id}}/owner POST Id='{0}', UserId='{1}'", request.Id, request.UserId));
                ThematicCommunity domain = ThematicCommunity.FromId(context, request.Id);
                UserTep           owner  = UserTep.FromId(context, request.UserId);
                domain.SetOwner(owner);

                result = new WebDomain(domain);

                context.Close();
            } catch (Exception e) {
                context.LogError(this, e.Message, e);
                context.Close();
                throw e;
            }
            return(result);
        }
Beispiel #10
0
        public object Post(UploadDomainImageRequest request)
        {
            var    context   = TepWebContext.GetWebContext(PagePrivileges.AdminOnly);
            string img       = "";
            string uid       = Guid.NewGuid().ToString();
            string extension = ".png";

            WebDomain result = null;

            try {
                context.Open();
                context.LogInfo(this, string.Format("/domain/{{Id}}/image POST Id='{0}'", request.Id));

                if (request.Id == 0)
                {
                    var segments = base.Request.PathInfo.Split(new [] { '/' },
                                                               StringSplitOptions.RemoveEmptyEntries);
                    request.Id = System.Int32.Parse(segments [1]);
                }

                Terradue.Portal.Domain domain = Terradue.Portal.Domain.FromId(context, request.Id);
                string oldImg = domain.IconUrl;
                if (this.RequestContext.Files.Length > 0)
                {
                    var uploadedFile = this.RequestContext.Files [0];
                    extension = uploadedFile.FileName.Substring(uploadedFile.FileName.LastIndexOf("."));
                    img       = "/files/" + uid + extension;

                    string path = AppDomain.CurrentDomain.BaseDirectory;
                    if (!path.EndsWith("/"))
                    {
                        path += "/";
                    }

                    context.LogInfo(this, string.Format("Uploading image to {0}", path + img));
                    uploadedFile.SaveTo(path + img);
                }
                else
                {
                    using (var fileStream = File.Create("files/" + uid + extension)) {
                        img = "files/" + uid + extension;
                        request.RequestStream.CopyTo(fileStream);
                    }
                }
                domain.IconUrl = img;
                domain.Store();

                result = new WebDomain(domain);

                try {
                    if (oldImg != null)
                    {
                        File.Delete("files/" + oldImg);
                    }
                } catch (Exception) { }

                context.Close();
            } catch (Exception e) {
                context.LogError(this, e.Message, e);
                context.Close();
                throw e;
            }
            return(result);
        }