Ejemplo n.º 1
0
 /// <summary>
 /// Encodes a text string
 /// </summary>
 /// <param name="name">the text to encode</param>
 /// <returns>a url safe string</returns>
 private static string UrlEncode(string name)
 {
     return(WebUtility.UrlEncode(name));
 }
Ejemplo n.º 2
0
        public override void LoadSubtitle(Subtitle subtitle, List <string> lines, string fileName)
        {
            _errorCount = 0;
            subtitle.Paragraphs.Clear();
            foreach (string line in lines)
            {
                if (line.Contains("[0] = ") && line.Contains("[1] = '") && line.Contains("[2] = '"))
                {
                    var p  = new Paragraph();
                    var sb = new StringBuilder();

                    int pos = line.IndexOf("[0] = ");
                    for (int i = pos + 6; i < line.Length && Utilities.IsInteger(line[i].ToString()); i++)
                    {
                        sb.Append(line.Substring(i, 1));
                    }
                    p.StartTime.TotalMilliseconds = int.Parse(sb.ToString());

                    pos = line.IndexOf("[1] = '");
                    sb  = new StringBuilder();
                    for (int i = pos + 7; i < line.Length && line[i] != '\''; i++)
                    {
                        sb.Append(line.Substring(i, 1));
                    }
                    if (sb.Length > 0)
                    {
                        sb.AppendLine();
                    }
                    pos = line.IndexOf("[2] = '");
                    for (int i = pos + 7; i < line.Length && line[i] != '\''; i++)
                    {
                        sb.Append(line.Substring(i, 1));
                    }
                    p.Text = sb.ToString().Trim();
                    p.Text = WebUtility.HtmlDecode(p.Text);
                    p.Text = ConvertJavaSpecialCharacters(p.Text);
                    subtitle.Paragraphs.Add(p);
                }
            }
            for (int i = 1; i < subtitle.Paragraphs.Count; i++)
            {
                Paragraph p    = subtitle.GetParagraphOrDefault(i - 1);
                Paragraph next = subtitle.GetParagraphOrDefault(i);
                if (p != null && next != null)
                {
                    p.EndTime.TotalMilliseconds = next.StartTime.TotalMilliseconds;
                }
                if (!string.IsNullOrEmpty(next.Text))
                {
                    p.EndTime.TotalMilliseconds--;
                }
            }
            for (int i = subtitle.Paragraphs.Count - 1; i >= 0; i--)
            {
                Paragraph p = subtitle.GetParagraphOrDefault(i);
                if (p != null && string.IsNullOrEmpty(p.Text))
                {
                    subtitle.Paragraphs.RemoveAt(i);
                }
            }
            subtitle.Renumber(1);
        }
Ejemplo n.º 3
0
        public IActionResult Page(string url, string collectionId)
        {
            if (string.IsNullOrWhiteSpace(url))
            {
                return(View("Index"));
            }

            if (!url.StartsWith("http://") && !url.StartsWith("https://"))
            {
                return(View("Index"));
            }

            var collectionName = collectionId ?? "www";

            try
            {
                _crawlQueue.Enqueue(new Uri(url));

                return(Redirect("/add/thankyou"));
            }
            catch (Exception ex)
            {
                // TODO: add logging framework
                System.IO.File.WriteAllText(string.Format("_{0}_{1}.log", DateTime.Now.ToBinary(), WebUtility.UrlEncode(url)), ex.ToString());

                return(View("Error"));
            }
        }
Ejemplo n.º 4
0
        internal bool Init(SteamClient steamClient, string webAPIUserNonce, string parentalPin)
        {
            if (steamClient == null || steamClient.SteamID == null || string.IsNullOrEmpty(webAPIUserNonce))
            {
                return(false);
            }

            ulong steamID = steamClient.SteamID;

            string sessionID = Convert.ToBase64String(Encoding.UTF8.GetBytes(steamID.ToString()));

            // Generate an AES session key
            byte[] sessionKey = CryptoHelper.GenerateRandomBlock(32);

            // RSA encrypt it with the public key for the universe we're on
            byte[] cryptedSessionKey;
            using (RSACrypto rsa = new RSACrypto(KeyDictionary.GetPublicKey(steamClient.ConnectedUniverse))) {
                cryptedSessionKey = rsa.Encrypt(sessionKey);
            }

            // Copy our login key
            byte[] loginKey = new byte[webAPIUserNonce.Length];
            Array.Copy(Encoding.ASCII.GetBytes(webAPIUserNonce), loginKey, webAPIUserNonce.Length);

            // AES encrypt the loginkey with our session key
            byte[] cryptedLoginKey = CryptoHelper.SymmetricEncrypt(loginKey, sessionKey);

            // Do the magic
            Logging.LogGenericInfo("Logging in to ISteamUserAuth...", Bot.BotName);

            KeyValue authResult;

            using (dynamic iSteamUserAuth = WebAPI.GetInterface("ISteamUserAuth")) {
                iSteamUserAuth.Timeout = Timeout;

                try {
                    authResult = iSteamUserAuth.AuthenticateUser(
                        steamid: steamID,
                        sessionkey: Encoding.ASCII.GetString(WebUtility.UrlEncodeToBytes(cryptedSessionKey, 0, cryptedSessionKey.Length)),
                        encrypted_loginkey: Encoding.ASCII.GetString(WebUtility.UrlEncodeToBytes(cryptedLoginKey, 0, cryptedLoginKey.Length)),
                        method: WebRequestMethods.Http.Post,
                        secure: !Program.GlobalConfig.ForceHttp
                        );
                } catch (Exception e) {
                    Logging.LogGenericException(e, Bot.BotName);
                    return(false);
                }
            }

            if (authResult == null)
            {
                return(false);
            }

            Logging.LogGenericInfo("Success!", Bot.BotName);

            string steamLogin       = authResult["token"].AsString();
            string steamLoginSecure = authResult["tokensecure"].AsString();

            Cookie["sessionid"]        = sessionID;
            Cookie["steamLogin"]       = steamLogin;
            Cookie["steamLoginSecure"] = steamLoginSecure;

            // The below is used for display purposes only
            Cookie["webTradeEligibility"] = "{\"allowed\":0,\"reason\":0,\"allowed_at_time\":0,\"steamguard_required_days\":0,\"sales_this_year\":0,\"max_sales_per_year\":0,\"forms_requested\":0}";

            if (!UnlockParentalAccount(parentalPin).Result)
            {
                return(false);
            }

            LastSessionRefreshCheck = DateTime.Now;
            return(true);
        }
        public async Task <AnimeGeneralDetailsData> GetAnimeDetails(bool force, string id, string title, bool animeMode,
                                                                    ApiType?apiOverride = null)
        {
            var output = force ? null : await DataCache.RetrieveAnimeSearchResultsData(id, animeMode);

            if (output != null)
            {
                return(output);
            }

            var requestedApiType = apiOverride ?? CurrentApiType;

            try
            {
                switch (requestedApiType)
                {
                case ApiType.Mal:
                    string data = null;
                    if (!string.IsNullOrEmpty(title))
                    {
                        data = animeMode
                            ? await new AnimeSearchQuery(Utils.Utilities.CleanAnimeTitle(title), requestedApiType)
                               .GetRequestResponse(false)
                            : await new MangaSearchQuery(Utils.Utilities.CleanAnimeTitle(title)).GetRequestResponse(false);
                    }

                    if (string.IsNullOrEmpty(data) || !data.Contains(id))
                    {
                        //we are loading title from website because request came from mal url
                        var correctTitle = await AnimeTitleQuery.GetTitle(int.Parse(id), animeMode);

                        data = animeMode
                            ? await new AnimeSearchQuery(Utils.Utilities.CleanAnimeTitle(correctTitle), requestedApiType)
                               .GetRequestResponse(false)
                            : await new MangaSearchQuery(Utils.Utilities.CleanAnimeTitle(correctTitle)).GetRequestResponse(false);
                    }

                    data = WebUtility.HtmlDecode(data);

                    data = data.Replace("&", "");     //unparsable stuff ahaead :(
                    var parsedData = XDocument.Parse(data);

                    var elements = parsedData.Element(animeMode ? "anime" : "manga").Elements("entry");
                    var xmlObj   = elements.First(element => element.Element("id").Value == id);

                    output = new AnimeGeneralDetailsData();
                    output.ParseXElement(xmlObj, animeMode, Settings.PreferEnglishTitles);

                    DataCache.SaveAnimeSearchResultsData(id, output, animeMode);
                    break;

                case ApiType.Hummingbird:
                    Request =
                        WebRequest.Create(
                            Uri.EscapeUriString($"https://hummingbird.me/api/v1/anime/{id}"));
                    Request.ContentType = "application/x-www-form-urlencoded";
                    Request.Method      = "GET";

                    var raw = await GetRequestResponse();

                    if (string.IsNullOrEmpty(raw))
                    {
                        break;
                    }

                    dynamic jsonObj = JsonConvert.DeserializeObject(raw);
                    var     allEps  = 0;
                    if (jsonObj.episode_count != null)
                    {
                        allEps = Convert.ToInt32(jsonObj.episode_count.ToString());
                    }
                    output = new AnimeGeneralDetailsData
                    {
                        Title       = jsonObj.title.ToString(),
                        ImgUrl      = jsonObj.cover_image.ToString(),
                        Type        = jsonObj.show_type.ToString(),
                        Id          = Convert.ToInt32(jsonObj.id.ToString()),
                        MalId       = Convert.ToInt32(jsonObj.mal_id.ToString()),
                        AllEpisodes = allEps,
                        StartDate   = jsonObj.started_airing.ToString(),
                        EndDate     = jsonObj.finished_airing.ToString(),
                        Status      = jsonObj.status,
                        Synopsis    = jsonObj.synopsis,
                        GlobalScore = jsonObj.community_rating,
                        Synonyms    = new List <string> {
                            jsonObj.alternate_title.ToString()
                        }
                    };
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }
            }
            catch (Exception e)
            {
                // todo android notification nav bug
                // probably MAl garbled response
            }

            return(output);
        }
