Пример #1
0
        public ActionResult AddGame(string id)
        {
            SetImageCountToViewBag();
            Game model = new Game();

            ViewBag.User = UserLogic.VerifyUser(AppCookies.getCookie(AppCookies.UserId));
            return(View(model));
        }
Пример #2
0
 public string Upload(HttpPostedFileBase file)
 {
     try
     {
         HttpFileCollection hfc           = System.Web.HttpContext.Current.Request.Files;
         string             userId        = AppCookies.getCookie(AppCookies.UserId);
         string             path          = "~/images/" + userId + "/";
         string             thumbNailPath = "~/thumbnails/" + userId + "/";
         Directory.CreateDirectory(Server.MapPath(path));
         Directory.CreateDirectory(Server.MapPath(thumbNailPath));
         for (int i = 0; i < hfc.Count; i++)
         {
             HttpPostedFile hpf = hfc[i];
             if (hpf.ContentLength > 0)
             {
                 string fileName = "";
                 if (Request.Browser.Browser == "IE")
                 {
                     fileName = Path.GetFileName(hpf.FileName);
                 }
                 else
                 {
                     fileName = hpf.FileName;
                 }
                 if (!(fileName.EndsWith(".jpg", StringComparison.CurrentCultureIgnoreCase) | fileName.EndsWith(".png", StringComparison.CurrentCultureIgnoreCase) | fileName.EndsWith(".gif", StringComparison.CurrentCultureIgnoreCase)))
                 {
                     return("{error: 'File format not supported. Permitted files[.jpg, .png, .gif]'}");
                 }
                 string fullPathWithFileName = path + fileName;
                 string fullThumbNailPath    = thumbNailPath + fileName;
                 int    j = 0;
                 while (System.IO.File.Exists(Server.MapPath(fullPathWithFileName)))
                 {
                     j++;
                     var fileNameWithoutExtension = fileName.Split('.')[0];
                     fileNameWithoutExtension += j == 1 ? j.ToString() : fileNameWithoutExtension.Substring(0, fileNameWithoutExtension.Length - j.ToString().Length) + j.ToString();
                     fullPathWithFileName      = path + fileNameWithoutExtension + "." + fileName.Split('.')[1];
                     fullThumbNailPath         = thumbNailPath + fileNameWithoutExtension + "." + fileName.Split('.')[1];
                 }
                 hpf.SaveAs(Server.MapPath(fullPathWithFileName));
                 GenerateThumbnail(Server.MapPath(fullPathWithFileName), Server.MapPath(fullThumbNailPath));
             }
         }
         return("{}");
     }
     catch (Exception ex)
     {
         return("{error: '" + ex.Message + "'}");
     }
 }
Пример #3
0
        public void SetImageCountToViewBag()
        {
            string userId = AppCookies.getCookie(AppCookies.UserId);
            string path   = "~/images/" + userId + "/";
            var    Images = Directory.EnumerateFiles(Server.MapPath(path), "*.gif").ToList();

            Images.AddRange(Directory.EnumerateFiles(Server.MapPath(path), "*.png").ToList());
            Images.AddRange(Directory.EnumerateFiles(Server.MapPath(path), "*.jpg").ToList());
            Images              = Images.Select(x => x.Replace(Server.MapPath(path), "")).ToList();
            ViewBag.Count       = Images.Count;
            ViewBag.Images      = Images.Take(16).ToList();
            ViewBag.CurrentPage = 1;
            ViewBag.Key         = "";
            ViewBag.UserId      = userId;
        }
Пример #4
0
        public ActionResult Manage(string page, string key)
        {
            key = key ?? "";
            string userId = AppCookies.getCookie(AppCookies.UserId);
            string path   = "~/images/" + userId + "/";
            var    Images = Directory.EnumerateFiles(Server.MapPath(path), "*.gif").ToList();

            Images.AddRange(Directory.EnumerateFiles(Server.MapPath(path), "*.png").ToList());
            Images.AddRange(Directory.EnumerateFiles(Server.MapPath(path), "*.jpg").ToList());
            Images        = Images.Select(x => x.Replace(Server.MapPath(path), "")).Where(x => x.ToLower().Contains(key.ToLower())).ToList();
            ViewBag.Count = Images.Count;
            int skip = Convert.ToInt32(page) <= 0 ? 0 : Convert.ToInt32(page) - 1;

            ViewBag.Images      = Images.Skip(skip * 16).Take(16).ToList();
            ViewBag.CurrentPage = Convert.ToInt32(page);
            ViewBag.Key         = key;
            ViewBag.UserId      = userId;
            return(PartialView("ImageList"));
        }
