Ejemplo n.º 1
0
 /// <summary>
 ///     Edit values
 /// </summary>
 /// <param name="model">Model values to change</param>
 /// <returns>view with updated info and success/failure message</returns>
 public ActionResult EditRecaptcha(DbTables.GoogleCaptchaAPI model)
 {
     try
     {
         var GoogleRe        = new DbTables.GoogleCaptchaAPI();
         var GoogleRecaptcha = _context.GoogleCaptchaAPI.ToList();
         if (GoogleRecaptcha.Any())
         {
             GoogleRe         = GoogleRecaptcha.First();
             GoogleRe.SiteKey = model.SiteKey;
             GoogleRe.Secret  = model.Secret;
         }
         else
         {
             GoogleRe.SiteKey = model.SiteKey;
             GoogleRe.Secret  = model.Secret;
             _context.GoogleCaptchaAPI.Add(GoogleRe);
         }
         _context.SaveChanges();
         ViewBag.Success = "Google ReCaptcha variabler ble sukessfult oppdatert";
         return(PartialView("_RecaptchaPartial", _context.GoogleCaptchaAPI.First()));
     }
     catch (EntityException ex)
     {
         ViewBag.Error = "Error: " + ex.Message;
         return(PartialView("_RecaptchaPartial", _context.GoogleCaptchaAPI.First()));
     }
 }
Ejemplo n.º 2
0
        public ActionResult RequestMembership()
        {
            ViewBag.Message = "Forespør Medlemskap.";

            var GoogleCaptcha     = new DbTables.GoogleCaptchaAPI();
            var GoogleCaptchaList = _context.GoogleCaptchaAPI.ToList();


            var model = new RequestModel
            {
                MembershipRequest = new DbTables.MembershipRequest(),
                SiteKey           = GoogleCaptcha.SiteKey
            };

            if (GoogleCaptchaList.Any())
            {
                //check if there are google recaptcha element in the database, add to model if true
                if (GoogleCaptchaList.First().Enabeled)
                {
                    model.SiteKey = GoogleCaptchaList.First().SiteKey;
                }
            }
            var terms = _context.TermsOfUse.ToList();
            var Terms = new DbTables.TermsOfUse();

            if (terms.Any()) //check if there are any terms of use in the database
            {
                Terms = terms.First();
                if (Terms.Enabeled && (Terms.Terms.FileId != 0))
                {
                    model.TermsID = Terms.Terms.FileId;
                }
            }
            var background     = new DbTables.BackgroundImage();
            var backgroundList = _context.BackgroundImage.ToList();

            if (backgroundList.Any())
            {
                background = backgroundList.First();
                if (background.Enabeled)
                {
                    ViewBag.Style = "background:url('/File/Background?id=" + background.Image.FileId +
                                    "') no-repeat center center fixed;-webkit-background-size: cover;-moz-background-size: cover;-o-background-size: cover;background-size: cove;overflow-x: hidden;";
                    ViewBag.BackGround = "background-color:transparent;";
                }
            }
            return(View(model));
        }
Ejemplo n.º 3
0
        /// <summary>
        ///     Validates whether the recapthca failed or not
        /// </summary>
        /// <param name="encodedResponse">Response token from the Recapthca API</param>
        /// <returns>Returns true or false based on the validation of user</returns>
        public static bool Validate(string encodedResponse)
        {
            if (string.IsNullOrEmpty(encodedResponse))
            {
                return(false);
            }
            var _context          = new ApplicationDbContext();
            var client            = new WebClient();
            var GoogleCaptchaList = _context.GoogleCaptchaAPI.ToList();
            var GoogleCaptcha     = new DbTables.GoogleCaptchaAPI();

            if (GoogleCaptchaList.Any())
            {
                GoogleCaptcha = GoogleCaptchaList.First();
            }
            else
            {
                return(false);
            }
            var secret = GoogleCaptcha.Secret;

            if (string.IsNullOrEmpty(secret))
            {
                return(false);
            }

            var googleReply =
                client.DownloadString(
                    string.Format("https://www.google.com/recaptcha/api/siteverify?secret={0}&response={1}", secret,
                                  encodedResponse)); // upload values and get response

            var serializer = new JavaScriptSerializer();

            var reCaptcha = serializer.Deserialize <ReCaptcha>(googleReply); //serialize the answer

            return(reCaptcha.Success);
        }
Ejemplo n.º 4
0
        // GET: Admin/Various
        /// <summary>
        ///     Index view of various, check if various database elements are actually added and then add these to the model if
        ///     they exist
        /// </summary>
        /// <returns>Various index view</returns>
        public ActionResult Index()
        {
            var carouselObj   = new DbTables.Carousel();
            var GoogleCap     = new DbTables.GoogleCaptchaAPI();
            var GoogleCapList = _context.GoogleCaptchaAPI.ToList();

            if (GoogleCapList.Any())
            {
                GoogleCap = GoogleCapList.First();
            }
            var SendG        = new DbTables.SendGridAPI();
            var SendgridList = _context.SendGridAPI.ToList();

            if (SendgridList.Any())
            {
                SendG = SendgridList.First();
            }
            var Stripe     = new DbTables.StripeAPI();
            var StripeList = _context.StripeAPI.ToList();

            if (StripeList.Any())
            {
                Stripe = StripeList.First();
            }
            var Facebook     = new DbTables.Facebook();
            var FacebookList = _context.Facebook.ToList();

            if (FacebookList.Any())
            {
                Facebook = FacebookList.First();
            }
            var Twitter     = new DbTables.Twitter();
            var TwitterList = _context.Twitter.ToList();

            if (TwitterList.Any())
            {
                Twitter = TwitterList.First();
            }
            var Disqus     = new DbTables.Disqus();
            var DisqusList = _context.Disqus.ToList();

            if (DisqusList.Any())
            {
                Disqus = DisqusList.First();
            }
            var About     = new DbTables.Info();
            var AboutList = _context.About.ToList();

            if (AboutList.Any())
            {
                About = AboutList.First();
            }
            var carousel = _context.Carousel.ToList();

            if (carousel.Any())
            {
                carouselObj = carousel.First();
            }
            var Terms     = new DbTables.TermsOfUse();
            var TermsList = _context.TermsOfUse.ToList();

            if (TermsList.Any())
            {
                Terms = TermsList.First();
            }
            var Background     = new DbTables.BackgroundImage();
            var BackgroundList = _context.BackgroundImage.ToList();

            if (BackgroundList.Any())
            {
                Background = BackgroundList.First();
            }

            var model = new VariousModel
            {
                GoogleCaptchaAPI = GoogleCap,
                SendGridAPI      = SendG,
                Terms            = Terms,
                Carousel         = carouselObj,
                About            = About,
                StripeAPI        = Stripe,
                Twitter          = Twitter,
                Facebook         = Facebook,
                Background       = Background,
                Disqus           = Disqus
            };

            return(View(model));
        }