Ejemplo n.º 1
0
        public async Task <ActionResult> history()
        {
            var json = new StreamReader(Request.Body).ReadToEnd();
            var data = JsonConvert.DeserializeObject <ApplicationUser>(json);

            var History = await UserPackagesBLL.Load_User_Payment_History(_context, data.UserName, true, 100); // fix top 100 records (no pagination);

            return(Ok(new { status = "success", history = History }));
        }
Ejemplo n.º 2
0
        // GET: media
        public async Task <IActionResult> Index(long?pid)
        {
            if (pid == null)
            {
                return(Redirect(Config.GetUrl("videos")));
            }

            var model = new VideoViewModel();

            model.isAllowed = true;

            /*if (HttpContext.Request.Query["status"].Count > 0)
             * {
             *  if (HttpContext.Request.Query["status"] == "pending")
             *      model.Message = SiteConfig.sharedLocalizer["video_message_02"]; // Video has been posted and will be appear shortly.
             * }*/

            var _list = await VideoBLL.LoadItems(_context, new VideoEntity()
            {
                id         = (long)pid,
                ispublic   = false,
                issummary  = false,
                isdropdown = false,
                nofilter   = true
            });

            if (_list.Count == 0)
            {
                model.isAllowed     = false;
                model.DetailMessage = SiteConfig.generalLocalizer["_no_records"].Value;
                return(View(model));
            }

            model.Data = _list[0];

            // fetch associated categories
            model.Data.category_list = await CategoryContentsBLL.FetchContentCategoryList(_context, _list[0].id, (byte)CategoryContentsBLL.Types.Videos);

            model.PreviewUrl = VideoUrlConfig.PrepareUrl(model.Data);

            if (model.Data.isadult == (byte)AdultTypes.Adult)
            {
                // 1:-> adult content, 0:-> non adult content
                var getValue = HttpContext.Session.GetString("adultmember");
                if (getValue == null)
                {
                    return(Redirect(Config.GetUrl("home/validateadult?surl=" + WebUtility.UrlEncode(model.PreviewUrl) + "")));
                }
            }

            // premium check
            if (_list[0].isfeatured == (byte)FeaturedTypes.Premium)
            {
                // content is marked as premium
                if (!User.Identity.IsAuthenticated)
                {
                    Response.Redirect(Config.GetUrl("login?ReturnUrl=" + WebUtility.UrlEncode(model.PreviewUrl) + ""), true);
                    return(View(model));
                }
                if (Jugnoon.Settings.Configs.PremiumSettings.premium_option == 1)
                {
                    // check for subscription
                    if (!UserPackagesBLL.Check_membership(_context, SiteConfig.userManager.GetUserName(User)))
                    {
                        // redirect to purchase page
                        Response.Redirect(Config.GetUrl("account/payment/packages?status=noaccess&surl=" + WebUtility.UrlEncode(model.PreviewUrl) + ""));
                        return(View(model));
                    }
                }
                else
                {
                    // credit base purchase view implementation logic required here.
                }
            }

            if (_list[0].isapproved == 0)
            {
                model.Message = SiteConfig.videoLocalizer["_video_pending_status"]; // Video is pending for moderator approval
            }
            if (_list[0].isenabled == (byte)EnabledTypes.Disabled)
            {
                model.isAllowed     = false;
                model.DetailMessage = SiteConfig.videoLocalizer["_video_blocked_status"]; // Video has been blocked. contact site administrator for more detail
                return(View(model));
            }

            var _Path = "videos/";

            if (_list[0].type == 1)
            {
                _Path = "audio/";
            }

            model.Info = new InfoViewModel()
            {
                ContentID      = model.Data.id,
                Description    = model.Data.description,
                Created_at     = model.Data.created_at,
                Author         = model.Data.author,
                Category       = model.Data.category_list,
                Tags           = model.Data.tags,
                Liked          = model.Data.liked,
                Disliked       = model.Data.disliked,
                Total_Ratings  = model.Data.total_rating,
                Average_Rating = model.Data.avg_rating,
                MediaType      = model.Data.type,
                Path           = _Path
            };

            // simple view statistics
            _list[0].views = _list[0].views + 1;
            VideoBLL.Update_Field_V3(_context, (long)pid, model.Data.views, "views");

            model.Data.views++;

            // Video Path settings
            string VideoPath   = "";
            string PictureName = "";

            if (model.Data.type == 0)
            {
                // video settings
                // if streamoutputs exist, video transcoded via Elastic Trancoder. It have own setup below.
                if (_list[0].streamoutputs == null || _list[0].streamoutputs == "")
                {
                    VideoPath = VideoUrlConfig.Return_FLV_Video_Url(model.Data.pub_url, model.Data.userid) + "/" + model.Data.videofilename;

                    /*string MP4Path = "";
                     * if (VideoPath.EndsWith(".webm"))
                     *  MP4Path = VideoPath.Replace(".webm", ".mp4");*/
                }

                if (model.Data.thumb_url != "none")
                {
                    PictureName = model.Data.thumb_url;
                }
                else
                {
                    PictureName = VideoUrlConfig.Return_Video_Thumb_Url(model.Data.thumb_url, model.Data.userid) + "/" + model.Data.thumbfilename;
                }
            }
            else
            {
                // audio settings
                VideoPath = VideoUrlConfig.Return_MP3_Audio_Url(model.Data.pub_url, model.Data.userid) + "/" + model.Data.videofilename;
                if (model.Data.thumb_url != "none")
                {
                    PictureName = model.Data.thumb_url;
                }
                else if (_list[0].coverurl.StartsWith("http"))
                {
                    PictureName = _list[0].coverurl;
                }
                else
                {
                    PictureName = VideoUrlConfig.Return_Video_Thumb_Url(model.Data.thumb_url, model.Data.userid) + "/" + model.Data.thumbfilename;
                }
            }


            string _script   = _list[0].embed_script;
            string _videoUrl = "";

            if (_list[0].preview_url != null && _list[0].preview_url != "")
            {
                _videoUrl = _list[0].preview_url;
            }
            else
            {
                _videoUrl = _list[0].pub_url;
            }

            model.Player = new VideoJsModelView()
            {
                EmbedScript = "",
                Type        = model.Data.type
            };

            if (_list[0].coverurl != null && _list[0].coverurl != "")
            {
                model.Player.PictureUrl = _list[0].coverurl;
            }
            else
            {
                model.Player.PictureUrl = PictureName;
            }

            // attach video data with player model
            // useful when you bind some video data within player
            model.Player.Data = _list[0];

            if (model.Data.type == 0)
            {
                // video player settings
                // if AWS Uploader Enabled
                if (_list[0].streamoutputs != null && _list[0].streamoutputs != "")
                {
                    // enabled advance adaptive streaming / mpeg-dash / hls
                    model.Player.enabledAWS = true;
                    model.Player.VideoFeed  = new List <SupportedVideos>();
                    var supportedStreamOptions = _list[0].streamoutputs.Split(char.Parse(","));
                    foreach (var option in supportedStreamOptions)
                    {
                        /*if (option == "mpegdash")
                         * {
                         *  //CloudFront.CreateCannedPrivateURL(_list[0].pub_url + "mpegdash.mpd", 3000),
                         *  model.Player.VideoFeed.Add(new SupportedVideos()
                         *  {
                         *      src = CloudFront.CreateCannedPrivateURL(_list[0].pub_url + "mpegdash.mpd", 900),
                         *      type = "application/dash+xml"
                         *  });
                         * }
                         *
                         * if (option == "hls")
                         * {
                         *  // CloudFront.CreateCannedPrivateURL(_list[0].pub_url + "hls.m3u8", 3000),
                         *  model.Player.VideoFeed.Add(new SupportedVideos()
                         *  {
                         *      src = CloudFront.CreateCannedPrivateURL(_list[0].pub_url + "hls.m3u8", 900),
                         *      type = "application/x-mpegURL"
                         *  });
                         * }*/
                        // temporary replace private url with public url
                        var url = _list[0].pub_url.Replace(Jugnoon.Videos.Configs.AwsSettings.private_url, Jugnoon.Videos.Configs.AwsSettings.public_url);
                        if (option == "mp4_480")
                        {
                            model.Player.VideoFeed.Add(new SupportedVideos()
                            {
                                //src = CloudFront.CreateCannedPrivateURL(_list[0].pub_url.Replace("d1fpw0dove1bub.cloudfront.net", "d16gr1zx2upz2x.cloudfront.net") + "menifest_480.mp4",900),
                                src  = url + "menifest_480.mp4",
                                type = "video/mp4"
                            });
                        }
                        // enable hd streaming (make sure it is enabled in AWS Lambda to publish

                        /*if (option == "mp4_720")
                         * {
                         *  model.Player.VideoFeed.Add(new SupportedVideos()
                         *  {
                         *      src = CloudFront.CreateCannedPrivateURL(_list[0].pub_url + "menifest_720.mp4", 3000),
                         *      type = "video/mp4"
                         *  });
                         * }*/
                    }
                }
                // If cloud enabled
                else if (_script != "" || _list[0].youtubeid != "")
                {
                    // third party embed video script enabled
                    if (_script == "")
                    {
                        model.Player.EmbedScript = _list[0].youtubeid;
                    }
                    else
                    {
                        model.Player.EmbedScript = _script;
                    }
                }
                else if (_videoUrl.StartsWith("http"))
                {
                    // cloud front streaming
                    model.Player.VideoUrl = CloudFront.CreateCannedPrivateURL(_videoUrl, 60);
                }
                else if (_list[0].videofilename.EndsWith("mp4"))
                {
                    if (TokenBLL.isTokenEnabled)
                    {
                        // Token Based Stream Authentication Enabled
                        // Recommended to stream on HTML5 Players
                        string maxParam = VideoBLL.GenerateBandwidthParam();
                        string Token    = TokenBLL.Add(_context);
                        model.Player.VideoUrl = "/stream/token.ashx?f=" + _list[0].videofilename + "&u=" + _list[0].userid + "&tk=" + Token + "" + maxParam;
                        if (_list[0].originalvideofilename.EndsWith(".png"))
                        {
                            model.Player.PictureUrl = "/contents/member/" + _list[0].userid + "/thumbs/" + _list[0].originalvideofilename;
                        }
                    }
                    else if (VideoBLL.EnableHttpStreaming)
                    {
                        // Http Streaming Enabled
                        // Recommended to stream on HTML5 Players
                        string maxParam = VideoBLL.GenerateBandwidthParam();
                        model.Player.VideoUrl = "/stream/stream.ashx?f=" + _list[0].videofilename + "&u=" + _list[0].userid + "" + maxParam;
                    }
                    else
                    {
                        // Direct Play
                        model.Player.VideoUrl = VideoPath;
                    }
                }
                else
                {
                    // load and play videos normally
                    model.Player.VideoUrl = VideoPath;
                }
            }
            else
            {
                // audio player settings
                model.Player.VideoUrl   = VideoPath;
                model.Player.PictureUrl = PictureName;
            }

            model.Action = new ActionViewModel()
            {
                ContentID    = (long)pid,
                Liked        = _list[0].liked,
                Disliked     = _list[0].disliked,
                UserName     = _list[0].userid,
                Favorites    = _list[0].favorites,
                FileName     = model.Data.videofilename,
                VideoPath    = VideoPath,
                isRating     = _list[0].isratings,
                Views        = _list[0].views,
                Comments     = _list[0].comments,
                Content_Type = "video",
                isEmbed      = true,
                MediaType    = model.Data.type,
                Ratingtype   = 1, // 0: like / dislike, 1: rating
                Avg_Ratings  = _list[0].avg_rating,
                Ratings      = _list[0].ratings,
                TotalRatings = _list[0].total_rating,
                isDownload   = false
            };


            model.Comments = new CommentViewModel()
            {
                isComment = _list[0].iscomments
            };

            string meta_title = _list[0].title;

            if (meta_title == "")
            {
                meta_title = "Media No " + _list[0].id;
            }

            string _desc = UtilityBLL.StripHTML(_list[0].description);

            if (_desc == "")
            {
                _desc = _list[0].title;
            }
            else if (_desc.Length > 160)
            {
                _desc = _desc.Substring(0, 160);
            }

            ViewBag.title       = meta_title;
            ViewBag.description = _desc + ", date uploaded: " + _list[0].created_at + ", VID: " + _list[0].id;

            return(View(model));
        }
        public async Task <IActionResult> login(LoginViewModel model, string returnUrl = null)
        {
            ViewData["ReturnUrl"] = returnUrl;
            ViewData["Page"]      = "signin";
            if (Configs.RegistrationSettings.enableChapcha)
            {
                var recaptcha = await _recaptcha.Validate(Request);

                if (!recaptcha.success)
                {
                    ModelState.AddModelError("Recaptcha", "Invalid Chapcha. Please try again!");
                    return(View("~/Views/Home/index.cshtml", model));
                }
            }
            if (ModelState.IsValid)
            {
                // IP Address tracking and processing
                string ipaddress = Request.HttpContext.Connection.RemoteIpAddress.ToString();
                if (BlockIPBLL.Validate(_context, ipaddress))
                {
                    model.Message = SiteConfig.generalLocalizer["_ip_blocked"].Value;
                    return(View("~/Views/Home/index.cshtml", model));
                }

                ApplicationUser user;
                if (model.Email.Contains("@"))
                {
                    user = await SiteConfig.userManager.FindByEmailAsync(model.Email);

                    if (user == null)
                    {
                        ModelState.AddModelError(string.Empty, SiteConfig.generalLocalizer["_invalid_login_attempt"].Value);
                        return(View("~/Views/Home/index.cshtml", model));
                    }
                    else
                    {
                        if (user.isenabled == 0)
                        {
                            // user account is suspeneded
                            ModelState.AddModelError(string.Empty, SiteConfig.generalLocalizer["_account_suspended"].Value);
                            return(View("~/Views/Home/index.cshtml", model));
                        }
                        model.Email = user.UserName;
                    }
                }
                else
                {
                    user = await SiteConfig.userManager.FindByNameAsync(model.Email);

                    if (user != null)
                    {
                        if (user.isenabled == 0)
                        {
                            // user account is suspeneded
                            ModelState.AddModelError(string.Empty, SiteConfig.generalLocalizer["_account_suspended"].Value);
                            return(View("~/Views/Home/index.cshtml", model));
                        }
                    }
                }

                var result = await _signInManager.PasswordSignInAsync(model.Email, model.Password, model.RememberMe, lockoutOnFailure : false);

                if (result.Succeeded)
                {
                    // Store IP Address Log
                    if (Configs.GeneralSettings.store_ipaddress)
                    {
                        UserLogBLL.Add(_context, user.Id, SiteConfig.HttpContextAccessor.HttpContext.Connection.RemoteIpAddress.ToString());
                    }


                    // Update Last Login Activity
                    UserBLL.Update_Field_Email(_context, model.Email, "last_login", DateTime.Now);

                    // Create User Directory for Media Storage
                    var dirPath = SiteConfig.Environment.ContentRootPath + UtilityBLL.ParseUsername(SystemDirectoryPaths.UserDirectory, model.Email.ToLower().ToString());
                    if (!System.IO.Directory.Exists(dirPath))
                    {
                        Directory_Process.CreateRequiredDirectories(dirPath);
                    }

                    // Subscription Enabled
                    if (!UserPackagesBLL.Check_Package_Feature())        // if packages enabled
                    {
                        if (Configs.PremiumSettings.premium_option == 1) // if membership subscription option is on
                        {
                            int membertype = UserBLL.Get_MemberType(_context, model.Email);
                            if (membertype == 2) // premium member
                            {
                                if (!UserBLL.Check_membership_Status(_context, model.Email))
                                {
                                    // user membership subscription expired.
                                    // i: update user status as normal
                                    UserBLL.Update_Field_Email(_context, model.Email, "type", (byte)0);
                                }
                            }
                        }
                    }

                    if (returnUrl == null || returnUrl == "")
                    {
                        returnUrl = "/account/";
                    }
                    return(Redirect(returnUrl)); // LocalRedirect(returnUrl);
                }
                if (result.RequiresTwoFactor)
                {
                    return(RedirectToAction(nameof(LoginWith2fa), new { returnUrl, model.RememberMe }));
                }
                if (result.IsLockedOut)
                {
                    ViewData["Page"] = "lockout";
                    return(RedirectToAction(nameof(HomeController.Index), "Home"));
                }
                else
                {
                    ModelState.AddModelError(string.Empty, SiteConfig.generalLocalizer["_invalid_login_attempt"].Value);
                    return(View("~/Views/Home/index.cshtml", model));
                }
            }

            return(View(model));
        }