public new ActionResult Profile() { Models.User user = new Models.User(); using (var context = new ImgShareDBContext()) { context.ConnectionString = "mongodb://localhost:27017"; context.IsSSLEnabled = true; context.DatabaseName = "imgshare"; context.Connect(); HttpCookie cookie = Request.Cookies.Get("upload_services"); var id = ObjectId.Parse(cookie["id"]); user = context.GetUserById(id); context.Dispose(); } if (user != null) { return(View(user)); } else { return(Content("Profil ne postoji")); } }
public ActionResult Login(string username, string password) { using (var dbContext = new ImgShareDBContext()) { dbContext.ConnectionString = "mongodb://localhost:27017/"; dbContext.DatabaseName = "imgshare"; dbContext.IsSSLEnabled = true; dbContext.Connect(); Models.User u = dbContext.GetUserByUsername(username, password); if (u != null) { HttpCookie cookie = new HttpCookie("upload_services"); cookie["username"] = u.Username; cookie["firstname"] = u.FirstName; cookie["lastname"] = u.LastName; cookie["id"] = u._id.ToString(); cookie.Expires = DateTime.Now.AddDays(1d); Response.Cookies.Add(cookie); dbContext.Dispose(); return(Json(new { isok = true, message = "Successfully logged in!" })); } dbContext.Dispose(); } return(Json(new { isok = false, message = "Incorrect Username/Password!" })); }
public void DeleteAccount(string userid) { using (var dbContext = new ImgShareDBContext()) { dbContext.ConnectionString = "mongodb://localhost:27017"; dbContext.IsSSLEnabled = true; dbContext.DatabaseName = "imgshare"; dbContext.Connect(); dbContext.RemoveAccount(userid); dbContext.Dispose(); } Logout(); }
public void Remove(string _id, string userId) { using (var dbContext = new ImgShareDBContext()) { dbContext.ConnectionString = "mongodb://localhost:27017"; dbContext.IsSSLEnabled = true; dbContext.DatabaseName = "imgshare"; dbContext.Connect(); dbContext.RemoveImage(_id, userId); dbContext.Dispose(); //release the resources used here } Response.Redirect("/User/Profile"); }
public string GetImages() { using (var dbContext = new ImgShareDBContext()) { dbContext.ConnectionString = "mongodb://localhost:27017/"; dbContext.DatabaseName = "imgshare"; dbContext.IsSSLEnabled = true; dbContext.Connect(); var products = dbContext.GetImages(); dbContext.Dispose(); JavaScriptSerializer objSerializer = new JavaScriptSerializer(); return(objSerializer.Serialize(products)); } }
public void Register(string firstname, string lastname, string email, string password, string username) { Models.User user = new Models.User(firstname, lastname, email, username, password); using (var dbContext = new ImgShareDBContext()) { dbContext.ConnectionString = "mongodb://localhost:27017"; dbContext.DatabaseName = "imgshare"; dbContext.IsSSLEnabled = true; dbContext.Connect(); dbContext.InsertUser(user); dbContext.Dispose(); } Login(username, password); Response.Redirect("/"); }
public void UploadImage(HttpPostedFileBase file, string visability) { if (file == null) { Response.Redirect("/Upload"); } else { var fileName = ""; var uploadedFile = Request.Files[0]; fileName = Path.GetFileName(uploadedFile.FileName); using (var DBContext = new ImgShareDBContext()) { DBContext.ConnectionString = "mongodb://localhost:27017"; DBContext.DatabaseName = "imgshare"; DBContext.IsSSLEnabled = true; DBContext.Connect(); Models.Image forUpload = new Models.Image() { _id = ObjectId.GenerateNewId(), Name = Request.Files[0].FileName }; if (Request.Cookies.Count > 0) { if (visability.Equals("private")) { forUpload.Visibility = false; } else { forUpload.Visibility = true; } } else { forUpload.Visibility = true; } using (var binaryReader = new BinaryReader(Request.Files[0].InputStream)) { forUpload.ImgInBytes = binaryReader.ReadBytes(uploadedFile.ContentLength); } if (Request.Cookies.Count > 0) { DBContext.UpdateUserUploads(forUpload, Request.Cookies[0]["username"]); } else { DBContext.UpdateUserUploads(forUpload, String.Empty); } DBContext.Dispose(); //release resources used here } Response.Redirect("/"); } }