Ejemplo n.º 6
0
 public static string UrlEncode(this string url)
 {
     return(WebUtility.UrlEncode(url));
 }
Ejemplo n.º 7
0
        public async Task Define([Remainder] string word)
        {
            if (!await ValidateQuery(Context.Channel, word).ConfigureAwait(false))
            {
                return;
            }

            using (var http = _httpFactory.CreateClient())
            {
                var res = await http.GetStringAsync("http://api.pearson.com/v2/dictionaries/entries?headword=" + WebUtility.UrlEncode(word.Trim())).ConfigureAwait(false);

                var data = JsonConvert.DeserializeObject <DefineModel>(res);

                var sense = data.Results.FirstOrDefault(x => x.Senses?[0].Definition != null)?.Senses[0];

                if (sense?.Definition == null)
                {
                    await ReplyErrorLocalizedAsync("define_unknown").ConfigureAwait(false);

                    return;
                }

                var definition = sense.Definition.ToString();
                if (!(sense.Definition is string))
                {
                    definition = ((JArray)JToken.Parse(sense.Definition.ToString())).First.ToString();
                }

                var embed = new EmbedBuilder().WithOkColor()
                            .WithTitle(GetText("define") + " " + word)
                            .WithDescription(definition)
                            .WithFooter(efb => efb.WithText(sense.Gramatical_info?.Type));

                if (sense.Examples != null)
                {
                    embed.AddField(efb => efb.WithName(GetText("example")).WithValue(sense.Examples.First().Text));
                }

                await Context.Channel.EmbedAsync(embed).ConfigureAwait(false);
            }
        }
Ejemplo n.º 8
0
        public string DownloadString(Uri address)
        {
            try
            {
                //UserAgent must be the same throughout all requests
                BaseWebClient.Headers.Add(HttpRequestHeader.UserAgent, UserAgent);

                return(BaseWebClient.DownloadString(address));
            }
            catch (WebException ex)
            {
                if (ex.Status != WebExceptionStatus.ProtocolError)
                {
                    throw;
                }

                HttpWebResponse httpResponse = (HttpWebResponse)ex.Response;

                if (httpResponse.StatusCode != HttpStatusCode.ServiceUnavailable)
                {
                    throw;
                }

                using (StreamReader stream = new StreamReader(ex.Response.GetResponseStream()))
                {
                    string response = stream.ReadToEnd();

                    List <CFValues> inputs = RegexScraper.ScrapeFromString <CFValues>(response, @"name=""(?<Name>.*?)"" value=""(?<Value>.*?)""");
                    List <string>   script = RegexScraper.ScrapeFromString <string>(response, @"<script.*?>(?<val>.*?)</script>", options: RegexOptions.Singleline);

                    //Shouldn't be needed, but causes no harm
                    List <string> action = RegexScraper.ScrapeFromString <string>(response, @"action=""(?<val>.*?)""");

                    if (inputs.Count == 0 || script.Count == 0 || action.Count == 0)
                    {
                        //Site's different or page changed
                        throw;
                    }

                    BaseWebClient.Headers.Add(HttpRequestHeader.Referer, address.ToString());
                    BaseWebClient.Headers.Add(HttpRequestHeader.UserAgent, UserAgent);

                    string baseAddress           = address.GetLeftPart(UriPartial.Authority);
                    string solveChallengeAddress = baseAddress + action[0];

                    CFChallenge challenge = new CFChallenge(script[0], address);

                    BaseWebClient.QueryString.Add("jschl_answer", challenge.SolveChallenge().ToString());

                    foreach (CFValues value in inputs)
                    {
                        BaseWebClient.QueryString.Add(value.Name, WebUtility.UrlEncode(value.Value));
                    }

                    Thread.Sleep(3000);

                    string siteResponse = BaseWebClient.DownloadString(solveChallengeAddress);

                    BaseWebClient.QueryString.Clear();

                    return(siteResponse);
                }
            }
        }
