public void SendCode(int AuthorId)
        {
            Author author = authorHelper.GetById(AuthorId);

            // at this point, author must have a new email address to be verified
            author.isEmailConfirmed = false;
            authorHelper.Update(author);

            // invalidate all other previous EmailCodes of same author
            var oldConfirmations = emailCodeHelper.GetAll().Where(ec => ec.AuthorId == author.Id && !ec.isExpired);

            foreach (EmailCode code in oldConfirmations)
            {
                code.isExpired = true;
                emailCodeHelper.Update(code);
            }

            // 6 digit random code
            int confirmation_number = new Random().Next(100000, 999999);

            // save code to db
            emailCodeHelper.Create(new EmailCode()
            {
                AuthorId           = author.Id,
                Email              = author.Email,
                ConfirmationNumber = confirmation_number,
                isExpired          = false
            });

            // send email to author
            string title = "Confirmation number";
            string body  = "Dear " + author.FullName + "\nYour confirmation number is: " + confirmation_number;

            SendMail(author.Email, title, body);
        }
Exemple #2
0
        // GET: Post/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            Post post = postHelper.GetById(id.Value);

            if (post == null)
            {
                return(HttpNotFound());
            }

            if (!post.isActive)
            {
                if (!LoggedIn())
                {
                    if (!isAuthor() || !isAdmin())
                    {
                        return(RedirectToAction("Index", "Home"));
                    }
                }
            }

            Author author = authorHelper.GetById(post.AuthorId);

            ViewBag.isAnonymous = author.isAnonymous;
            ViewBag.AuthorEmail = author.Email;
            ViewBag.Categories  = categoryHelper.GetAll().Where(c => c.isActive);
            return(View(post));
        }
Exemple #3
0
        public ActionResult VerifyAuthor(int id)
        {
            if (!LoggedIn())
            {
                return(RedirectToAction("LoginAdmin", "Auth"));
            }

            if (!isAdmin())
            {
                return(RedirectToAction("Index", "Author"));
            }

            try
            {
                Author author = authorHelper.GetById(id);
                author.isVerified = true;
                authorHelper.Update(author);
            }
            catch (Exception) { }

            return(RedirectToAction("Authors"));
        }
        public ActionResult Author(int id)
        {
            Author author = authorHelper.GetById(id);

            author.Password = "";

            ViewBag.Author     = author;
            ViewBag.Categories = categoryHelper.GetAll().Where(c => c.isActive).ToList();

            if (!author.isAnonymous)
            {
                return(View(postHelper.GetAll().Where(p => p.AuthorId == author.Id && p.isActive).ToList()));
            }

            if ((LoggedIn() && isAdmin()) || (LoggedIn() && GetAuthorId() == id))
            {
                return(View(postHelper.GetAll().Where(p => p.AuthorId == author.Id).ToList()));
            }

            return(RedirectToAction("Index"));
        }
        public ActionResult Index()
        {
            if (!LoggedIn())
            {
                return(RedirectToAction("Login", "Auth"));
            }

            if (isAdmin())
            {
                return(RedirectToAction("Index", "Admin"));
            }

            if (!isAdmin() && !isAuthor())
            {
                return(RedirectToAction("Logout", "Auth"));
            }

            Author author = authorHelper.GetById(GetAuthorId());

            if (!author.isEmailConfirmed)
            {
                return(RedirectToAction("ConfirmEmail"));
            }

            List <Post> posts = postHelper.GetAll().Where(p => p.AuthorId == author.Id && p.isActive).OrderByDescending(p => p.DateCreated).ToList();

            ViewBag.Categories = categoryHelper.GetAll().Where(cat => cat.isActive);
            return(View(posts));
        }