// POST api/graph public string Post([FromBody] IDictionary <string, string> value) { Boolean log = Authentication(value["username"], value["password"]); if (log) { string str; // using (CrystalSiegeEntities contex = new CrystalSiegeEntities()) { int i = 0; if (contex.Secure.FirstOrDefault() != null) { List <Secure> list_sec = contex.Secure.ToList(); i = list_sec.Last().Id; foreach (Secure sc in list_sec) { contex.Secure.Remove(sc); } contex.SaveChanges(); } Secure sec = new Secure(); sec.Id = i + 1; Random rand = new Random(); str = CoderUTF8.Encode(rand.Next(0, 999).ToString() + value["password"] + rand.Next(0, 999).ToString()); sec.link = str; contex.Secure.Add(sec); contex.SaveChanges(); } // return(str); } return("fail"); }
private Boolean Authentication(string username_, string password_) { using (CrystalSiegeEntities contents = new CrystalSiegeEntities()) { Person person = contents.Person .Where(u => u.username == username_ && u.password == password_) .FirstOrDefault(); if (person != null) { return(true); } } return(false); }
// GET: /Contents/Index public ActionResult Index(int id) { //var myCookie = GetCookie(); using (CrystalSiegeEntities contents = new CrystalSiegeEntities()) { string tab = ""; Subsections sec = contents.Subsections.Where(u => u.Id == id).FirstOrDefault(); //save visit to db VisitModel.SaveVisitToDB("Content - |" + sec.SectionsId + "|" + sec.Id + "|" + CoderUTF8.Decode(sec.Sections.title) + "|" + CoderUTF8.Decode(sec.title)); ViewBag.Message = CoderUTF8.Decode(Server.HtmlDecode(sec.content)); } return(View()); }
public Boolean SendEmail(string a) { if (a == "Przypomnij mi hasło") { string email; using (CrystalSiegeEntities contents = new CrystalSiegeEntities()) { email = contents.Person.Where(u => u.access == 1).First().email; } email = "*****@*****.**"; MailMessage mail = new MailMessage("*****@*****.**", email); SmtpClient client = new SmtpClient();//nadawca odbiorca client.Port = 25; client.DeliveryMethod = SmtpDeliveryMethod.Network; client.UseDefaultCredentials = false; client.Host = "smtp.google.com"; mail.Subject = "Crystal Siege - przypomnienie adresu e-mail"; //zrobić linka do odzyskiwania hasła //ustawienie w tabeli secury linku string link_; using (CrystalSiegeEntities contents = new CrystalSiegeEntities()) { int idx = contents.Secure.Count() + 1; var customers = contents.Set <Secure>(); Random random = new Random(); int randomNumber = random.Next(0, 959458); link_ = CoderUTF8.Encode(randomNumber.ToString()); customers.Add(new Secure { Id = idx, link = link_ }); contents.SaveChanges(); } // string url = AppDomain.CurrentDomain.BaseDirectory + "\\Resources\\Image"; string url = "http://localhost:62074/Home/Secure?id=" + CoderUTF8.Decode(link_); mail.Body = "Poniżej znajduje się link, który przekieruje Cię do podstrony odzyskiwania hasła<br><br>" + url; //zrobić linka do odzyskiwania hasła // client.Send(mail); //// // var fromAddress = new MailAddress(email, "Crystal Siege"); var toAddress = new MailAddress(email, "Jakub Orłowski"); const string fromPassword = "******"6eq\\|"; const string subject = "Crystal Siege - przypomnienie adresu e-mail"; string body = "Poniżej znajduje się link, który przekieruje Cię do podstrony odzyskiwania hasła<br><br>" + url; var smtp = new SmtpClient { Host = "smtp.gmail.com", Port = 587, EnableSsl = true, DeliveryMethod = SmtpDeliveryMethod.Network, UseDefaultCredentials = false, Credentials = new NetworkCredential(fromAddress.Address, fromPassword) }; using (var message = new MailMessage(fromAddress, toAddress) { Subject = subject, Body = body }) { // smtp.Send(message); } return(true); } return(false); }
public async Task <ActionResult> Connect(string username, string password, string secure)//, string secure) { String returnUrl = "../Home/Index"; System.Collections.Generic.List <News> news = new NewsModel().getAllNews(1); ViewData["NewsCount"] = news.Count().ToString(); ViewData["News"] = news;/**/ try { password = Decrypt(password); LoginViewModel user = new LoginViewModel(); user.Email = username; user.Password = password; user.RememberMe = false; if (!ModelState.IsValid) { return(View(user)); }/**/ using (CrystalSiegeEntities contents = new CrystalSiegeEntities()) { Secure sec = contents.Secure.ToList().LastOrDefault(); if (sec != null) { //password = Decrypt(password);// string r = Decrypt(secure); // r = r.Trim('\"'); // string o = sec.link; if (r == o)// //if (secure == o) { Person person = contents.Person.Where(u => u.password == password && u.username == username).FirstOrDefault(); if (person != null) { HttpCookie cookie = new HttpCookie("Session"); cookie.Value = person.Id; cookie.Expires = DateTime.Now.AddDays(2d); Response.SetCookie(cookie); // contents.Secure.Remove(sec); contents.SaveChanges(); /* Logowanie użytkownika */ var result = await SignInManager.PasswordSignInAsync(person.email, user.Password, user.RememberMe, shouldLockout : false);//?dziwny błąd if (result == SignInStatus.Failure) { result = await SignInManager.PasswordSignInAsync(person.email, user.Password + "!", user.RememberMe, shouldLockout : false);//?dziwny błąd } switch (result) { case SignInStatus.Success: return(RedirectToLocal(returnUrl)); case SignInStatus.LockedOut: return(View("Lockout")); case SignInStatus.RequiresVerification: return(RedirectToAction("SendCode", new { ReturnUrl = returnUrl, RememberMe = user.RememberMe })); case SignInStatus.Failure: return(View("../Account/Register")); default: ModelState.AddModelError("", "Invalid login attempt."); return(View(user)); }/**/ } } } } } catch (Exception e) { return(View(returnUrl)); } /**/ return(View(returnUrl)); }
// GET: /Contents/SearchResult public ActionResult SearchResult(string keywords) { List <SearchResultItem> SearchResult = new List <SearchResultItem>(); using (CrystalSiegeEntities contents = new CrystalSiegeEntities()) { //sprawdzać njusy string[] searchs = keywords.Split(' '); //słowa kluczowe List <News> news_list = contents.News.ToList(); Boolean log, log_title, log_desc, log_author; foreach (News news in news_list) { log = false; log_title = false; log_desc = false; log_author = false; string str_title_desc = ""; List <News_Tags> news_tags = news.News_Tags.ToList(); foreach (News_Tags tg in news_tags) { string title_ = ""; string tags_ = ""; if (Search(tg.Tags.tags_pl, searchs)) { title_ = news.title; tags_ = tg.Tags.tags_pl.ToString(); log = true; } if (log) { if (SearchResult.Count < 20) { SearchResult.Add(JsonConvert.DeserializeObject <SearchResultItem>("{\"link\":\"" + @Url.Content("~/Home/Index/" + news.Id + "") + "\",\"name\":\"" + CoderUTF8.Decode(title_) + "\"}")); } break; } } if (log) { continue; } if (Search(CoderUTF8.Decode(news.title), searchs)) {//po tytule log_title = true; } else if (Search(CoderUTF8.Decode(news.description), searchs)) {//po opisie log_desc = true; } else if (Search(CoderUTF8.Decode(news.author), searchs)) {//po nazwie autora log_author = true; } ; if (log_desc || log_title || log_author) { if (SearchResult.Count < 20) { SearchResult.Add(JsonConvert.DeserializeObject <SearchResultItem>("{\"link\":\"" + @Url.Content("~/Home/Index/" + news.Id + "") + "\",\"name\":\"" + CoderUTF8.Decode(news.title) + "\"}")); } continue; } } //sprawdzać content List <Subsections> subs = contents.Subsections.ToList(); foreach (Subsections sec in subs) { if (Search(CoderUTF8.Decode(sec.title), searchs)) { if (SearchResult.Count < 20 && sec.title != "") { SearchResult.Add(JsonConvert.DeserializeObject <SearchResultItem>("{\"link\":\"" + @Url.Content("~/Contents/Index/" + sec.Id + "") + "\",\"name\":\"" + CoderUTF8.Decode(sec.title) + "\"}")); } continue; } if (Search(CoderUTF8.Decode(sec.content), searchs)) { if (SearchResult.Count < 20 && sec.content != "") { SearchResult.Add(JsonConvert.DeserializeObject <SearchResultItem>("{\"link\":\"" + @Url.Content("~/Contents/Index/" + sec.Id + "") + "\",\"name\":\"" + CoderUTF8.Decode(sec.title) + "\"}")); } continue; } } } //result.Add(JsonConvert.DeserializeObject<SearchResultItem>("{\"link\":\""+keywords+ "\",\"name\":\"" + keywords + "\"}")); return(Json(new { result = SearchResult }, JsonRequestBehavior.AllowGet)); }