Ejemplo n.º 9
0
        public async Task <BotMessage> GetResponse(ResponseContext context)
        {
            Match  match      = Regex.Match(context.Message.Text, WIKI_MULTIWORD_REGEX);
            string searchTerm = string.Empty;

            if (match.Success)
            {
                searchTerm = match.Groups["term"].Value;
            }
            else
            {
                match      = Regex.Match(context.Message.Text, WIKI_SINGLEWORD_REGEX);
                searchTerm = match.Groups["term"].Value;
            }
            string  requestUrl   = string.Format("http://en.wikipedia.org/w/api.php?action=query&list=search&format=json&prop=extracts&exintro=&explaintext=&srsearch={0}&utf8=&continue=", WebUtility.UrlEncode(searchTerm.Trim()));
            string  response     = await new HttpClient().GetStringAsync(requestUrl);
            JObject responseData = JObject.Parse(response);

            if (responseData["query"] != null && responseData["query"]["searchinfo"] != null)
            {
                int totalHits = responseData["query"]["searchinfo"]["totalhits"].Value <int>();

                if (totalHits > 0)
                {
                    string  articleTitle      = responseData["query"]["search"][0]["title"].Value <string>();
                    string  articleRequestUrl = "https://en.wikipedia.org/w/api.php?format=json&action=query&prop=extracts&exintro=&explaintext=&titles=" + WebUtility.UrlEncode(articleTitle);
                    string  articleResponse   = await new HttpClient().GetStringAsync(articleRequestUrl);
                    JObject articleData       = JObject.Parse(articleResponse);

                    if (articleData["query"]["pages"]["-1"] == null)
                    {
                        string summary = articleData["query"]["pages"].First.First["extract"].Value <string>();
                        if (summary.IndexOf('\n') > 0)
                        {
                            summary = summary.Substring(0, summary.IndexOf('\n'));
                        }

                        return(new BotMessage()
                        {
                            Text = "Awwww yeah. I know all about that. Check it, y'all!: " + string.Format("http://en.wikipedia.org/wiki/{0}", articleTitle.Replace(" ", "_")) + " \n> " + summary
                        });
                    }
                }
            }

            return(new BotMessage()
            {
                Text = "I never heard of that, which isn't all that surprisin'. What IS surprisin' is that neither has Wikipedia. Have you been hangin' out behind the barn again with SkeeterBot?"
            });
        }
Ejemplo n.º 10
0
        public async Task Google([Remainder] string query = null)
        {
            var oterms = query?.Trim();

            if (!await ValidateQuery(Context.Channel, query).ConfigureAwait(false))
            {
                return;
            }

            query = WebUtility.UrlEncode(oterms).Replace(' ', '+');

            var fullQueryLink = $"https://www.google.ca/search?q={ query }&safe=on&lr=lang_eng&hl=en&ie=utf-8&oe=utf-8";

            using (var msg = new HttpRequestMessage(HttpMethod.Get, fullQueryLink))
            {
                msg.Headers.AddFakeHeaders();
                var config = Configuration.Default.WithDefaultLoader();
                var parser = new HtmlParser(config);
                var test   = "";
                using (var http = _httpFactory.CreateClient())
                    using (var response = await http.SendAsync(msg).ConfigureAwait(false))
                        using (var document = await parser.ParseAsync(test = await response.Content.ReadAsStringAsync().ConfigureAwait(false)).ConfigureAwait(false))
                        {
                            var elems        = document.QuerySelectorAll("div.g");
                            var resultsElem  = document.QuerySelectorAll("#resultStats").FirstOrDefault();
                            var totalResults = resultsElem?.TextContent;
                            //var time = resultsElem.Children.FirstOrDefault()?.TextContent
                            //^ this doesn't work for some reason, <nobr> is completely missing in parsed collection
                            if (!elems.Any())
                            {
                                return;
                            }

                            var results = elems.Select <IElement, GoogleSearchResult?>(elem =>
                            {
                                var aTag = elem.QuerySelector("a") as IHtmlAnchorElement; // <h3> -> <a>
                                var href = aTag?.Href;
                                var name = aTag?.Children.FirstOrDefault()?.TextContent;
                                if (href == null || name == null)
                                {
                                    return(null);
                                }

                                var txt = elem.QuerySelectorAll(".st").FirstOrDefault()?.TextContent;

                                if (txt == null)
                                {
                                    return(null);
                                }

                                return(new GoogleSearchResult(name, href, txt));
                            }).Where(x => x != null).Take(5);

                            var embed = new EmbedBuilder()
                                        .WithOkColor()
                                        .WithAuthor(eab => eab.WithName(GetText("search_for") + " " + oterms.TrimTo(50))
                                                    .WithUrl(fullQueryLink)
                                                    .WithIconUrl("http://i.imgur.com/G46fm8J.png"))
                                        .WithTitle(Context.User.ToString())
                                        .WithFooter(efb => efb.WithText(totalResults));

                            var desc = await Task.WhenAll(results.Select(async res =>
                                                                         $"[{Format.Bold(res?.Title)}]({(await _google.ShortenUrl(res?.Link).ConfigureAwait(false))})\n{res?.Text?.TrimTo(400 - res.Value.Title.Length - res.Value.Link.Length)}\n\n"))
                                       .ConfigureAwait(false);

                            var descStr = string.Concat(desc);
                            await Context.Channel.EmbedAsync(embed.WithDescription(descStr)).ConfigureAwait(false);
                        }
            }
        }
Ejemplo n.º 11
0
 protected virtual string InstanceUrl(string id, string baseUrl = null)
 {
     return($"{this.ClassUrl(baseUrl)}/{WebUtility.UrlEncode(id)}");
 }
Ejemplo n.º 12
0
 public static string UriEncode(this string input)
 {
     return(WebUtility.UrlEncode(input));
 }
Ejemplo n.º 13
0
        protected override void ExecuteCmdlet()
        {
            if (MyInvocation.InvocationName.ToLower().Equals("get-pnpaaduser"))
            {
                WriteWarning("Get-PnPAADUser is obsolete. Use Get-PnPAzureADUser instead which has the same parameters.");
            }

            if (PnPConnection.Current.ClientId == PnPConnection.PnPManagementShellClientId)
            {
                PnPConnection.Current.Scopes = new[] { "Directory.ReadWrite.All" };
            }
            if (ParameterSpecified(nameof(Identity)))
            {
                PnP.PowerShell.Commands.Model.AzureAD.User user;
                if (Guid.TryParse(Identity, out Guid identityGuid))
                {
                    user = PnP.PowerShell.Commands.Utilities.AzureAdUtility.GetUser(AccessToken, identityGuid);
                }
                else
                {
                    user = PnP.PowerShell.Commands.Utilities.AzureAdUtility.GetUser(AccessToken, WebUtility.UrlEncode(Identity), Select);
                }
                WriteObject(user);
            }
            else if (ParameterSpecified(nameof(Delta)))
            {
                var userDelta = PnP.PowerShell.Commands.Utilities.AzureAdUtility.ListUserDelta(AccessToken, DeltaToken, Filter, OrderBy, Select, StartIndex, EndIndex);
                WriteObject(userDelta);
            }
            else
            {
                var users = PnP.PowerShell.Commands.Utilities.AzureAdUtility.ListUsers(AccessToken, Filter, OrderBy, Select, StartIndex, EndIndex);
                WriteObject(users, true);
            }
        }
