Ejemplo n.º 1
0
        public static void SendConfirmationEmail(string userName)
        {
            EcoPathDBEntities _context = new EcoPathDBEntities();
            var user = (from ua in _context.User_Accounts
                        where ua.Username == userName
                        select ua).FirstOrDefault();

            if (user != null)
            {
                var confirmationGuid = user.Id.ToString();
                var verifyUrl        =
                    HttpContext.Current.Request.Url.GetLeftPart(UriPartial.Authority) + "/EcoPathPortal/Account/Verify/" + confirmationGuid;

                using (var client = new SmtpClient())
                {
                    using (var message = new MailMessage(EmailFrom, user.Email))
                    {
                        message.Subject = "Потвърдете вашата регистрация в Еко-Пътеки БГ";
                        message.Body    = "<html><head><meta content=\"text/html; charset=utf-8\" /></head><body><p>"
                                          + userName + ", </p><p>За да потвърдите вашият акаунт, моля натиснете този линк:</p>"
                                          + "<p><a href=\"" + verifyUrl + "\" target=\"_blank\">" + verifyUrl
                                          + "</a></p><div>Благодарим ви че се регистрирахте,</div><div>Екипът на еcopath.bg</div><p>Не отговаряйте на "
                                          + "този e-mail. Линкът за потвърждаване е личен и не трябва да го споделяте.</p></body></html>";

                        message.IsBodyHtml = true;

                        client.EnableSsl = true;
                        client.Send(message);
                    };
                };
            }
        }
Ejemplo n.º 2
0
        public ActionResult Index(string id = null)
        {
            var _context = new EcoPathDBEntities();
            int pathId;

            if (id == null)
            {
                return(RedirectToAction("Index", "Home"));
            }
            if (!Int32.TryParse(id, out pathId))
            {
                return(RedirectToAction("Index", "Home"));
            }

            var ecoPath = (from e in _context.EcoPaths
                           where e.Id == pathId
                           select e).FirstOrDefault();

            if (ecoPath == null)
            {
                return(RedirectToAction("Index", "Home"));
            }

            var model = new EcoPathModel(ecoPath);

            return(View(model));
        }
Ejemplo n.º 3
0
        public ActionResult Index(Models.EcoPathModel model, HttpPostedFileBase file)
        {
            var _context = new EcoPathDBEntities();

            var id = (from u in _context.User_Accounts
                      where u.Username == User.Identity.Name
                      select u.Id).FirstOrDefault();

            if (id != null)
            {
                if (!String.IsNullOrEmpty(model.newCommText))
                {
                    var newComment = new Comment
                    {
                        EcoPathId = model.entId,
                        UserId    = id,
                        Text      = model.newCommText,
                        Date      = DateTime.Now
                    };

                    _context.Comments.AddObject(newComment);
                    _context.SaveChanges();
                }

                if (file != null && file.ContentLength > 0)
                {
                    var fileName   = Path.GetFileName(file.FileName);
                    var fileTitle  = fileName.Substring(0, fileName.LastIndexOf('.'));
                    var folderPath = HttpRuntime.AppDomainAppPath + @"\Content\Images\" + model.entId;

                    var count = 1;
                    while (System.IO.File.Exists(Path.Combine(folderPath, fileName)))
                    {
                        var imageName = fileName.Substring(0, fileName.LastIndexOf('.'));
                        var imageType = fileName.Substring(fileName.LastIndexOf('.'));
                        fileName = imageName + "(" + count + ")" + imageType;
                    }
                    var path = Path.Combine(folderPath, fileName);
                    file.SaveAs(path);

                    var newImage = new Image
                    {
                        EcoPathId = 1,
                        UserId    = id,
                        ImageName = fileName,
                        Title     = fileTitle
                    };

                    _context.Images.AddObject(newImage);
                    _context.SaveChanges();
                }
            }
            return(RedirectToAction("Index", new { id = model.entId }));
        }
Ejemplo n.º 4
0
 public ActionResult Verify(string id)
 {
     if (string.IsNullOrEmpty(id) || (!Regex.IsMatch(id, @"[0-9a-f]{8}\-([0-9a-f]{4}\-){3}[0-9a-f]{12}")))
     {
         ViewBag.Msg = "Грешен линк";
         return(View());
     }
     else
     {
         EcoPathDBEntities _context = new EcoPathDBEntities();
         User_Account      user     = (from ua in _context.User_Accounts
                                       where ua.Id == new Guid(id)
                                       select ua).FirstOrDefault();
         if (user != null)
         {
             if (!user.Confirmed)
             {
                 user.Confirmed = true;
                 _context.SaveChanges();
                 ViewBag.Msg = "Вие успешно потвърдихте Вашият потребителски акаунт! Ще бъдете прехвърлени на началната страница след 5 секунди.";
                 FormsAuthentication.SetAuthCookie(user.Username, false);
                 return(View());
             }
             else
             {
                 FormsAuthentication.SignOut();
                 ViewBag.Msg = "Този потребителски акаунт е вече потвърден";
                 return(View());
             }
         }
         else
         {
             FormsAuthentication.SignOut();
             ViewBag.Msg = "Не съществува потребител с този код.";
             return(View());
         }
     }
 }