Пример #5
0
        public ActionResult Delete(string imageToDelete)
        {
            string userId        = AppCookies.getCookie(AppCookies.UserId);
            string path          = "~/images/" + userId + "/" + imageToDelete;
            string thumbnailPath = "~/images/" + userId + "/" + imageToDelete;

            System.IO.File.Delete(Server.MapPath(path));
            System.IO.File.Delete(Server.MapPath(thumbnailPath));

            path = "~/images/" + userId + "/";
            var Images = Directory.EnumerateFiles(Server.MapPath(path), "*.gif").ToList();

            Images.AddRange(Directory.EnumerateFiles(Server.MapPath(path), "*.png").ToList());
            Images.AddRange(Directory.EnumerateFiles(Server.MapPath(path), "*.jpg").ToList());
            Images              = Images.Select(x => x.Replace(Server.MapPath(path), "")).ToList();
            ViewBag.Count       = Images.Count;
            ViewBag.Images      = Images.Take(16).ToList();
            ViewBag.CurrentPage = 1;
            ViewBag.UserId      = userId;
            return(PartialView("ImageList"));
        }
Пример #6
0
        public ActionResult Index()
        {
            string userId = AppCookies.getCookie(AppCookies.UserId);

            if (userId == null)
            {
                return(RedirectToAction("Login"));
            }
            else
            {
                IUser user = UserLogic.VerifyUser(userId);
                if (user != null)
                {
                    ViewBag.User = user;
                    return(View());
                }
                else
                {
                    return(RedirectToAction("Login"));
                }
            }
        }
Пример #7
0
        public ActionResult Register(FormCollection form)
        {
            if (form == null)
            {
                return(View());
            }
            else if (form.AllKeys.Count() < 1)
            {
                return(View());
            }
            else
            {
                if (form.AllKeys.Contains("id_token")) //google sign in
                {
                    HttpClient client        = new HttpClient();
                    string     tokenResponse = client.GetAsync("https://www.googleapis.com/oauth2/v3/tokeninfo?id_token=" + form["id_token"]).Result.Content.ReadAsStringAsync().Result;
                    dynamic    data          = JObject.Parse(tokenResponse);
                    if (data.email_verified == "true")
                    {
                        if (UserLogic.IsRegisteredGoogleUser("google-" + data.sub))
                        {
                            AppCookies.setCookie(AppCookies.UserId, "google-" + data.sub);
                            return(Json(new { action = "/" }));
                        }
                        else
                        {
                            //register new google user
                            GoogleUser user = new GoogleUser();
                            user.DateCreated   = user.DateUpdated = DateTime.Now;
                            user.EmailVerified = true;
                            user.EMail         = form["Email"];
                            user.UserName      = user.Name = form["Name"];
                            user.ImageUrl      = form["ImageURL"];
                            user.GoogleID      = "google-" + data.sub;
                            new GoogleUserDAO().Save(user);
                            AppCookies.setCookie(AppCookies.UserId, "google-" + data.sub);
                            return(Json(new { action = "/" }));
                        }
                    }
                    else
                    {
                        //
                        return(Json(new { action = "", error = "OneDice could not verify your google information" }));
                    }
                }
                else
                {
                    //register new user
                    OneDice.Core.User user = new User();
                    user.DateCreated = user.DateUpdated = DateTime.Now;
                    user.UserName    = user.Name = form["register-username"];
                    user.EMail       = form["register-email"];
                    user.Password    = AppSecurity.SHA1Encrypt(form["register-password"]);
                    var userDao = new UserDAO();
                    userDao.Save(user);

                    AppCookies.setCookie(AppCookies.UserId, userDao.Table.Where(x => x.EMail == user.EMail).FirstOrDefault().ID.ToString());
                    return(Json(new { action = "/" }));
                }
            }
        }
Пример #8
0
 public ActionResult ViewTournaments()
 {
     ViewBag.User = UserLogic.VerifyUser(AppCookies.getCookie(AppCookies.UserId));
     return(View());
 }
Пример #9
0
 public ActionResult Dashboard()
 {
     ViewBag.User = UserLogic.VerifyUser(AppCookies.getCookie(AppCookies.UserId));
     return(View());
 }