Ejemplo n.º 14
0
        public override void Process(TagHelperContext context, TagHelperOutput output)
        {
            if (Source.IsNullOrWhiteSpace())
            {
                Source = Url.Action(DefaultSourceAction);
            }
            if (GridClass.IsNullOrWhiteSpace())
            {
                GridClass = DefaultClass;
            }
            if (ModelType == null)
            {
                ModelType = ViewContext.ViewData.ModelMetadata.ModelType;
                if (OrderAsc.IsNullOrEmpty() && OrderDesc.IsNullOrEmpty() && typeof(EditorEntity).IsAssignableFrom(ModelType))
                {
                    OrderDesc = "LastUpdateDate";
                }
            }
            var           viewConfig         = ServiceLocator.GetViewConfigure(ModelType);
            var           localize           = ServiceLocator.GetService <ILocalize>();
            StringBuilder tableHeaderBuilder = new StringBuilder();
            StringBuilder tableSearchBuilder = new StringBuilder();

            if (viewConfig != null)
            {
                var primaryKey = viewConfig.MetaData.Properties.Select(m => m.Value).FirstOrDefault(m => m.CustomAttributes.Any(attr => attr.AttributeType == typeof(KeyAttribute)));

                if ((EditAble ?? true) && primaryKey != null)
                {
                    string name = primaryKey.Name.FirstCharToLowerCase();
                    if (name.Length == 2)
                    {
                        name = name.ToLower();
                    }

                    if (Edit.IsNullOrWhiteSpace())
                    {
                        Edit = Url.Action(DefaultEditAction) + "/{" + name + "}";
                    }
                    if (Delete.IsNullOrWhiteSpace())
                    {
                        Delete = Url.Action(DefaultDeleteAction) + "/{" + name + "}";
                    }
                    string manager = (EditTemplate ?? EditLinkTemplate).FormatWith(Edit);
                    if (DeleteAble ?? true)
                    {
                        manager += " " + (DeleteTemplate ?? DeleteLinkTemplate).FormatWith(Delete);
                    }
                    tableHeaderBuilder.AppendFormat(TableHeadStructure,
                                                    string.Empty,
                                                    WebUtility.HtmlEncode(manager),
                                                    string.Empty,
                                                    ActionLable ?? localize.Get("Action"),
                                                    string.Empty,
                                                    Query.Operators.None,
                                                    string.Empty,
                                                    string.Empty);
                    tableSearchBuilder.Append(TableSearchStructure);
                }

                var columns = viewConfig.GetViewPortDescriptors(true)
                              .Where(m => m.IsShowInGrid)
                              .Each(m =>
                {
                    var dropDown = m as DropDownListDescriptor;
                    StringBuilder optionBuilder = new StringBuilder();
                    if (dropDown != null)
                    {
                        if (dropDown.OptionItems != null && dropDown.OptionItems.Any())
                        {
                            foreach (var item in dropDown.OptionItems)
                            {
                                optionBuilder.AppendFormat("{{\"name\":\"{0}\",\"value\":\"{1}\"}},", item.Value, item.Key);
                            }
                        }
                        else if (dropDown.SourceType == Constant.SourceType.ViewData)
                        {
                            var selectList = ViewContext.ViewData[dropDown.SourceKey] as SelectList;
                            if (selectList != null)
                            {
                                foreach (var item in selectList)
                                {
                                    optionBuilder.AppendFormat("{{\"name\":\"{0}\",\"value\":\"{1}\"}},", item.Text, item.Value);
                                }
                            }
                        }
                    }
                    else if (m.DataType == typeof(bool) || m.DataType == typeof(bool?))
                    {
                        optionBuilder.AppendFormat("{{\"name\":\"{0}\",\"value\":\"{1}\"}},", localize.Get("Yes"), "true");
                        optionBuilder.AppendFormat("{{\"name\":\"{0}\",\"value\":\"{1}\"}},", localize.Get("No"), "false");
                    }
                    tableHeaderBuilder.AppendFormat(TableHeadStructure,
                                                    m.Name.FirstCharToLowerCase(),
                                                    WebUtility.HtmlEncode(m.GridColumnTemplate),
                                                    OrderAsc == m.Name ? "asc" : OrderDesc == m.Name ? "desc" : "",
                                                    m.DisplayName,
                                                    optionBuilder.Length == 0 ? string.Empty : WebUtility.HtmlEncode($"[{optionBuilder.ToString().Trim(',')}]"),
                                                    m.SearchOperator,
                                                    m.DataType.Name,
                                                    (m as TextBoxDescriptor)?.JavaScriptDateFormat);
                    tableSearchBuilder.Append(TableSearchStructure);
                });
            }
            output.TagName = "div";
            //output.Attributes.Add("class", "container-fluid");
            output.Content.SetHtmlContent(TableStructure.FormatWith(GridClass, Source, tableHeaderBuilder, tableSearchBuilder));
        }
