public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) { if (reader.TokenType != JsonToken.StartObject) { return(null); } var gid = 0L; var token = default(EToken); reader.Read(); do { switch (reader.Value.ToString()) { case "gid": gid = (long)reader.ReadAsDouble().GetValueOrDefault(); break; case "token": token = EToken.Parse(reader.ReadAsString()); break; default: break; } reader.Read(); } while (reader.TokenType != JsonToken.EndObject); return(new GalleryInfo(gid, token)); }
public long CrearToken(EToken token) { try { long IdToken = -1; using (ctx_grupos ctx = new ctx_grupos()) { Token nuevoToken = new Token { NumberToken = token.NumberToken, CreateDate = token.CreateDate, ExpireDate = token.ExpireDate, Email = token.Email, Status = token.Status }; ctx.Token.Add(nuevoToken); ctx.SaveChanges(); IdToken = nuevoToken.IdToken; } return(IdToken); } catch (GettingException ex) { StackTrace st = new StackTrace(ex, true); StackFrame frame = st.GetFrame(0); throw new GettingException(string.Format("{0}", "Error: " + ex.Message.ToString() + " Origen: " + ex.TargetSite.ReflectedType.FullName.ToString() + " Metodo: " + frame.GetMethod().Name.ToString() + " Linea: " + frame.GetFileLineNumber().ToString())); } }
LKJsonObj ReadArray(string data) { List <object> array = new List <object>(); do { object obj = ReadJsObject(data); if (obj != null) { array.Add(obj); } string str_token = string.Empty; EToken token = ReadToken(data, ref str_token); if (token == EToken.right_bracket) { return(new LKJsonObj(array)); } else if (token == EToken.comma) { continue; } else { throw new Exception("invalid token"); } } while (true); }
protected void B_Recuperar_Click(object sender, EventArgs e) { EUsuario usuario = new DaoUser().getUserByUserName(TB_UserName.Text); if (usuario != null) { EToken validarToken = new DaoSeguridad().getTokenByUser(usuario.Id); EToken token = new EToken(); token.Creado = DateTime.Now; token.UserId = usuario.Id; token.Vigencia = DateTime.Now.AddHours(2); token.TokenGenerado = encriptar(JsonConvert.SerializeObject(token)); new DaoSeguridad().insertarToken(token); Correo correo = new Correo(); String mensaje = "su link de acceso es: " + "http://*****:*****@gmail.com", token.TokenGenerado, mensaje); L_Mensaje.Text = "Su nueva contraseña ha sido enviada a su correo"; } else { L_Mensaje.Text = "El usuario digitado no existe"; } }
private static long sendMail(EToken token) { long result = -1; MailMessage message = new MailMessage(); SmtpClient smtp = new SmtpClient(); message.From = new MailAddress("*****@*****.**"); message.To.Add(new MailAddress(token.Email)); message.Subject = "Grupos - Recordar Contraseña"; message.IsBodyHtml = true; message.Body = getHtml(token); smtp.Port = 25; smtp.Host = "190.8.176.202"; smtp.EnableSsl = false; smtp.UseDefaultCredentials = false; smtp.Credentials = new NetworkCredential("*****@*****.**", "Grupos2020*"); smtp.DeliveryMethod = SmtpDeliveryMethod.Network; try { smtp.Send(message); result = 1; } catch (SmtpException ex) { return(result); } return(result); }
public void insertarToken(EToken token) { using (var db = new Mapeo()) { db.token.Add(token); db.SaveChanges(); } }
private IToken Add(EToken token, int start, string text) { var rv = text.IsWordOperator() ? new Token(EToken.BinaryOperator, start, text) : new Token(token, start, text); Tokens.Add(rv); return(rv); }
internal static bool TryParseGalleryPopup(UriHandlerData data, out GalleryInfo info, out GalleryLaunchStatus type) { info = default; type = default; if (data.Paths.Count < 1) { return(false); } if (!Array.Exists(_Popups, s => data.Path0.Equals(s, StringComparison.OrdinalIgnoreCase))) { return(false); } if (!long.TryParse(data.Queries.GetString("gid"), out var gId)) { return(false); } var tokenstr = data.Queries.GetString("t") + data.Queries.GetString("token"); if (!EToken.TryParse(tokenstr, out var token)) { return(false); } info = new GalleryInfo(gId, token); type = GalleryLaunchStatus.Default; switch (data.Path0) { case "gallerytorrents.php": type = GalleryLaunchStatus.Torrent; break; case "stats.php": type = GalleryLaunchStatus.Stats; break; case "archiver.php": type = GalleryLaunchStatus.Archive; break; default: switch (data.Queries.GetString("act")) { case "addfav": type = GalleryLaunchStatus.Favorite; break; case "expunge": type = GalleryLaunchStatus.Expunge; break; case "rename": type = GalleryLaunchStatus.Rename; break; } break; } return(true); }
private List <Tuple <EToken, string, string> > TokenizeFile(List <string> ParsedLines) { List <Tuple <EToken, string, string> > tokens = new List <Tuple <EToken, string, string> >(); for (int i = 0; i < ParsedLines.Count; i++) { string line = ParsedLines[i]; if (Macros.IsValidMacro(line)) { // Determine what kind of token this is and then perform a lookahead. EToken token = Macros.GetMacroFromMacroString(line); string followingLine = RemoveUnparseableTokens(ParsedLines[i + 1]); // If this is a declaration token, we must perform some additional parsing. if (token == EToken.ClassDeclaration || token == EToken.StructDeclaration) { //Split the line along the color (ie. class Test : 'public Parent1, public Parent2, Parent3, private Parent4'). string[] declarationAndParents = followingLine.Split(':', StringSplitOptions.RemoveEmptyEntries); // Capture the declaration name (ie. 'class EntityName' turns into 'EntityName'). string declaringName = declarationAndParents[0].Split(' ', StringSplitOptions.RemoveEmptyEntries)[1].Trim(); tokens.Add(new Tuple <EToken, string, string>(token, line, declaringName)); // Capture any parent declarations as well. Split the parent portion of the declaration by comma. if (declarationAndParents.Length > 1) { // Split the parent declarations into tokens in the form of either 'public Parent' or just 'Parent'. string[] parents = declarationAndParents[1].Trim().Split(',', StringSplitOptions.RemoveEmptyEntries); // Iterate through all parents and remove any leading or trailing spaces. Then see if there is // a space inside the declaration. If there is, this is a parent declaration in the form of // 'public Parent', otherwise this is just a 'Parent'. for (int j = 0; j < parents.Length; j++) { // Check to see if this is a two keyword or single keyword declaration. string parentPair = parents[j].Trim(); string parent = ""; if (parentPair.Contains(' ')) { parent = parentPair.Split(' ', StringSplitOptions.RemoveEmptyEntries)[1]; } else { parent = parentPair; } tokens.Add(new Tuple <EToken, string, string>(EToken.ParentClassDeclaration, line, parent)); } } } else { tokens.Add(new Tuple <EToken, string, string>(token, line, followingLine)); } } } return(tokens); }
// read a token string EToken ReadToken(string data, ref string outs) { bool res = JumpOverEmptyChar(data); if (res == false) { outs = string.Empty; return(EToken.end); } StringBuilder sb = new StringBuilder(); while (true) { char c; res = GetCharacter(data, out c); if (res == true) { EToken token = GetToken(c); if (token == EToken.unknown) { if (IsEmptyChar(c) == false) { sb.Append(c); } else { outs = sb.ToString(); return(EToken.unknown); } } else { if (sb.Length > 0) { outs = sb.ToString(); mReadIndex--; // give back return(EToken.unknown); } else { outs = string.Empty; return(token); } } } else { outs = sb.ToString(); return(EToken.end); } } }
public long CrearToken(EToken token) { try { long IdToken = new DRecuperarPassword().CrearToken(token); return(IdToken); } catch (GettingException ex) { StackTrace st = new StackTrace(ex, true); StackFrame frame = st.GetFrame(0); throw new GettingException(string.Format("{0}", "Error: " + ex.Message.ToString() + " Origen: " + ex.TargetSite.ReflectedType.FullName.ToString() + " Metodo: " + frame.GetMethod().Name.ToString() + " Linea: " + frame.GetFileLineNumber().ToString())); } }
public ActionResult EnviarCorreoRecuperacion(string email) { int respuesta = 0;//0 => correo no existe, 1 => error al enviar correo, 2 => correo enviado try { bool correoExistente = new BRecuperarPassword().CorreoExistente(email); if (correoExistente) { string token = tokenNumber(); if (token != "") { EToken nuevoToken = new EToken { NumberToken = token, CreateDate = DateTime.Now, ExpireDate = DateTime.Now.AddMinutes(5), Email = email, Status = true }; long IdToken = new BRecuperarPassword().CrearToken(nuevoToken); if (IdToken > 0) { long resultado = sendMail(nuevoToken); if (resultado > 0) //email enviado { respuesta = 2; //enviado } else { resultado = 1; } } } } else { respuesta = 0;//no existe } } catch (GettingException ex) { StackTrace st = new StackTrace(ex, true); StackFrame frame = st.GetFrame(0); throw new GettingException(string.Format("{0}", "Error: " + ex.Message.ToString() + " Origen: " + ex.TargetSite.ReflectedType.FullName.ToString() + " Metodo: " + frame.GetMethod().Name.ToString() + " Linea: " + frame.GetFileLineNumber().ToString())); } return(Json(respuesta)); }
LKJsonObj ReadObject(string data) { Dictionary <string, object> value_map = new Dictionary <string, object>(); do { // find " string str_token = string.Empty; EToken token = ReadToken(data, ref str_token); if (token == EToken.quotation) { string key = ReadString(data); EToken colon = ReadToken(data, ref str_token); if (colon == EToken.colon) { object val = ReadJsObject(data); value_map.Add(key, val); } else { throw new Exception("need : between key and value"); } token = ReadToken(data, ref str_token); if (token == EToken.right_brace) { return(new LKJsonObj(value_map)); } else if (token == EToken.comma) { continue; } else { throw new Exception("need } at the end"); } } else if (token == EToken.right_brace) { return(new LKJsonObj(value_map)); } else { throw new Exception("invalid token"); } } while (true); }
public LKJsonObj ReadJsObject(string data) { string str_token = string.Empty; EToken token = ReadToken(data, ref str_token); if (token == EToken.left_brace) { return(ReadObject(data)); } else if (token == EToken.left_bracket) { return(ReadArray(data)); } else if (token == EToken.quotation) { return(new LKJsonObj(ReadString(data))); } else if (token == EToken.unknown) { /* * int n = 0; * float f = 0; * if (int.TryParse(str_token, out n) == true) * return new LKJsonObj(n); * else if (float.TryParse(str_token, out f) == true) * return new LKJsonObj(f); * * if (str_token == "true") * return new LKJsonObj(true); * else if (str_token == "false") * return new LKJsonObj(false); * else if (str_token == "null") * return null; */ return(new LKJsonObj(str_token)); } else if (token == EToken.right_bracket) { // give back GiveBack(); return(null); } else { throw new Exception("invalid token"); } }
public TStyle GetStyle(EToken token) { switch (token) { case EToken.Comment: return(Comment); case EToken.String: return(String); case EToken.StringEscape: return(StringEscape); case EToken.Number: return(Number); case EToken.Punctuation: return(Punctuation); case EToken.Operator: return(Operator); case EToken.Keyword: return(Keyword); case EToken.Namespace: return(Namespace); case EToken.Type: return(Type); case EToken.Function: return(Function); case EToken.LocalVar: return(LocalVar); case EToken.Parameter: return(Parameter); case EToken.Field: return(Field); case EToken.Constant: return(Constant); case EToken.EnumMember: return(EnumMember); case EToken.Label: return(Label); case EToken.Preprocessor: return(Preprocessor); case EToken.Excluded: return(Excluded); case EToken.XmlDocText: return(XmlDocText); case EToken.XmlDocTag: return(XmlDocTag); case EToken.LineNumber: return(LineNumber); } return(default);
internal static bool TryParse(UriHandlerData data, out ImageInfo info) { if (data.Path0 == "s" && data.Paths.Count >= 3) { var sp = data.Paths[2].Split('-'); if ((sp.Length == 2) && long.TryParse(sp[0], out var gID) && int.TryParse(sp[1], out var pID) && EToken.TryParse(data.Paths[1], out var token)) { info = new ImageInfo(gID, token, pID); return(true); } } info = default; return(false); }
public static string Name(this EToken token) { switch (token) { case EToken.ScanError: return("<ScanError>"); case EToken.EOT: return("<EOT>"); case EToken.Identifier: return("<Identifier>"); case EToken.StringLiteral: return("<StringLiteral>"); case EToken.Number: return("<Number>"); case EToken.BinaryOperator: return("<BinOp>"); case EToken.UnaryOperator: return("Unop<>"); case EToken.EqualsOperator: return("<EqualsOp>"); case EToken.Comma: return("<Comma>"); case EToken.Semicolon: return("<SemiColon>"); case EToken.Bang: return("<Bang>"); case EToken.OpenParen: return("<OpenParen>"); case EToken.CloseParen: return("<CloseParen>"); case EToken.ExternRef: return("<ExternRef>"); case EToken.OpenExternRef: return("<OpenExternRef>"); case EToken.OpenBrace: return("<OpenBrace>"); case EToken.CloseBrace: return("<CloseBrace>"); case EToken.Apostrophe: return("<Apostrophe>"); case EToken.ErrorTag: return("<ErrorTag>"); default: return("<Unknown>"); } }
private Gallery(long id, EToken token, int recordCount) : base(recordCount) { Id = id; Token = token; Rating = new RatingStatus(this); GalleryUri = new GalleryInfo(id, token).Uri; if (Client.Current.Settings.RawSettings.TryGetValue("tr", out var trv)) { switch (trv) { case "1": _PageSize = 50; break; case "2": _PageSize = 100; break; case "3": _PageSize = 200; break; default: _PageSize = 20; break; } } }
private static string getHtml(EToken token) { Seguridad seguridad = new Seguridad(); var emailEncriptado = seguridad.Encriptar(token.Email); var url = "https://*****:*****@"<div bgcolor='#f3f3f3' style='margin:5px 0 0 0;padding:0;background-color:#f3f3f3'><p></p>" + "<table bgcolor = '#f3f3f3' border='0' cellpadding='0' cellspacing ='0' style = 'color:#4a4a4a;font-family:'Museo Sans Rounded',Museo Sans Rounded,'Museo Sans',Museo Sans,'Helvetica Neue',Helvetica,Arial,sans-serif;font-size:14px;line-height:20px;border-collapse:callapse;border-spacing:0;margin:0 auto' width='100%'>" + "<tbody><tr><td style ='padding-left:20px;padding-right:20px'><table align ='center' border ='0' cellpadding = '0 cellspacing = '0' style = 'width:100%;margin:0 auto;max-width:600px' width = '100%'>" + "<tbody><tr style = 'background: white;font-weight: bold;'><td style = 'text-align:center;padding-top:3%'>CAMBIAR CONTRASEÑA</td></tr><tr><td bgcolor = '#ffffff' style = 'background-color:#ffffff;padding:9%'>" + "<table border = '0' cellpadding = '0' cellspacing = '0' id = 'm_-740823046140379716intro' style = 'width:100%;margin:0 auto'><tbody><tr><td style = 'max-width:600px' width = '100%'>" + "Tu código es <b>[token]</b>, recuerda que será valido por 5 minutos.<br><br>Ingresa a la siguiente dirección para cambiar tu contraseña: [url]</td></tr></tbody></table></td></tr>" + "<tr><td border = '0' cellpadding='0' cellspacing='0' style='padding:20px 0' width='100%'><table border = '0' cellpadding='0' cellspacing='0' style='border-collapse:collapse' width='100%'>" + "<tbody><tr>" + "<td style = 'padding:20px' width='100%'><div style = 'margin:0;text-align:center;font-size:12px;color:#bbbbbb'> NO RESPONDER - Mensaje Generado Automáticamente</div><div style = 'margin:0;font-size:11px;text-align:center;color:#bbbbbb' >©2020 Grupos.co | Bogotá, Colombia</div>" + "</td></tr></tbody></table></td></tr></tbody></table></td></tr></tbody></table></div>"; html = html.Replace("[token]", token.NumberToken.ToString()); html = html.Replace("[url]", url); return(html); }
internal Gallery( long gid, string error = null, string token = "0", string title = null, string title_jpn = null, string category = null, string thumb = null, string uploader = null, string posted = null, string filecount = null, long filesize = 0, bool expunged = true, string rating = null, string torrentcount = null, string[] tags = null) : this(gid, EToken.Parse(token.CoalesceNullOrWhiteSpace("0")), int.Parse(filecount, NumberStyles.Integer, CultureInfo.InvariantCulture)) { if (error != null) { throw new Exception(error); } Available = !expunged; Title = HtmlEntity.DeEntitize(title); TitleJpn = HtmlEntity.DeEntitize(title_jpn); if (!_CategoriesForRestApi.TryGetValue(category, out var ca)) { ca = Category.Unspecified; } Category = ca; Uploader = HtmlEntity.DeEntitize(uploader); Posted = DateTimeOffset.FromUnixTimeSeconds(long.Parse(posted, NumberStyles.Integer, CultureInfo.InvariantCulture)); FileSize = filesize; Expunged = expunged; Rating.AverageScore = double.Parse(rating, NumberStyles.Number, CultureInfo.InvariantCulture); TorrentCount = int.Parse(torrentcount, NumberStyles.Integer, CultureInfo.InvariantCulture); Tags = new TagCollection(this, tags.Select(tag => Tag.Parse(tag))); ThumbUri = ThumbClient.FormatThumbUri(thumb); }
internal static bool TryParseGallery(UriHandlerData data, out GalleryInfo info) { info = default; if (data.Paths.Count < 3) { return(false); } if (!Array.Exists(_GalleryPaths, s => data.Path0.Equals(s, StringComparison.OrdinalIgnoreCase))) { return(false); } if (!long.TryParse(data.Paths[1], out var gId)) { return(false); } if (!EToken.TryParse(data.Paths[2], out var token)) { return(false); } info = new GalleryInfo(gId, token); return(true); }
public static async Task <IList <Gallery> > Parse(HtmlDocument doc, CancellationToken token) { var dataRoot = doc.DocumentNode.Descendants().SingleOrDefault(node => node.HasClass("itg")); if (dataRoot is null) { return(Array.Empty <Gallery>()); } var gInfoList = new List <GalleryInfo>(dataRoot.ChildNodes.Count); var dataNodeList = new List <HtmlNode>(dataRoot.ChildNodes.Count); foreach (var node in dataRoot.ChildNodes) { foreach (var link in node.Descendants("a")) { var match = _GLinkMatcher.Match(link.GetAttribute("href", "")); if (!match.Success) { continue; } dataNodeList.Add(node); gInfoList.Add(new GalleryInfo(long.Parse(match.Groups[1].Value), EToken.Parse(match.Groups[2].Value))); break; } } var getG = Gallery.FetchGalleriesAsync(gInfoList); token.Register(getG.Cancel); var galleries = await getG; token.ThrowIfCancellationRequested(); for (var i = 0; i < galleries.Count; i++) { _HandleAdditionalInfo(dataNodeList[i], galleries[i]); } return(galleries); }
public GalleryInfo(long id, EToken token) { ID = id; Token = token; }
private IToken Add(EToken token, int start, ILinksLexer lexer) => Add(token, start, lexer.Formula.Substring(start - 1, lexer.CharPosition - start));
public ImageInfo(long galleryID, EToken imageKey, int pageID) { GalleryId = galleryID; ImageKey = imageKey; PageId = pageID; }
private bool _ReadNextToken() { while (_nextChar == ' ' || _nextChar == '\t' || _nextChar == '\r' || _nextChar == '\n') { _ReadNextChar(); } _nextTokenType = EToken.NONE; _nextTokenLexeme = ""; _nextTokenNumber = 0.0; _nextTokenStart = _streamIndex; if (_nextChar == '\0') { _nextTokenType = EToken.EOF; return(true); } if (_nextChar == '{') { _nextTokenType = EToken.OPEN_OBJECT; _ReadNextChar(); return(true); } if (_nextChar == '}') { _nextTokenType = EToken.CLOSE_OBJECT; _ReadNextChar(); return(true); } if (_nextChar == '[') { _nextTokenType = EToken.OPEN_ARRAY; _ReadNextChar(); return(true); } if (_nextChar == ']') { _nextTokenType = EToken.CLOSE_ARRAY; _ReadNextChar(); return(true); } if (_nextChar == ',') { _nextTokenType = EToken.LIST_SEPARATOR; _ReadNextChar(); return(true); } if (_nextChar == ':') { _nextTokenType = EToken.ASSIGNMENT; _ReadNextChar(); return(true); } if (_nextChar == '"') { _nextTokenType = EToken.STRING; _ReadNextChar(); while (_nextChar != '\0') { if (_nextChar == '"') { _ReadNextChar(); return(true); } _nextTokenLexeme += _nextChar; _ReadNextChar(); } return(false); } if (_IsAlpha(_nextChar)) { _nextTokenType = EToken.STRING; _nextTokenLexeme += _nextChar; _ReadNextChar(); while (_IsAlpha(_nextChar) || _IsDigit(_nextChar)) { _nextTokenLexeme += _nextChar; _ReadNextChar(); } if (_nextTokenLexeme == "true") { _nextTokenType = EToken.TRUE; } else if (_nextTokenLexeme == "false") { _nextTokenType = EToken.FALSE; } else if (_nextTokenLexeme == "null") { _nextTokenType = EToken.NULL; } return(true); } if (_IsDigit(_nextChar)) { _nextTokenType = EToken.NUMBER; _nextTokenLexeme += _nextChar; _ReadNextChar(); while (_IsDigit(_nextChar)) { _nextTokenLexeme += _nextChar; _ReadNextChar(); } if (_nextChar == '.') { _nextTokenLexeme += _nextChar; _ReadNextChar(); if (!_IsDigit(_nextChar)) { return(false); } _nextTokenLexeme += _nextChar; _ReadNextChar(); while (_IsDigit(_nextChar)) { _nextTokenLexeme += _nextChar; _ReadNextChar(); } } double.TryParse(_nextTokenLexeme, out _nextTokenNumber); return(true); } return(false); }
internal void Init(EToken imageKey, Uri thumb) { ImageKey = imageKey; ThumbUri = thumb; }
public Token(EToken token, int start, string text) { Value = token; Start = start; Text = text; }