Ejemplo n.º 15
0
        private static void InsertTweets()
        {
            //"value.id_str,value.utc_year,value.utc_month,value.utc_day,value.utc_hours,value.utc_minutes,value.text,value.match_key_1,value.match_key_2,value.match_key_3,value.match_key_4,value.match_key_5,value.match_key_6"
            var fileName     = @"C:\data\tweets.csv";
            var createdCount = 0;
            var _truncateLiveTableCommandText = @"TRUNCATE TABLE full_tweets";
            var _batchSize = 100000;

            using (var textFieldParser = new TextFieldParser(fileName))
            {
                textFieldParser.TextFieldType             = FieldType.Delimited;
                textFieldParser.Delimiters                = new[] { "," };
                textFieldParser.HasFieldsEnclosedInQuotes = true;

                var dataTable = new DataTable("full_tweets");

                dataTable.Columns.Add("id_str");
                dataTable.Columns.Add("year");
                dataTable.Columns.Add("month");
                dataTable.Columns.Add("day");
                dataTable.Columns.Add("hour");
                dataTable.Columns.Add("minute");
                dataTable.Columns.Add("text");
                dataTable.Columns.Add("key1");
                dataTable.Columns.Add("key2");
                dataTable.Columns.Add("key3");
                dataTable.Columns.Add("key4");
                dataTable.Columns.Add("key5");
                dataTable.Columns.Add("key6");
                using (var sqlConnection = new SqlConnection("data source=BUFFALO-PC;initial catalog=birddog;integrated security=True;"))
                {
                    sqlConnection.Open();

                    // Truncate the live table
                    using (var sqlCommand = new SqlCommand(_truncateLiveTableCommandText, sqlConnection))
                    {
                        sqlCommand.ExecuteNonQuery();
                    }

                    // Create the bulk copy object
                    var sqlBulkCopy = new SqlBulkCopy(sqlConnection)
                    {
                        DestinationTableName = "full_tweets"
                    };

                    // Setup the column mappings, anything ommitted is skipped
                    sqlBulkCopy.ColumnMappings.Add("id_str", "id_str");
                    sqlBulkCopy.ColumnMappings.Add("year", "year");
                    sqlBulkCopy.ColumnMappings.Add("month", "month");
                    sqlBulkCopy.ColumnMappings.Add("day", "day");
                    sqlBulkCopy.ColumnMappings.Add("hour", "hour");
                    sqlBulkCopy.ColumnMappings.Add("minute", "minute");
                    sqlBulkCopy.ColumnMappings.Add("text", "text");
                    sqlBulkCopy.ColumnMappings.Add("key1", "key1");
                    sqlBulkCopy.ColumnMappings.Add("key2", "key2");
                    sqlBulkCopy.ColumnMappings.Add("key3", "key3");
                    sqlBulkCopy.ColumnMappings.Add("key4", "key4");
                    sqlBulkCopy.ColumnMappings.Add("key5", "key5");
                    sqlBulkCopy.ColumnMappings.Add("key6", "key6");

                    // Loop through the CSV and load each set of 100,000 records into a DataTable
                    // Then send it to the LiveTable
                    textFieldParser.ReadFields(); //skip first line
                    var strings = new List <string>();
                    while (!textFieldParser.EndOfData)
                    {
                        var fields = textFieldParser.ReadFields();
                        dataTable.Rows.Add(fields[0], (int)double.Parse(fields[1]), (int)double.Parse(fields[2]), (int)double.Parse(fields[3]), (int)double.Parse(fields[4]),
                                           (int)double.Parse(fields[5]), WebUtility.HtmlDecode(fields[6]), fields[7], fields[8], fields[9], fields[10], fields[11], fields[12]);
                        //strings.Add(WebUtility.HtmlDecode(fields[6]));
                        createdCount++;

                        //var maxLength = strings.Where(x => x.Length > 140);
                        if (createdCount % _batchSize == 0)
                        {
                            InsertDataTable(sqlBulkCopy, sqlConnection, dataTable);
                        }
                    }

                    // Don't forget to send the last batch under 100,000
                    InsertDataTable(sqlBulkCopy, sqlConnection, dataTable);

                    sqlConnection.Close();
                }
            }
        }
Ejemplo n.º 16
0
 /// <summary>
 /// 更换群主
 /// </summary>
 /// <returns></returns>
 public static string _ChangeTopicOwner(this SiteUrls siteUrls, string spaceKey, string returnUrl)
 {
     return(CachedUrlHelper.Action("_ChangeTopicOwner", "TopicSpaceSettings", TopicAreaName, new RouteValueDictionary {
         { "spaceKey", spaceKey }, { "returnUrl", WebUtility.UrlEncode(returnUrl) }
     }));
 }
Ejemplo n.º 17
0
 /// <summary>
 /// 获取附件下载的URL
 /// </summary>
 /// <param name="attachmentId">附件Id</param>
 /// <param name="enableCaching">是否缓存</param>
 public static string ContentAttachmentUrl(this SiteUrls siteUrls, long attachmentId, bool enableCaching = true)
 {
     return(WebUtility.ResolveUrl(string.Format("~/Handlers/ContentAttachmentAuthorize.ashx?attachmentId={0}&enableCaching={1}", attachmentId, enableCaching)));
 }
Ejemplo n.º 18
0
        public async Task <IActionResult> FileUpload(List <IFormFile> files)
        {
            try
            {
                if (files.Count != 1)
                {
                    return(BadRequest(new { message = "Must Submit One File" }));
                }

                long     size                = files.Sum(f => f.Length);
                var      new_name            = "";
                var      filePaths           = new List <string>();
                string[] permittedExtensions = { ".pdf" };


                foreach (var formFile in files)
                {
                    if (formFile.Length >= 1000000)
                    {
                        return(BadRequest(new { message = "File too large. Expect less than 10M" }));
                    }

                    if (formFile.Length <= 0)
                    {
                        return(BadRequest(new { message = "File empty." }));
                    }

                    var ext = Path.GetExtension(WebUtility.HtmlEncode(formFile.FileName)).ToLowerInvariant();

                    if (string.IsNullOrEmpty(ext) || !permittedExtensions.Contains(ext))
                    {
                        return(BadRequest(new { message = "File need to be .pdf ." }));
                    }

                    Dictionary <string, List <byte[]> > _fileSignature = new Dictionary <string, List <byte[]> >
                    {
                        { ".pdf", new List <byte[]>
                          {
                              new byte[] { 0x25, 0x50, 0x44, 0x46 },
                          } },
                    };

                    using (var reader = new BinaryReader(formFile.OpenReadStream()))
                    {
                        var signatures  = _fileSignature[ext];
                        var headerBytes = reader.ReadBytes(signatures.Max(m => m.Length));

                        if (!signatures.Any(signature =>
                                            headerBytes.Take(signature.Length).SequenceEqual(signature)))
                        {
                            return(BadRequest(new { message = "File need to be a pdf file not a disguise as pdf file." }));
                        }
                    }

                    new_name = string.Format("{0}.{1}", WebUtility.HtmlEncode(formFile.FileName).Replace(".", string.Empty), ext);
                    var filePath = Path.Combine(_configuration["StoreFilePath"], new_name);

                    using (var stream = new FileStream(filePath, FileMode.Create))
                    {
                        await formFile.CopyToAsync(stream);
                    }
                }

                return(Ok(new { message = new_name, count = files.Count, size, filePaths }));
            }
            catch (Exception e)
            {
                return(BadRequest(new { message = "Failed to upload file: " + e.Message }));
            }
        }
Ejemplo n.º 19
0
 /// <summary>
 /// 附件下载的临时地址,根据设定的时间自动过期
 /// </summary>
 /// <param name="attachmentId">附件id</param>
 /// <param name="token">加密串</param>
 /// <param name="enableCaching">是否缓存</param>
 /// <returns></returns>
 public static string ContentAttachmentTempUrl(this SiteUrls siteUrls, long attachmentId, string token, bool enableCaching = true)
 {
     return(WebUtility.ResolveUrl(string.Format("~/Handlers/ContentAttachment.ashx?attachmentId={0}&token={1}&enableCaching={2}", attachmentId, token, enableCaching)));
 }
Ejemplo n.º 20
0
 private static string DecodedUrl(string inputUrl)
 {
     return(WebUtility.UrlDecode(inputUrl));
 }
Ejemplo n.º 21
0
        /// <summary>
        /// Configures XML of web parts.
        /// </summary>
        /// <param name="requestObject">Request Object</param>
        /// <param name="client">Client object containing Client data</param>
        /// <param name="matter">Matter object containing Matter data</param>
        /// <param name="clientContext">SharePoint Client Context</param>
        /// <param name="sitePageLib">SharePoint List of matter library</param>
        /// <param name="objFileInfo">Object of FileCreationInformation</param>
        /// <param name="uri">To get URL segments</param>
        /// <param name="web">Web object of the current context</param>
        /// <returns>List of Web Parts</returns>
        public string[] ConfigureXMLCodeOfWebParts(Client client, Matter matter, ClientContext clientContext, string pageName, Uri uri,
                                                   Web web, MatterConfigurations matterConfigurations)
        {
            //injecting matterextraproperties as string while creating matter landing page.
            string matterExtraPropertiesValues = string.Empty;

            if (matterConfigurations != null && matterConfigurations.AdditionalFieldValues != null)
            {
                matterExtraPropertiesValues = DisplayAllExtraMatterProperties(matterConfigurations.AdditionalFieldValues);
            }
            string[] result = null;
            try
            {
                List sitePageLib = web.Lists.GetByTitle(matter.Name);
                clientContext.Load(sitePageLib);
                clientContext.ExecuteQuery();

                ////Configure list View Web Part XML
                string listViewWebPart = ConfigureListViewWebPart(sitePageLib, clientContext, pageName, client, matter,
                                                                  string.Format(CultureInfo.InvariantCulture, "{0}{1}{2}{3}{4}", uri.AbsolutePath, ServiceConstants.FORWARD_SLASH, matter.Name,
                                                                                ServiceConstants.FORWARD_SLASH, pageName));
                string[] contentEditorSectionIds = matterSettings.MatterLandingPageSections.Split(Convert.ToChar(ServiceConstants.COMMA, CultureInfo.InvariantCulture));

                ////Configure content Editor Web Part of user information XML
                string contentEditorWebPartTasks = string.Empty;
                if (matterConfigurations.IsTaskSelected)
                {
                    contentEditorWebPartTasks = string.Format(CultureInfo.InvariantCulture, ServiceConstants.CONTENT_EDITOR_WEB_PART,
                                                              string.Format(CultureInfo.InvariantCulture, ServiceConstants.MATTER_LANDING_SECTION_CONTENT,
                                                                            contentEditorSectionIds[Convert.ToInt32(MatterLandingSection.TaskPanel, CultureInfo.InvariantCulture)]));
                }

                string calendarWebpart = string.Empty, rssFeedWebPart = string.Empty, rssTitleWebPart = string.Empty;
                if (matterConfigurations.IsRSSSelected)
                {
                    rssFeedWebPart  = string.Format(CultureInfo.InvariantCulture, ServiceConstants.RSS_FEED_WEB_PART, WebUtility.UrlEncode(matter.Name));
                    rssTitleWebPart = string.Format(CultureInfo.InvariantCulture, ServiceConstants.CONTENT_EDITOR_WEB_PART,
                                                    string.Format(CultureInfo.InvariantCulture, ServiceConstants.MATTER_LANDING_SECTION_CONTENT,
                                                                  contentEditorSectionIds[Convert.ToInt32(MatterLandingSection.RSSTitlePanel, CultureInfo.InvariantCulture)]));
                }

                ////Configure calendar Web Part XML
                if (matterConfigurations.IsCalendarSelected)
                {
                    ////If create calendar is enabled configure calendar Web Part XML; else dont configure
                    calendarWebpart = string.Format(CultureInfo.InvariantCulture, ServiceConstants.CONTENT_EDITOR_WEB_PART, string.Format(CultureInfo.InvariantCulture, ServiceConstants.MATTER_LANDING_SECTION_CONTENT, contentEditorSectionIds[Convert.ToInt32(MatterLandingSection.CalendarPanel, CultureInfo.InvariantCulture)]));
                }

                string matterInformationSection = string.Format(CultureInfo.InvariantCulture, ServiceConstants.CONTENT_EDITOR_WEB_PART, string.Format(CultureInfo.InvariantCulture, ServiceConstants.MATTER_LANDING_SECTION_CONTENT, contentEditorSectionIds[Convert.ToInt32(MatterLandingSection.InformationPanel, CultureInfo.InvariantCulture)]));
                string cssLink                 = string.Format(CultureInfo.InvariantCulture, matterSettings.MatterLandingCSSFileName, matterSettings.MatterLandingFolderName);
                string commonCssLink           = string.Format(CultureInfo.InvariantCulture, matterSettings.CommonCSSFileLink, matterSettings.CommonFolderName);
                string jsLinkMatterLandingPage = string.Format(CultureInfo.InvariantCulture, matterSettings.MatterLandingJSFileName, matterSettings.MatterLandingFolderName);
                string jsLinkJQuery            = string.Format(CultureInfo.InvariantCulture, matterSettings.JQueryFileName, matterSettings.CommonFolderName);
                string jsLinkCommon            = string.Format(CultureInfo.InvariantCulture, matterSettings.CommonJSFileLink, matterSettings.CommonFolderName);
                string headerWebPartSection    = string.Format(CultureInfo.InvariantCulture, ServiceConstants.MATTER_LANDING_SECTION_CONTENT, contentEditorSectionIds[Convert.ToInt32(MatterLandingSection.HeaderPanel, CultureInfo.InvariantCulture)]);
                string footerWebPartSection    = string.Format(CultureInfo.InvariantCulture, ServiceConstants.MATTER_LANDING_SECTION_CONTENT, contentEditorSectionIds[Convert.ToInt32(MatterLandingSection.FooterPanel, CultureInfo.InvariantCulture)]);
                headerWebPartSection = string.Concat(string.Format(CultureInfo.InvariantCulture, ServiceConstants.STYLE_TAG, cssLink), headerWebPartSection);
                headerWebPartSection = string.Concat(string.Format(CultureInfo.InvariantCulture, ServiceConstants.STYLE_TAG, commonCssLink), headerWebPartSection);
                headerWebPartSection = string.Concat(string.Format(CultureInfo.InvariantCulture, ServiceConstants.SCRIPT_TAG_WITH_CONTENTS, string.Format(CultureInfo.InvariantCulture, ServiceConstants.MATTER_LANDING_STAMP_PROPERTIES, matter.Name, matter.MatterGuid, matterExtraPropertiesValues)), headerWebPartSection);
                footerWebPartSection = string.Concat(string.Format(CultureInfo.InvariantCulture, ServiceConstants.SCRIPT_TAG, jsLinkMatterLandingPage), footerWebPartSection);
                footerWebPartSection = string.Concat(string.Format(CultureInfo.InvariantCulture, ServiceConstants.SCRIPT_TAG, jsLinkCommon), footerWebPartSection);
                footerWebPartSection = string.Concat(string.Format(CultureInfo.InvariantCulture, ServiceConstants.SCRIPT_TAG, jsLinkJQuery), footerWebPartSection);
                string   headerWebPart  = string.Format(CultureInfo.InvariantCulture, ServiceConstants.CONTENT_EDITOR_WEB_PART, headerWebPartSection);
                string   footerWebPart  = string.Format(CultureInfo.InvariantCulture, ServiceConstants.CONTENT_EDITOR_WEB_PART, footerWebPartSection);
                string   oneNoteWebPart = string.Format(CultureInfo.InvariantCulture, ServiceConstants.CONTENT_EDITOR_WEB_PART, string.Format(CultureInfo.InvariantCulture, ServiceConstants.MATTER_LANDING_SECTION_CONTENT, contentEditorSectionIds[Convert.ToInt32(MatterLandingSection.OneNotePanel, CultureInfo.InvariantCulture)]));
                string[] webParts       = { headerWebPart, matterInformationSection, oneNoteWebPart, listViewWebPart, rssFeedWebPart, rssTitleWebPart, footerWebPart, calendarWebpart, contentEditorWebPartTasks };
                result = webParts;
            }
            catch (Exception exception)
            {
                customLogger.LogError(exception, MethodBase.GetCurrentMethod().DeclaringType.Name, MethodBase.GetCurrentMethod().Name, logTables.SPOLogTable);
                throw;
            }
            return(result);
        }
Ejemplo n.º 22
0
 public static string HtmlDecode(this string url)
 {
     return(WebUtility.HtmlDecode(url));
 }
Ejemplo n.º 23
0
        /// <summary>
        /// Gets json from last.fm and adds the correct url and
        /// image to each song
        /// </summary>
        /// <param name="song"></param>
        /// <returns></returns>
        private async Task AddJsonElemnts(Song song)
        {
            string artist = song.Artist;
            string title  = song.Title;
            string uri    = "";

            var url = "http://ws.audioscrobbler.com/2.0/?method=track.getInfo&api_key=" + API_KEY +
                      "&format=json&artist=" + WebUtility.UrlEncode(artist) + "&track=" + WebUtility.UrlEncode(title);

            try
            {
                using (var httpClient = new HttpClient())
                {
                    var json = await httpClient.GetStringAsync(url);

                    // Use JSON.Net to convert into C# object
                    dynamic jsonObj = JsonConvert.DeserializeObject(json);
                    uri        = jsonObj.track.url;
                    song.Url   = jsonObj.track.url;
                    song.Image = jsonObj.track.album.image[0]["#text"];
                }
            }
            catch (Exception x)
            {
            }
        }
Ejemplo n.º 24
0
        // -------------------------------------------------------------------------------
        // -------------------------------------------------------------------------------
        /// <summary>
        /// Sets the element with the descendents of the parent XElement
        /// </summary>
        /// <param name="parEl"></param>
        /// <returns></returns>
        // -------------------------------------------------------------------------------
        // -------------------------------------------------------------------------------
        public void SetEl(XElement parEl)
        {
            RssRfc822DateTimeConverter dtConvert = new RssRfc822DateTimeConverter();

            // channel title
            xUtil.AddEl(parEl, TAG_TITLE, title);

            // link to channel
            xUtil.AddEl(parEl, TAG_LINK, link);

            // channel description
            xUtil.AddEl(parEl, TAG_DESCRIPTION, WebUtility.HtmlEncode(description));

            // optional elements are only included if they are not null or have string length
            // greater than zero or in the case of dates, greater that datetime.minvalue

            // language
            if (language.Length > 0)
            {
                xUtil.AddEl(parEl, TAG_LANGUAGE, language);
            }

            // copyright
            if (copyright.Length > 0)
            {
                xUtil.AddEl(parEl, TAG_COPYRIGHT, copyright);
            }

            // managing editor
            if (managingEditor.Length > 0)
            {
                xUtil.AddEl(parEl, TAG_MANAGINGEDITOR, managingEditor);
            }

            // webmaster
            if (webMaster.Length > 0)
            {
                xUtil.AddEl(parEl, TAG_WEBMASTER, webMaster);
            }

            if (pubDate != DateTime.MinValue)
            {
                xUtil.AddEl(parEl, TAG_PUBDATE, dtConvert.FormatDateTime(pubDate));
            }

            if (lastBuildDate != DateTime.MinValue)
            {
                xUtil.AddEl(parEl, TAG_LASTBUILDDATE, dtConvert.FormatDateTime(lastBuildDate));
            }


            // applicable categories
            if (categories.Count > 0)
            {
                for (int i = 0; i < categories.Count; i++)
                {
                    XElement el = categories[i].GetEl();
                    parEl.Add(el);
                }
            }


            // arrogance
            if (generator.Length == 0)
            {
                generator = RSS.GENERATOR;
            }


            // generator
            if (generator.Length > 0)
            {
                xUtil.AddEl(parEl, TAG_GENERATOR, generator);
            }

            if (docs.Length > 0)
            {
                xUtil.AddEl(parEl, TAG_DOCS, docs);
            }

            // multiple cloud interfaces allowed here
            if (cloud.Count > 0)
            {
                for (int i = 0; i < cloud.Count; i++)
                {
                    XElement cloudEl = cloud[i].GetEl();
                    parEl.Add(cloudEl);
                }
            }

            if (ttl > 0)
            {
                xUtil.AddEl(parEl, TAG_TTL, ttl);
            }

            if (image != null)
            {
                XElement imageEl = image.GetEl();
                parEl.Add(imageEl);
            }

            if (textInput != null)
            {
                XElement textInputEl = textInput.GetEl();
                parEl.Add(textInputEl);
            }

            if (skipHours != null)
            {
                if (skipHours.Hours.Count > 0)
                {
                    XElement skipHoursEl = skipHours.GetEl();
                    parEl.Add(skipHoursEl);
                }
            }

            if (skipDays != null)
            {
                if (skipDays.Days.Count > 0)
                {
                    XElement skipDaysEl = skipDays.GetEl();
                    parEl.Add(skipDaysEl);
                }
            }
        }
Ejemplo n.º 25
0
        private async Task <T> GetLibData <T>(string id, string type, LanguageType lan) where T : class
        {
            string route = Statics.LIB_QUERY_URL + $"?language={lan.ToString().ToLower()}&item={WebUtility.UrlEncode(id)}&category={type}";
            var    data  = await NetworkTools.GetEntityAsync <T>(route, Token, ExceptionAction);

            return(data);
        }
Ejemplo n.º 26
0
        private async Task <IEnumerable <Value> > FindAsync(
            string tableName,
            Key key  = null,
            int take = -1,
            IEnumerable <Criteria> criterias = null)
        {
            var table = await this.EnsureTableAsync(tableName, false);

            if (table == null)
            {
                return(new List <Value>());
            }

            var filters = new List <string>();

            if (key?.PartitionKey != null)
            {
                filters.Add(TableQuery.GenerateFilterCondition(
                                "PartitionKey",
                                QueryComparisons.Equal,
                                WebUtility.UrlEncode(key.PartitionKey)));
            }

            if (key?.RowKey != null)
            {
                filters.Add(TableQuery.GenerateFilterCondition(
                                "RowKey",
                                QueryComparisons.Equal,
                                WebUtility.UrlEncode(key.RowKey)));
            }

            this.Map(criterias, filters);

            var query = new TableQuery();

            if (filters.Count > 0)
            {
                var filter = filters[0];
                for (var i = 1; i < filters.Count; i++)
                {
                    filter = TableQuery.CombineFilters(filter, TableOperators.And, filters[i]);
                }

                query = query.Where(filter);
            }

            if (take > 0)
            {
                query = query.Take(take);
            }

            TableContinuationToken token = null;
            var entities = new List <DynamicTableEntity>();

            do
            {
                var queryResults = await table.ExecuteQuerySegmentedAsync(query, token);

                entities.AddRange(queryResults.Results);
                token = queryResults.ContinuationToken;
            }while(token != null);

            return(entities.Select(this.ToValue).ToList());
        }
Ejemplo n.º 27
0
        //TODO shoud be moved to another layer
        private async Task <User> CreateUser(User user)
        {
            User newUser = null;

            bool verified;
            bool allowregistration;

            if (user.Username == UserNames.Host || User.IsInRole(RoleNames.Admin))
            {
                verified          = true;
                allowregistration = true;
            }
            else
            {
                verified          = false;
                allowregistration = _sites.GetSite(user.SiteId).AllowRegistration;
            }

            if (allowregistration)
            {
                IdentityUser identityuser = await _identityUserManager.FindByNameAsync(user.Username);

                if (identityuser == null)
                {
                    identityuser                = new IdentityUser();
                    identityuser.UserName       = user.Username;
                    identityuser.Email          = user.Email;
                    identityuser.EmailConfirmed = verified;
                    var result = await _identityUserManager.CreateAsync(identityuser, user.Password);

                    if (result.Succeeded)
                    {
                        user.LastLoginOn   = null;
                        user.LastIPAddress = "";
                        newUser            = _users.AddUser(user);
                        if (!verified)
                        {
                            string token = await _identityUserManager.GenerateEmailConfirmationTokenAsync(identityuser);

                            string url          = HttpContext.Request.Scheme + "://" + _tenants.GetAlias().Name + "/login?name=" + user.Username + "&token=" + WebUtility.UrlEncode(token);
                            string body         = "Dear " + user.DisplayName + ",\n\nIn Order To Complete The Registration Of Your User Account Please Click The Link Displayed Below:\n\n" + url + "\n\nThank You!";
                            var    notification = new Notification(user.SiteId, null, newUser, "User Account Verification", body, null);
                            _notifications.AddNotification(notification);
                        }

                        // assign to host role if this is the host user ( initial installation )
                        if (user.Username == UserNames.Host)
                        {
                            int      hostroleid = _roles.GetRoles(user.SiteId, true).Where(item => item.Name == RoleNames.Host).FirstOrDefault().RoleId;
                            UserRole userrole   = new UserRole();
                            userrole.UserId        = newUser.UserId;
                            userrole.RoleId        = hostroleid;
                            userrole.EffectiveDate = null;
                            userrole.ExpiryDate    = null;
                            _userRoles.AddUserRole(userrole);
                        }

                        // add folder for user
                        Folder folder = _folders.GetFolder(user.SiteId, Utilities.PathCombine("Users", Path.DirectorySeparatorChar.ToString()));
                        if (folder != null)
                        {
                            _folders.AddFolder(new Folder
                            {
                                SiteId      = folder.SiteId,
                                ParentId    = folder.FolderId,
                                Name        = "My Folder",
                                Path        = Utilities.PathCombine(folder.Path, newUser.UserId.ToString(), Path.DirectorySeparatorChar.ToString()),
                                Order       = 1,
                                IsSystem    = true,
                                Permissions = new List <Permission>
                                {
                                    new Permission(PermissionNames.Browse, newUser.UserId, true),
                                    new Permission(PermissionNames.View, RoleNames.Everyone, true),
                                    new Permission(PermissionNames.Edit, newUser.UserId, true)
                                }.EncodePermissions()
                            });
                        }
                    }
                }
                else
                {
                    var result = await _identitySignInManager.CheckPasswordSignInAsync(identityuser, user.Password, false);

                    if (result.Succeeded)
                    {
                        newUser = _users.GetUser(user.Username);
                    }
                }

                if (newUser != null && user.Username != UserNames.Host)
                {
                    // add auto assigned roles to user for site
                    List <Role> roles = _roles.GetRoles(user.SiteId).Where(item => item.IsAutoAssigned).ToList();
                    foreach (Role role in roles)
                    {
                        UserRole userrole = new UserRole();
                        userrole.UserId        = newUser.UserId;
                        userrole.RoleId        = role.RoleId;
                        userrole.EffectiveDate = null;
                        userrole.ExpiryDate    = null;
                        _userRoles.AddUserRole(userrole);
                    }
                }

                if (newUser != null)
                {
                    newUser.Password = ""; // remove sensitive information
                    _logger.Log(user.SiteId, LogLevel.Information, this, LogFunction.Create, "User Added {User}", newUser);
                }
            }
            else
            {
                _logger.Log(user.SiteId, LogLevel.Error, this, LogFunction.Create, "User Registration Is Not Enabled For Site. User Was Not Added {User}", user);
            }

            return(newUser);
        }
        public static void ApplyParameterToRequestString(ref string requestString, string argument, string value)
        {
            var token = requestString.Contains("?") ? "&" : "?";

            requestString = $"{requestString}{token}{argument}={WebUtility.UrlEncode(value)}";
        }
Ejemplo n.º 29
0
        public async Task Forgot([FromBody] User user)
        {
            if (ModelState.IsValid)
            {
                IdentityUser identityuser = await _identityUserManager.FindByNameAsync(user.Username);

                if (identityuser != null)
                {
                    string token = await _identityUserManager.GeneratePasswordResetTokenAsync(identityuser);

                    string url          = HttpContext.Request.Scheme + "://" + _tenants.GetAlias().Name + "/reset?name=" + user.Username + "&token=" + WebUtility.UrlEncode(token);
                    string body         = "Dear " + user.DisplayName + ",\n\nPlease Click The Link Displayed Below To Reset Your Password:\n\n" + url + "\n\nThank You!";
                    var    notification = new Notification(user.SiteId, null, user, "User Password Reset", body, null);
                    _notifications.AddNotification(notification);
                    _logger.Log(LogLevel.Information, this, LogFunction.Security, "Password Reset Notification Sent For {Username}", user.Username);
                }
                else
                {
                    _logger.Log(LogLevel.Error, this, LogFunction.Security, "Password Reset Notification Failed For {Username}", user.Username);
                }
            }
        }
Ejemplo n.º 30
0
    protected void Page_Load(object sender, EventArgs e)
    {
        m_ConfigHelper = new ConfigHelper();
        m_WebLogService = new WebLogService();
        m_PostFactory = new PostFactory();
        m_AuthFactory = new AuthFactory();
        m_CommonFactory = new CommonFactory();
        m_SessionHelper = new SessionHelper();
        m_WebUtility = new WebUtility();
        m_AuthService = m_AuthFactory.GetAuthService();
        m_PostFileService = m_PostFactory.GetPostFileService();
        m_CommonService = m_CommonFactory.GetCommonService();
        m_PostService = m_PostFactory.GetPostService();

        if (!IsPostBack)
        {
            pnlContent.Visible = false;
            fillGridView();
            ShowMode();
        }
    }
Ejemplo n.º 31
0
 public static string ConstructSearchUrl(string userid, string limit, string query)
 {
     return(ServerUrl(int.Parse(ServerSettings.JMMServerPort), MainWindow.PathAddressPlex + "/Search/" + WebUtility.UrlEncode(userid) + "/" + limit + "/" + WebUtility.UrlEncode(query)));
 }