Compare commits
10 Commits
be864f564b
...
4a5bfe58bf
| Author | SHA1 | Date | |
|---|---|---|---|
| 4a5bfe58bf | |||
| eced31d841 | |||
| 4380d9da5c | |||
| d123ce205f | |||
| 4ffc4197aa | |||
| f71b11c131 | |||
| 07ffa3303d | |||
| 936222ab07 | |||
| f5dabbdcd8 | |||
| 0e30088405 |
@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data.Entity;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
using System.Web.Mvc;
|
||||
@ -14,7 +15,7 @@ namespace WebApplication1.Controllers
|
||||
public ActionResult Index()
|
||||
{
|
||||
ViewBag.newsCount = db.news.Count();
|
||||
ViewBag.views = "";
|
||||
ViewBag.views = db.viewlogs.Where(v => DbFunctions.TruncateTime(v.viewdate) == DateTime.Today).Count();
|
||||
setTitle();
|
||||
return View();
|
||||
}
|
||||
|
||||
@ -17,12 +17,24 @@ namespace WebApplication1.Controllers
|
||||
// GET: categories
|
||||
public ActionResult Index()
|
||||
{
|
||||
string userrole = Convert.ToString(Session["Userrole"]);
|
||||
|
||||
if (userrole.Contains("tag&catManagment"))
|
||||
ViewBag.role = 1;
|
||||
else ViewBag.role = 0;
|
||||
return View(db.categories.ToList());
|
||||
}
|
||||
|
||||
// GET: categories/Details/5
|
||||
public ActionResult Details(int? id)
|
||||
{
|
||||
string userrole = Convert.ToString(Session["Userrole"]);
|
||||
|
||||
if (userrole.Contains("tag&catManagment"))
|
||||
ViewBag.role = 1;
|
||||
else ViewBag.role = 0;
|
||||
|
||||
ViewBag.uid = Convert.ToInt32(Session["Userid"]);
|
||||
if (id == null)
|
||||
{
|
||||
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
|
||||
@ -42,7 +54,7 @@ namespace WebApplication1.Controllers
|
||||
{
|
||||
if (Session["User"] != null)
|
||||
{
|
||||
if (Convert.ToInt32(Session["Userrole"]) == 1)
|
||||
if (Convert.ToInt32(Session["Userrole"]) > 0)
|
||||
{
|
||||
return View();
|
||||
}
|
||||
@ -75,6 +87,12 @@ namespace WebApplication1.Controllers
|
||||
|
||||
// GET: categories/Edit/5
|
||||
public ActionResult Edit(int? id)
|
||||
{
|
||||
if (Session["User"] != null)
|
||||
{
|
||||
string userrole = Convert.ToString(Session["Userrole"]);
|
||||
|
||||
if (userrole.Contains("tag&catManagment"))
|
||||
{
|
||||
if (id == null)
|
||||
{
|
||||
@ -87,6 +105,14 @@ namespace WebApplication1.Controllers
|
||||
}
|
||||
return View(category);
|
||||
}
|
||||
else
|
||||
{
|
||||
return new HttpStatusCodeResult(HttpStatusCode.Unauthorized);
|
||||
}
|
||||
}
|
||||
else
|
||||
return RedirectToAction("index", "home");
|
||||
}
|
||||
|
||||
// POST: categories/Edit/5
|
||||
// To protect from overposting attacks, enable the specific properties you want to bind to, for
|
||||
@ -106,6 +132,12 @@ namespace WebApplication1.Controllers
|
||||
|
||||
// GET: categories/Delete/5
|
||||
public ActionResult Delete(int? id)
|
||||
{
|
||||
if (Session["User"] != null)
|
||||
{
|
||||
string userrole = Convert.ToString(Session["Userrole"]);
|
||||
|
||||
if (userrole.Contains("tag&catManagment"))
|
||||
{
|
||||
if (id == null)
|
||||
{
|
||||
@ -118,6 +150,14 @@ namespace WebApplication1.Controllers
|
||||
}
|
||||
return View(category);
|
||||
}
|
||||
else
|
||||
{
|
||||
return new HttpStatusCodeResult(HttpStatusCode.Unauthorized);
|
||||
}
|
||||
}
|
||||
else
|
||||
return RedirectToAction("index", "home");
|
||||
}
|
||||
|
||||
// POST: categories/Delete/5
|
||||
[HttpPost, ActionName("Delete")]
|
||||
|
||||
@ -15,10 +15,26 @@ namespace WebApplication1.Controllers
|
||||
public class newsController : Controller
|
||||
{
|
||||
private newswebappEntities db = new newswebappEntities();
|
||||
public static string GetUserIpAddress(HttpRequestBase request)
|
||||
{
|
||||
string ipAddress = request.ServerVariables["HTTP_X_FORWARDED_FOR"];
|
||||
if (string.IsNullOrEmpty(ipAddress))
|
||||
{
|
||||
ipAddress = request.ServerVariables["REMOTE_ADDR"];
|
||||
}
|
||||
return ipAddress;
|
||||
}
|
||||
|
||||
// GET: news
|
||||
public ActionResult Index()
|
||||
{
|
||||
string userrole = Convert.ToString(Session["Userrole"]);
|
||||
|
||||
if (userrole.Contains("tag&catManagment"))
|
||||
ViewBag.role = 1;
|
||||
else ViewBag.role = 0;
|
||||
|
||||
ViewBag.uid = Convert.ToInt32(Session["Userid"]);
|
||||
var models = (from user in db.users // Access Users DbSet
|
||||
join news in db.news on user.ID equals news.userID into newsGroup // Join News DbSet
|
||||
from news in newsGroup.DefaultIfEmpty() // Left outer join
|
||||
@ -26,6 +42,7 @@ namespace WebApplication1.Controllers
|
||||
select new newsModel
|
||||
{
|
||||
DisplayName = user != null ? user.displayname : null,
|
||||
userID = user != null ? user.ID : 0,
|
||||
NewsID = news.ID, // Use null-conditional operator for missing news
|
||||
Title = news.title,
|
||||
Image = news.image,
|
||||
@ -47,6 +64,9 @@ namespace WebApplication1.Controllers
|
||||
// GET: news/Details/5
|
||||
public ActionResult Details(int? id)
|
||||
{
|
||||
string userrole = Convert.ToString(Session["Userrole"]);
|
||||
ViewBag.role = userrole.Contains("tag&catManagment") ? 1 : 0;
|
||||
|
||||
if (id == null)
|
||||
{
|
||||
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
|
||||
@ -58,36 +78,50 @@ namespace WebApplication1.Controllers
|
||||
}
|
||||
var user = db.users.Find(news.userID);
|
||||
ViewBag.user = user;
|
||||
news.views += 1;
|
||||
db.SaveChanges();
|
||||
/*
|
||||
var key = Request.ServerVariables["REMOTE_ADDR"];
|
||||
var now = DateTime.UtcNow;
|
||||
|
||||
if (now - View.LastVisited > _timeLimit)
|
||||
// Get the user's IP address
|
||||
string userIpAddress = GetUserIpAddress(Request);
|
||||
|
||||
// Check if this IP address has already viewed this article
|
||||
DateTime thresholdDate = DateTime.Now.AddHours(-24);
|
||||
bool hasViewed = db.viewlogs.Any(v => v.newsid == id && v.ipadd == userIpAddress && v.viewdate >= thresholdDate);
|
||||
if (!hasViewed)
|
||||
{
|
||||
pageView.LastVisited = now;
|
||||
_pageViews[key] = pageView;
|
||||
return true; // View counted
|
||||
// Increment the view count
|
||||
news.views++;
|
||||
db.SaveChanges();
|
||||
|
||||
// Log the view
|
||||
db.viewlogs.Add(new viewlog
|
||||
{
|
||||
ipadd = userIpAddress,
|
||||
newsid = news.ID,
|
||||
viewdate = DateTime.Now
|
||||
});
|
||||
db.SaveChanges();
|
||||
}
|
||||
return false; // View within time limit, not counted
|
||||
*/
|
||||
|
||||
if (news.image == null) { news.image = "_"; }
|
||||
return View(news);
|
||||
|
||||
}
|
||||
|
||||
// GET: news/Create
|
||||
public ActionResult Create()
|
||||
{
|
||||
if (Session["User"] != null)
|
||||
{
|
||||
string userrole = Convert.ToString(Session["Userrole"]);
|
||||
|
||||
if (userrole.Contains("addNews"))
|
||||
{
|
||||
setLists();
|
||||
//var models= new Tuple<List<category>, List<tag>>(cat, tags);
|
||||
return View();
|
||||
}
|
||||
if (Session["User"] != null)
|
||||
else
|
||||
{
|
||||
ViewBag.categoryTitle = db.categories.ToList();
|
||||
return View();
|
||||
return new HttpStatusCodeResult(HttpStatusCode.Unauthorized);
|
||||
}
|
||||
}
|
||||
else
|
||||
return RedirectToAction("login", "users");
|
||||
@ -98,7 +132,7 @@ namespace WebApplication1.Controllers
|
||||
// more details see https://go.microsoft.com/fwlink/?LinkId=317598.
|
||||
[HttpPost]
|
||||
[ValidateAntiForgeryToken]
|
||||
public ActionResult Create([Bind(Include = "ID,title,image,link,summary,cat,tag,publishDate,userID,Content,views")] news news)
|
||||
public ActionResult Create([Bind(Include = "ID,title,image,link,summary,cat,tags,publishDate,userID,Content,views")] news news, List<string> Tags, List<string> Cat)
|
||||
{
|
||||
if (ModelState.IsValid)
|
||||
{
|
||||
@ -106,8 +140,31 @@ namespace WebApplication1.Controllers
|
||||
{
|
||||
setLists();
|
||||
|
||||
if (news.title != null && news.link != null && news.cat != null && news.tag != null)
|
||||
if (news.title != null && news.link != null && Cat != null && Tags != null)
|
||||
{
|
||||
|
||||
news.tag = "";
|
||||
foreach (string T in Tags)
|
||||
{
|
||||
if (T != Tags[0])
|
||||
{
|
||||
news.tag += " ,";
|
||||
news.tag += T;
|
||||
}
|
||||
else
|
||||
news.tag += T;
|
||||
}
|
||||
news.cat = "";
|
||||
foreach (string c in Cat)
|
||||
{
|
||||
if (c != Cat[0])
|
||||
{
|
||||
news.cat+= " ,";
|
||||
news.cat += c;
|
||||
}
|
||||
else
|
||||
news.cat += c;
|
||||
}
|
||||
var image = Request.Files[0];
|
||||
if (image.ContentLength > 1024 * 1024)
|
||||
{
|
||||
@ -122,6 +179,9 @@ namespace WebApplication1.Controllers
|
||||
if (!new[] { ".jpg", ".jpeg", ".png" }.Contains(fileExtension))
|
||||
{
|
||||
ModelState.AddModelError("image", "Only JPG, JPEG, and PNG files are allowed.");
|
||||
news.image = "";
|
||||
return View();
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -166,6 +226,11 @@ namespace WebApplication1.Controllers
|
||||
// GET: news/Edit/5
|
||||
public ActionResult Edit(int? id)
|
||||
{
|
||||
if (Session["User"] != null)
|
||||
{
|
||||
string userrole = Convert.ToString(Session["Userrole"]);
|
||||
setLists();
|
||||
|
||||
if (id == null)
|
||||
{
|
||||
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
|
||||
@ -175,19 +240,100 @@ namespace WebApplication1.Controllers
|
||||
{
|
||||
return HttpNotFound();
|
||||
}
|
||||
else if ( news.userID == Convert.ToInt32(Session["Userid"]) || userrole.Contains("newsManagement"))
|
||||
{
|
||||
return View(news);
|
||||
}
|
||||
else
|
||||
return new HttpStatusCodeResult(HttpStatusCode.Unauthorized);
|
||||
|
||||
}
|
||||
else
|
||||
return RedirectToAction("index", "home");
|
||||
|
||||
}
|
||||
|
||||
// POST: news/Edit/5
|
||||
// To protect from overposting attacks, enable the specific properties you want to bind to, for
|
||||
// more details see https://go.microsoft.com/fwlink/?LinkId=317598.
|
||||
[HttpPost]
|
||||
[ValidateAntiForgeryToken]
|
||||
public ActionResult Edit([Bind(Include = "ID,title,image,link,summary,cat,tag,publishDate,userID,Content,views")] news news)
|
||||
public ActionResult Edit([Bind(Include = "ID,title,image,link,summary,cat,tag,publishDate,userID,Content,views")] news news, List<string> Tags, List<string> Cat)
|
||||
{
|
||||
if (ModelState.IsValid)
|
||||
{
|
||||
db.Entry(news).State = EntityState.Modified;
|
||||
|
||||
news.cat = "";
|
||||
if (Tags != null)
|
||||
{
|
||||
news.tag = "";
|
||||
foreach (string T in Tags)
|
||||
{
|
||||
if (T != Tags[0])
|
||||
{
|
||||
news.tag += " ,";
|
||||
news.tag += T;
|
||||
}
|
||||
else
|
||||
news.tag += T;
|
||||
}
|
||||
}
|
||||
if (Cat != null){
|
||||
foreach (string c in Cat)
|
||||
{
|
||||
if (c != Cat[0])
|
||||
{
|
||||
news.cat += " ,";
|
||||
news.cat += c;
|
||||
}
|
||||
else
|
||||
news.cat += c;
|
||||
}
|
||||
}
|
||||
var image = Request.Files[0];
|
||||
if (image.ContentLength > 1024 * 1024)
|
||||
{
|
||||
//check if fields are empty
|
||||
ModelState.AddModelError("imageFile", "File size cannot exceed 1MB.");
|
||||
return RedirectToAction("Index");
|
||||
}
|
||||
|
||||
// Check file extension
|
||||
string fileExtension = Path.GetExtension(image.FileName).ToLower();
|
||||
//if (fileExtension != ".jpg" || fileExtension != ".jpeg" || fileExtension != ".png")
|
||||
if (!new[] { ".jpg", ".jpeg", ".png" }.Contains(fileExtension))
|
||||
{
|
||||
ModelState.AddModelError("image", "Only JPG, JPEG, and PNG files are allowed.");
|
||||
news.image = "";
|
||||
return View();
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
int length = 10; // Desired length of the random string
|
||||
string allowedChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
|
||||
char[] chars = new char[length];
|
||||
Random rand = new Random();
|
||||
string imgname = "";
|
||||
for (int i = 0; i < length; i++)
|
||||
{
|
||||
chars[i] = allowedChars[rand.Next(0, allowedChars.Length)];
|
||||
imgname += "" + chars[i];
|
||||
}
|
||||
var path = $"~/Media/news/" + imgname + fileExtension;
|
||||
image.SaveAs(Server.MapPath(path));
|
||||
news.image = path;
|
||||
}
|
||||
|
||||
//db op
|
||||
var curnews = db.news.Find(news.ID);
|
||||
curnews.title = news.title != null ? news.title : curnews.title;
|
||||
curnews.image = news.image != null ? news.image : curnews.image;
|
||||
curnews.summary = news.summary != null ? news.summary : curnews.summary;
|
||||
curnews.Content = news.Content != null ? news.Content : curnews.Content;
|
||||
curnews.link = news.link != null ? news.link : curnews.link;
|
||||
curnews.tag = news.tag != null ? news.tag : curnews.tag;
|
||||
curnews.cat = news.cat != null ? news.cat : curnews.cat;
|
||||
db.SaveChanges();
|
||||
return RedirectToAction("Index");
|
||||
}
|
||||
@ -196,6 +342,8 @@ namespace WebApplication1.Controllers
|
||||
|
||||
// GET: news/Delete/5
|
||||
public ActionResult Delete(int? id)
|
||||
{
|
||||
if (Session["User"] != null)
|
||||
{
|
||||
if (id == null)
|
||||
{
|
||||
@ -206,8 +354,17 @@ namespace WebApplication1.Controllers
|
||||
{
|
||||
return HttpNotFound();
|
||||
}
|
||||
else if (news.userID == Convert.ToInt32(Session["Userid"]) || Convert.ToInt32(Session["Userrole"]) > 0)
|
||||
{
|
||||
return View(news);
|
||||
}
|
||||
else
|
||||
return new HttpStatusCodeResult(HttpStatusCode.Unauthorized);
|
||||
|
||||
}
|
||||
else
|
||||
return RedirectToAction("index", "home");
|
||||
}
|
||||
|
||||
// POST: news/Delete/5
|
||||
[HttpPost, ActionName("Delete")]
|
||||
|
||||
@ -16,12 +16,25 @@ namespace WebApplication1.Models
|
||||
// GET: tags
|
||||
public ActionResult Index()
|
||||
{
|
||||
string userrole = Convert.ToString(Session["Userrole"]);
|
||||
|
||||
if (userrole.Contains("tag&catManagment"))
|
||||
ViewBag.role = 1;
|
||||
else ViewBag.role = 0;
|
||||
|
||||
return View(db.tags.ToList());
|
||||
}
|
||||
|
||||
// GET: tags/Details/5
|
||||
public ActionResult Details(int? id)
|
||||
{
|
||||
string userrole = Convert.ToString(Session["Userrole"]);
|
||||
|
||||
if (userrole.Contains("tag&catManagment"))
|
||||
ViewBag.role = 1;
|
||||
else ViewBag.role = 0;
|
||||
|
||||
ViewBag.uid = Convert.ToInt32(Session["Userid"]);
|
||||
if (id == null)
|
||||
{
|
||||
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
|
||||
@ -41,7 +54,9 @@ namespace WebApplication1.Models
|
||||
{
|
||||
if (Session["User"] != null)
|
||||
{
|
||||
if (Convert.ToInt32(Session["Userrole"]) == 1)
|
||||
string userrole = Convert.ToString(Session["Userrole"]);
|
||||
|
||||
if (userrole.Contains("tag&catManagment"))
|
||||
{
|
||||
return View();
|
||||
}
|
||||
@ -74,17 +89,31 @@ namespace WebApplication1.Models
|
||||
|
||||
// GET: tags/Edit/5
|
||||
public ActionResult Edit(int? id)
|
||||
{
|
||||
if (Session["User"] != null)
|
||||
{
|
||||
string userrole = Convert.ToString(Session["Userrole"]);
|
||||
|
||||
if (userrole.Contains("tag&catManagment"))
|
||||
{
|
||||
if (id == null)
|
||||
{
|
||||
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
|
||||
}
|
||||
tag tag = db.tags.Find(id);
|
||||
if (tag == null)
|
||||
tag tags = db.tags.Find(id);
|
||||
if (tags == null)
|
||||
{
|
||||
return HttpNotFound();
|
||||
}
|
||||
return View(tag);
|
||||
return View(tags);
|
||||
}
|
||||
else
|
||||
{
|
||||
return new HttpStatusCodeResult(HttpStatusCode.Unauthorized);
|
||||
}
|
||||
}
|
||||
else
|
||||
return RedirectToAction("index", "home");
|
||||
}
|
||||
|
||||
// POST: tags/Edit/5
|
||||
@ -105,17 +134,31 @@ namespace WebApplication1.Models
|
||||
|
||||
// GET: tags/Delete/5
|
||||
public ActionResult Delete(int? id)
|
||||
{
|
||||
if (Session["User"] != null)
|
||||
{
|
||||
string userrole = Convert.ToString(Session["Userrole"]);
|
||||
|
||||
if (userrole.Contains("tag&catManagment"))
|
||||
{
|
||||
if (id == null)
|
||||
{
|
||||
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
|
||||
}
|
||||
tag tag = db.tags.Find(id);
|
||||
if (tag == null)
|
||||
tag tags = db.tags.Find(id);
|
||||
if (tags == null)
|
||||
{
|
||||
return HttpNotFound();
|
||||
}
|
||||
return View(tag);
|
||||
return View(tags);
|
||||
}
|
||||
else
|
||||
{
|
||||
return new HttpStatusCodeResult(HttpStatusCode.Unauthorized);
|
||||
}
|
||||
}
|
||||
else
|
||||
return RedirectToAction("index", "home");
|
||||
}
|
||||
|
||||
// POST: tags/Delete/5
|
||||
|
||||
@ -7,6 +7,9 @@ using System.Net;
|
||||
using System.Web;
|
||||
using System.Web.Mvc;
|
||||
using WebApplication1.Models;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
using System.Web.UI.WebControls;
|
||||
|
||||
namespace WebApplication1.Controllers
|
||||
{
|
||||
@ -14,9 +17,98 @@ namespace WebApplication1.Controllers
|
||||
{
|
||||
private newswebappEntities db = new newswebappEntities();
|
||||
|
||||
private int ValidatePassword(string password, string confirmPassword)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(password))
|
||||
{
|
||||
ModelState.AddModelError("", "Password cannot be empty");
|
||||
return 1;
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
if (password != confirmPassword)
|
||||
{
|
||||
ModelState.AddModelError("", "Passwords don't match");
|
||||
return 1;
|
||||
|
||||
}
|
||||
|
||||
if (password.Length < 8)
|
||||
{
|
||||
ModelState.AddModelError("", "Password must be at least 8 characters long");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (!password.Any(char.IsUpper))
|
||||
{
|
||||
ModelState.AddModelError("", "Password must contain at least one uppercase letter");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (!password.Any(char.IsLower))
|
||||
{
|
||||
ModelState.AddModelError("", "Password must contain at least one lowercase letter");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (!password.Any(char.IsDigit))
|
||||
{
|
||||
ModelState.AddModelError("", "Password must contain at least one digit");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (!password.Any(ch => !char.IsLetterOrDigit(ch)))
|
||||
{
|
||||
ModelState.AddModelError("", "Password must contain at least one special character");
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
private int ValidateUsername(string username)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(username))
|
||||
{
|
||||
ModelState.AddModelError("", "Username cannot be empty");
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (username.Length < 3)
|
||||
{
|
||||
ModelState.AddModelError("", "Username must be at least 3 characters long");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (username.Length > 20)
|
||||
{
|
||||
ModelState.AddModelError("", "Username must not exceed 20 characters");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (!username.All(char.IsLetterOrDigit))
|
||||
{
|
||||
ModelState.AddModelError("", "Username can only contain letters and digits");
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
// GET: users
|
||||
public ActionResult Index()
|
||||
{ if (Convert.ToInt32(Session["Userrole"]) > 0)
|
||||
public ActionResult Index() {
|
||||
|
||||
string userrole = Convert.ToString(Session["Userrole"]);
|
||||
if (userrole.Contains("addNews"))
|
||||
{
|
||||
@ViewBag.role = "jornalist";
|
||||
}
|
||||
if (userrole.Contains("newsManagement") || userrole.Contains("tag&catManagment") )
|
||||
{
|
||||
@ViewBag.role = "admin";
|
||||
}
|
||||
@ -46,7 +138,8 @@ namespace WebApplication1.Controllers
|
||||
{
|
||||
if (Session["User"] != null)
|
||||
{
|
||||
if (Convert.ToInt32(Session["Userrole"]) == 1)
|
||||
string userrole = Convert.ToString(Session["Userrole"]);
|
||||
if (userrole.Contains("userManagment"))
|
||||
{
|
||||
return View(db.users.ToList());
|
||||
}
|
||||
@ -75,12 +168,20 @@ namespace WebApplication1.Controllers
|
||||
{
|
||||
if (ModelState.IsValid)
|
||||
{
|
||||
|
||||
var cpass = Request.Form["ConfirmPassword"];
|
||||
var valpass = ValidatePassword(user.password, cpass);
|
||||
var valuser = ValidateUsername(user.usename);
|
||||
if (valpass == 1 || valuser == 1)
|
||||
{
|
||||
return View();
|
||||
}
|
||||
//check if the username exists
|
||||
var check = db.users.FirstOrDefault(u => u.usename == user.usename);
|
||||
//checks username and password field in form
|
||||
if (user.usename != null && user.password != null)
|
||||
{
|
||||
user.role = "none";
|
||||
|
||||
if (check != null)
|
||||
{
|
||||
ModelState.AddModelError("", " username already exists");
|
||||
@ -88,6 +189,15 @@ namespace WebApplication1.Controllers
|
||||
//if username is valid create user add to db
|
||||
else
|
||||
{
|
||||
// Hash the password
|
||||
using (var sha256 = SHA256.Create())
|
||||
{
|
||||
var hashedBytes = sha256.ComputeHash(Encoding.UTF8.GetBytes(user.password));
|
||||
user.password = BitConverter.ToString(hashedBytes).Replace("-", "").ToLower();
|
||||
}
|
||||
|
||||
|
||||
|
||||
db.users.Add(user);
|
||||
db.SaveChanges();
|
||||
|
||||
@ -99,11 +209,6 @@ namespace WebApplication1.Controllers
|
||||
return RedirectToAction("Index");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ModelState.AddModelError("",
|
||||
"username and password field can not be empty");
|
||||
}
|
||||
}
|
||||
return View(user);
|
||||
}
|
||||
@ -134,6 +239,11 @@ namespace WebApplication1.Controllers
|
||||
{
|
||||
//check if user exists
|
||||
var existingUser = db.users.FirstOrDefault(u => u.usename == user.usename );
|
||||
using (var sha256 = SHA256.Create())
|
||||
{
|
||||
var hashedBytes = sha256.ComputeHash(Encoding.UTF8.GetBytes(user.password));
|
||||
user.password = BitConverter.ToString(hashedBytes).Replace("-", "").ToLower();
|
||||
}
|
||||
if (existingUser != null && existingUser.password == user.password)
|
||||
{
|
||||
//session start
|
||||
@ -182,13 +292,83 @@ namespace WebApplication1.Controllers
|
||||
{
|
||||
if (ModelState.IsValid)
|
||||
{
|
||||
db.Entry(user).State = EntityState.Modified;
|
||||
var u = db.users.Find(user.ID);
|
||||
|
||||
if (user.password != null){
|
||||
// Hash the password
|
||||
using (var sha256 = SHA256.Create())
|
||||
{
|
||||
var hashedBytes = sha256.ComputeHash(Encoding.UTF8.GetBytes(user.password));
|
||||
user.password = BitConverter.ToString(hashedBytes).Replace("-", "").ToLower();
|
||||
u.password = user.password;
|
||||
}
|
||||
}
|
||||
|
||||
u.displayname = user.displayname;
|
||||
|
||||
db.SaveChanges();
|
||||
return RedirectToAction("Index");
|
||||
}
|
||||
return View(user);
|
||||
}
|
||||
|
||||
public ActionResult Edituser(int? id)
|
||||
{
|
||||
if (Session["User"] != null)
|
||||
{
|
||||
string userrole = Convert.ToString(Session["Userrole"]);
|
||||
|
||||
if (userrole.Contains("userManagment"))
|
||||
{
|
||||
|
||||
if (id == null)
|
||||
{
|
||||
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
|
||||
}
|
||||
user user = db.users.Find(id);
|
||||
if (user == null)
|
||||
{
|
||||
return HttpNotFound();
|
||||
}
|
||||
return View(user);
|
||||
}
|
||||
else
|
||||
return new HttpStatusCodeResult(HttpStatusCode.Unauthorized);
|
||||
|
||||
}
|
||||
else
|
||||
return RedirectToAction("Login");
|
||||
}
|
||||
|
||||
|
||||
// POST: tickets/Edit/5
|
||||
// To protect from overposting attacks, enable the specific properties you want to bind to, for
|
||||
// more details see https://go.microsoft.com/fwlink/?LinkId=317598.
|
||||
[HttpPost]
|
||||
[ValidateAntiForgeryToken]
|
||||
public ActionResult Edituser([Bind(Include = "ID,usename,password,displayname,role")] user user, List<string> roles)
|
||||
{
|
||||
if (ModelState.IsValid)
|
||||
{
|
||||
user.role = "";
|
||||
foreach (string r in roles)
|
||||
{
|
||||
if (r != roles[0])
|
||||
{
|
||||
user.role += ",";
|
||||
user.role += r;
|
||||
}
|
||||
else
|
||||
user.role += r;
|
||||
}
|
||||
var currentuser = db.users.Find(user.ID);
|
||||
currentuser.displayname = user.displayname;
|
||||
currentuser.role = user.role;
|
||||
db.SaveChanges();
|
||||
return RedirectToAction("Index");
|
||||
}
|
||||
return View(user);
|
||||
}
|
||||
|
||||
|
||||
// GET: users/Delete/5
|
||||
|
||||
BIN
Media/news/32wiF8mzgi.jpg
Normal file
|
After Width: | Height: | Size: 98 KiB |
BIN
Media/news/5RCYg4F954.jpg
Normal file
|
After Width: | Height: | Size: 98 KiB |
BIN
Media/news/AnaSQwnOHg.jpg
Normal file
|
After Width: | Height: | Size: 98 KiB |
BIN
Media/news/DhunrFmH5e.jpg
Normal file
|
After Width: | Height: | Size: 98 KiB |
BIN
Media/news/YoUypscYRW.jpg
Normal file
|
After Width: | Height: | Size: 98 KiB |
BIN
Media/news/i08QfDIQ70.jpg
Normal file
|
After Width: | Height: | Size: 98 KiB |
BIN
Media/news/kgeN7kkWJ0.jpg
Normal file
|
After Width: | Height: | Size: 297 KiB |
BIN
Media/news/kmcZj0sRbt.jpg
Normal file
|
After Width: | Height: | Size: 297 KiB |
BIN
Media/news/orYf1iXWSH.jpg
Normal file
|
After Width: | Height: | Size: 98 KiB |
BIN
Media/news/rQISg2NRaA.jpg
Normal file
|
After Width: | Height: | Size: 98 KiB |
BIN
Media/news/zF9LapiTFm.jpg
Normal file
|
After Width: | Height: | Size: 98 KiB |
@ -31,5 +31,6 @@ namespace WebApplication1.Models
|
||||
public virtual DbSet<ticket> tickets { get; set; }
|
||||
public virtual DbSet<user> users { get; set; }
|
||||
public virtual DbSet<response> responses { get; set; }
|
||||
public virtual DbSet<viewlog> viewlogs { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@ -65,9 +65,18 @@
|
||||
</Key>
|
||||
<Property Name="ID" Type="int" StoreGeneratedPattern="Identity" Nullable="false" />
|
||||
<Property Name="usename" Type="nvarchar" MaxLength="50" Nullable="false" />
|
||||
<Property Name="password" Type="nvarchar" MaxLength="50" Nullable="false" />
|
||||
<Property Name="password" Type="nvarchar(max)" Nullable="false" />
|
||||
<Property Name="displayname" Type="nvarchar" MaxLength="50" />
|
||||
<Property Name="role" Type="int" Nullable="false" />
|
||||
<Property Name="role" Type="nvarchar" MaxLength="70" Nullable="false" />
|
||||
</EntityType>
|
||||
<EntityType Name="viewlog">
|
||||
<Key>
|
||||
<PropertyRef Name="ID" />
|
||||
</Key>
|
||||
<Property Name="ID" Type="int" StoreGeneratedPattern="Identity" Nullable="false" />
|
||||
<Property Name="ipadd" Type="nvarchar(max)" />
|
||||
<Property Name="newsid" Type="int" />
|
||||
<Property Name="viewdate" Type="datetime" />
|
||||
</EntityType>
|
||||
<EntityContainer Name="newswebappModelStoreContainer">
|
||||
<EntitySet Name="category" EntityType="Self.category" Schema="dbo" store:Type="Tables" />
|
||||
@ -76,6 +85,7 @@
|
||||
<EntitySet Name="tag" EntityType="Self.tag" Schema="dbo" store:Type="Tables" />
|
||||
<EntitySet Name="ticket" EntityType="Self.ticket" Schema="dbo" store:Type="Tables" />
|
||||
<EntitySet Name="user" EntityType="Self.user" Schema="dbo" store:Type="Tables" />
|
||||
<EntitySet Name="viewlog" EntityType="Self.viewlog" Schema="dbo" store:Type="Tables" />
|
||||
</EntityContainer>
|
||||
</Schema></edmx:StorageModels>
|
||||
<!-- CSDL content -->
|
||||
@ -88,6 +98,7 @@
|
||||
<EntitySet Name="tickets" EntityType="newswebappModel.ticket" />
|
||||
<EntitySet Name="users" EntityType="newswebappModel.user" />
|
||||
<EntitySet Name="responses" EntityType="newswebappModel.response" />
|
||||
<EntitySet Name="viewlogs" EntityType="newswebappModel.viewlog" />
|
||||
</EntityContainer>
|
||||
<EntityType Name="category">
|
||||
<Key>
|
||||
@ -139,9 +150,9 @@
|
||||
</Key>
|
||||
<Property Name="ID" Type="Int32" Nullable="false" annotation:StoreGeneratedPattern="Identity" />
|
||||
<Property Name="usename" Type="String" Nullable="false" MaxLength="50" FixedLength="false" Unicode="true" />
|
||||
<Property Name="password" Type="String" Nullable="false" MaxLength="50" FixedLength="false" Unicode="true" />
|
||||
<Property Name="password" Type="String" Nullable="false" MaxLength="Max" FixedLength="false" Unicode="true" />
|
||||
<Property Name="displayname" Type="String" MaxLength="50" FixedLength="false" Unicode="true" />
|
||||
<Property Name="role" Type="Int32" Nullable="false" />
|
||||
<Property Name="role" Type="String" Nullable="false" />
|
||||
</EntityType>
|
||||
<EntityType Name="response">
|
||||
<Key>
|
||||
@ -153,6 +164,15 @@
|
||||
<Property Name="adminid" Type="Int32" />
|
||||
<Property Name="ticketid" Type="Int32" />
|
||||
</EntityType>
|
||||
<EntityType Name="viewlog">
|
||||
<Key>
|
||||
<PropertyRef Name="ID" />
|
||||
</Key>
|
||||
<Property Name="ID" Type="Int32" Nullable="false" annotation:StoreGeneratedPattern="Identity" />
|
||||
<Property Name="ipadd" Type="String" MaxLength="Max" FixedLength="false" Unicode="true" />
|
||||
<Property Name="newsid" Type="Int32" />
|
||||
<Property Name="viewdate" Type="DateTime" Precision="3" />
|
||||
</EntityType>
|
||||
</Schema>
|
||||
</edmx:ConceptualModels>
|
||||
<!-- C-S mapping content -->
|
||||
@ -229,6 +249,16 @@
|
||||
</MappingFragment>
|
||||
</EntityTypeMapping>
|
||||
</EntitySetMapping>
|
||||
<EntitySetMapping Name="viewlogs">
|
||||
<EntityTypeMapping TypeName="newswebappModel.viewlog">
|
||||
<MappingFragment StoreEntitySet="viewlog">
|
||||
<ScalarProperty Name="viewdate" ColumnName="viewdate" />
|
||||
<ScalarProperty Name="newsid" ColumnName="newsid" />
|
||||
<ScalarProperty Name="ipadd" ColumnName="ipadd" />
|
||||
<ScalarProperty Name="ID" ColumnName="ID" />
|
||||
</MappingFragment>
|
||||
</EntityTypeMapping>
|
||||
</EntitySetMapping>
|
||||
</EntityContainerMapping>
|
||||
</Mapping>
|
||||
</edmx:Mappings>
|
||||
|
||||
@ -11,6 +11,7 @@
|
||||
<EntityTypeShape EntityType="newswebappModel.ticket" Width="1.5" PointX="0.75" PointY="4.75" />
|
||||
<EntityTypeShape EntityType="newswebappModel.user" Width="1.5" PointX="2.75" PointY="4.75" />
|
||||
<EntityTypeShape EntityType="newswebappModel.response" Width="1.5" PointX="4.75" PointY="4.625" />
|
||||
<EntityTypeShape EntityType="newswebappModel.viewlog" Width="1.5" PointX="3.25" PointY="7.25" />
|
||||
</Diagram>
|
||||
</edmx:Diagrams>
|
||||
</edmx:Designer>
|
||||
|
||||
@ -9,6 +9,7 @@ namespace WebApplication1.Models
|
||||
{
|
||||
public string DisplayName { get; set; }
|
||||
public int NewsID { get; set; }
|
||||
public int userID { get; set; }
|
||||
public string Title { get; set; }
|
||||
public string Image { get; set; }
|
||||
public string category { get; set; }
|
||||
|
||||
@ -18,6 +18,6 @@ namespace WebApplication1.Models
|
||||
public string usename { get; set; }
|
||||
public string password { get; set; }
|
||||
public string displayname { get; set; }
|
||||
public int role { get; set; }
|
||||
public string role { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
22
Models/viewlog.cs
Normal file
@ -0,0 +1,22 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <auto-generated>
|
||||
// This code was generated from a template.
|
||||
//
|
||||
// Manual changes to this file may cause unexpected behavior in your application.
|
||||
// Manual changes to this file will be overwritten if the code is regenerated.
|
||||
// </auto-generated>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace WebApplication1.Models
|
||||
{
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
public partial class viewlog
|
||||
{
|
||||
public int ID { get; set; }
|
||||
public string ipadd { get; set; }
|
||||
public Nullable<int> newsid { get; set; }
|
||||
public Nullable<System.DateTime> viewdate { get; set; }
|
||||
}
|
||||
}
|
||||
@ -19,15 +19,13 @@
|
||||
<a class="btn btn-outline-dark" href="/news"> Start Reading »</a>
|
||||
</p>
|
||||
</section>
|
||||
<section class="col-md-4" aria-labelledby="librariesTitle">
|
||||
<h2 id="librariesTitle">Get more libraries</h2>
|
||||
<p>NuGet is a free Visual Studio extension that makes it easy to add, remove, and update libraries and tools in Visual Studio projects.</p>
|
||||
<p><a class="btn btn-outline-dark" href="https://go.microsoft.com/fwlink/?LinkId=301866">Learn more »</a></p>
|
||||
</section>
|
||||
<section class="col-md-4" aria-labelledby="hostingTitle">
|
||||
<h2 id="hostingTitle">Web Hosting</h2>
|
||||
<p>You can easily find a web hosting company that offers the right mix of features and price for your applications.</p>
|
||||
<p><a class="btn btn-outline-dark" href="https://go.microsoft.com/fwlink/?LinkId=301867">Learn more »</a></p>
|
||||
<section class="col-md-4" aria-labelledby="viewcount">
|
||||
<h2 id="viewcount">View count</h2>
|
||||
<p>
|
||||
@ViewBag.views
|
||||
</p>
|
||||
<p>
|
||||
<a class="btn btn-outline-dark" href="/news"> Start Reading »</a></p>
|
||||
</section>
|
||||
</div>
|
||||
</main>
|
||||
@ -11,9 +11,6 @@
|
||||
<th>
|
||||
@Html.DisplayNameFor(model => model.title)
|
||||
</th>
|
||||
<th>
|
||||
@Html.DisplayNameFor(model => model.link)
|
||||
</th>
|
||||
<th>
|
||||
@Html.DisplayNameFor(model => model.tag)
|
||||
</th>
|
||||
@ -29,9 +26,6 @@
|
||||
<td>
|
||||
@Html.DisplayFor(modelItem => item.title)
|
||||
</td>
|
||||
<td>
|
||||
@Html.DisplayFor(modelItem => item.link)
|
||||
</td>
|
||||
<td>
|
||||
@Html.DisplayFor(modelItem => item.tag)
|
||||
</td>
|
||||
@ -39,9 +33,14 @@
|
||||
@Html.DisplayFor(modelItem => item.cat)
|
||||
</td>
|
||||
<td>
|
||||
@Html.ActionLink("Edit", "Edit", new { id = item.ID }) |
|
||||
@Html.ActionLink("Details", "Details", new { id = item.ID }) |
|
||||
@Html.ActionLink("Delete", "Delete", new { id = item.ID })
|
||||
@Html.ActionLink("Read", "../news/Details", new { id = item.ID })|
|
||||
@if (ViewBag.role > 0 || ViewBag.uid == item.userID)
|
||||
{
|
||||
|
||||
@Html.ActionLink("Edit", "../news/Edit", new { id = item.ID })
|
||||
<span>|</span>
|
||||
@Html.ActionLink("Delete", "../news/Delete", new { id = item.ID })
|
||||
}
|
||||
</td>
|
||||
</tr>
|
||||
}
|
||||
|
||||
@ -29,9 +29,15 @@
|
||||
@Html.DisplayFor(modelItem => item.title)
|
||||
</td>
|
||||
<td>
|
||||
@Html.ActionLink("Edit", "Edit", new { id=item.ID }) |
|
||||
|
||||
@Html.ActionLink("Details", "Details", new { id = item.ID }) |
|
||||
@if (ViewBag.role > 0)
|
||||
{
|
||||
@Html.ActionLink("Edit", "Edit", new { id = item.ID })
|
||||
<span>|</span>
|
||||
@Html.ActionLink("Delete", "Delete", new { id = item.ID })
|
||||
|
||||
}
|
||||
</td>
|
||||
</tr>
|
||||
}
|
||||
|
||||
@ -41,7 +41,7 @@
|
||||
<div class="form-group">
|
||||
<label class="control-label col-md-2">category</label>
|
||||
<div>
|
||||
<select id="cat" name="cat" class="form-control" multiple>
|
||||
<select id="cat" name="Cat" class="form-control" multiple>
|
||||
@foreach (var item in ViewBag.categoryTitle)
|
||||
{
|
||||
<option value="@item.title">@item.title</option>
|
||||
@ -54,7 +54,7 @@
|
||||
<div class="form-group">
|
||||
@Html.LabelFor(model => model.tag, htmlAttributes: new { @class = "control-label col-md-2" })
|
||||
<div class="col-md-10">
|
||||
<select id="tag" name="tag" class="form-control" multiple>
|
||||
<select id="tag" name="Tags" class="form-control" multiple>
|
||||
@foreach (var item in ViewBag.tagTitle)
|
||||
{
|
||||
<option value="@item.title">@item.title</option>
|
||||
|
||||
@ -24,7 +24,7 @@
|
||||
</dt>
|
||||
|
||||
<dd>
|
||||
<img src="@Url.Content(Model.image)" height="270" width="200" />
|
||||
<img src="@Url.Content(Model.image)" alt="@Model.title" height="270" width="200" />
|
||||
</dd>
|
||||
|
||||
<dt>
|
||||
@ -94,6 +94,12 @@
|
||||
</dl>
|
||||
</div>
|
||||
<p>
|
||||
@Html.ActionLink("Edit", "Edit", new { id = Model.ID }) |
|
||||
@if (@ViewBag.role == 1)
|
||||
{
|
||||
@Html.ActionLink("Edit", "Edit", new { id = Model.ID })
|
||||
<span>
|
||||
|
|
||||
</span>
|
||||
}
|
||||
@Html.ActionLink("Back to List", "Index")
|
||||
</p>
|
||||
|
||||
@ -6,15 +6,14 @@
|
||||
|
||||
<h2>Edit</h2>
|
||||
|
||||
@using (Html.BeginForm())
|
||||
@using (Html.BeginForm("Edit", "news", FormMethod.Post, new { enctype = "multipart/form-data" }))
|
||||
{
|
||||
@Html.AntiForgeryToken()
|
||||
|
||||
<div class="form-horizontal">
|
||||
<div class="form">
|
||||
<h4>news</h4>
|
||||
<hr />
|
||||
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
|
||||
@Html.HiddenFor(model => model.ID)
|
||||
|
||||
<div class="form-group">
|
||||
@Html.LabelFor(model => model.title, htmlAttributes: new { @class = "control-label col-md-2" })
|
||||
@ -24,14 +23,6 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
@Html.LabelFor(model => model.image, htmlAttributes: new { @class = "control-label col-md-2" })
|
||||
<div class="col-md-10">
|
||||
@Html.EditorFor(model => model.image, new { htmlAttributes = new { @class = "form-control" } })
|
||||
@Html.ValidationMessageFor(model => model.image, "", new { @class = "text-danger" })
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
@Html.LabelFor(model => model.link, htmlAttributes: new { @class = "control-label col-md-2" })
|
||||
<div class="col-md-10">
|
||||
@ -41,17 +32,21 @@
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
@Html.LabelFor(model => model.summary, htmlAttributes: new { @class = "control-label col-md-2" })
|
||||
@Html.LabelFor(model => model.image, htmlAttributes: new { @class = "control-label col-md-2" })
|
||||
<div class="col-md-10">
|
||||
@Html.EditorFor(model => model.summary, new { htmlAttributes = new { @class = "form-control" } })
|
||||
@Html.ValidationMessageFor(model => model.summary, "", new { @class = "text-danger" })
|
||||
@Html.EditorFor(model => model.image, new { htmlAttributes = new { @type = "file", @class = "form-control" } })
|
||||
@Html.ValidationMessageFor(model => model.image, "", new { @class = "text-danger" })
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
@Html.LabelFor(model => model.cat, htmlAttributes: new { @class = "control-label col-md-2" })
|
||||
<div class="col-md-10">
|
||||
@Html.EditorFor(model => model.cat, new { htmlAttributes = new { @class = "form-control" } })
|
||||
<label class="control-label col-md-2">category</label>
|
||||
<div>
|
||||
<select id="cat" name="Cat" class="form-control" multiple>
|
||||
@foreach (var item in ViewBag.categoryTitle)
|
||||
{
|
||||
<option value="@item.title">@item.title</option>
|
||||
}
|
||||
</select>
|
||||
@Html.ValidationMessageFor(model => model.cat, "", new { @class = "text-danger" })
|
||||
</div>
|
||||
</div>
|
||||
@ -59,46 +54,35 @@
|
||||
<div class="form-group">
|
||||
@Html.LabelFor(model => model.tag, htmlAttributes: new { @class = "control-label col-md-2" })
|
||||
<div class="col-md-10">
|
||||
@Html.EditorFor(model => model.tag, new { htmlAttributes = new { @class = "form-control" } })
|
||||
<select id="tag" name="Tags" class="form-control" multiple>
|
||||
@foreach (var item in ViewBag.tagTitle)
|
||||
{
|
||||
<option value="@item.title">@item.title</option>
|
||||
}
|
||||
</select>
|
||||
@Html.ValidationMessageFor(model => model.tag, "", new { @class = "text-danger" })
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
@Html.LabelFor(model => model.publishDate, htmlAttributes: new { @class = "control-label col-md-2" })
|
||||
@Html.LabelFor(model => model.summary, htmlAttributes: new { @class = "control-label col-md-2" })
|
||||
<div class="col-md-10">
|
||||
@Html.EditorFor(model => model.publishDate, new { htmlAttributes = new { @class = "form-control" } })
|
||||
@Html.ValidationMessageFor(model => model.publishDate, "", new { @class = "text-danger" })
|
||||
@Html.TextAreaFor(model => model.summary, new { @class = "form-control" })
|
||||
@Html.ValidationMessageFor(model => model.summary, "", new { @class = "text-danger" })
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
@Html.LabelFor(model => model.userID, htmlAttributes: new { @class = "control-label col-md-2" })
|
||||
<div class="col-md-10">
|
||||
@Html.EditorFor(model => model.userID, new { htmlAttributes = new { @class = "form-control" } })
|
||||
@Html.ValidationMessageFor(model => model.userID, "", new { @class = "text-danger" })
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
@Html.LabelFor(model => model.Content, htmlAttributes: new { @class = "control-label col-md-2" })
|
||||
<div class="col-md-10">
|
||||
@Html.EditorFor(model => model.Content, new { htmlAttributes = new { @class = "form-control" } })
|
||||
@Html.TextAreaFor(model => model.Content, new { @class = "form-control" })
|
||||
@Html.ValidationMessageFor(model => model.Content, "", new { @class = "text-danger" })
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
@Html.LabelFor(model => model.views, htmlAttributes: new { @class = "control-label col-md-2" })
|
||||
<div class="col-md-10">
|
||||
@Html.EditorFor(model => model.views, new { htmlAttributes = new { @class = "form-control" } })
|
||||
@Html.ValidationMessageFor(model => model.views, "", new { @class = "text-danger" })
|
||||
</div>
|
||||
</div>
|
||||
<br />
|
||||
|
||||
<div class="form-group">
|
||||
<div class="col-md-offset-2 col-md-10">
|
||||
<input type="submit" value="Save" class="btn btn-default" />
|
||||
<input type="submit" value="Create" class="btn btn-outline-dark" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@ -4,6 +4,7 @@
|
||||
|
||||
@{
|
||||
ViewBag.Title = "Index";
|
||||
|
||||
}
|
||||
|
||||
<h2>Index</h2>
|
||||
@ -56,9 +57,17 @@
|
||||
@Html.DisplayFor(modelItem => item.views)
|
||||
</td>
|
||||
<td>
|
||||
@Html.ActionLink("Edit", "Edit", new { id = item.NewsID }) |
|
||||
@Html.ActionLink("Details", "Details", new { id = item.NewsID }) |
|
||||
|
||||
@Html.ActionLink("Read", "Details", new { id = item.NewsID })|
|
||||
@if (ViewBag.role > 0 || ViewBag.uid == item.userID)
|
||||
{
|
||||
|
||||
@Html.ActionLink("Edit", "Edit", new { id = item.NewsID })
|
||||
<span>|</span>
|
||||
@Html.ActionLink("Delete", "Delete", new { id = item.NewsID })
|
||||
|
||||
}
|
||||
|
||||
</td>
|
||||
</tr>
|
||||
}
|
||||
|
||||
@ -42,9 +42,7 @@
|
||||
@Html.DisplayFor(modelItem => item.views)
|
||||
</td>
|
||||
<td>
|
||||
@Html.ActionLink("Edit", "Edit", new { id = item.ID }) |
|
||||
@Html.ActionLink("Details", "Details", new { id = item.ID }) |
|
||||
@Html.ActionLink("Delete", "Delete", new { id = item.ID })
|
||||
@Html.ActionLink("Details", "Details", new { id = item.ID })
|
||||
</td>
|
||||
</tr>
|
||||
}
|
||||
|
||||
@ -11,9 +11,6 @@
|
||||
<th>
|
||||
@Html.DisplayNameFor(model => model.title)
|
||||
</th>
|
||||
<th>
|
||||
@Html.DisplayNameFor(model => model.link)
|
||||
</th>
|
||||
<th>
|
||||
@Html.DisplayNameFor(model => model.tag)
|
||||
</th>
|
||||
@ -29,9 +26,6 @@
|
||||
<td>
|
||||
@Html.DisplayFor(modelItem => item.title)
|
||||
</td>
|
||||
<td>
|
||||
@Html.DisplayFor(modelItem => item.link)
|
||||
</td>
|
||||
<td>
|
||||
@Html.DisplayFor(modelItem => item.tag)
|
||||
</td>
|
||||
@ -39,9 +33,15 @@
|
||||
@Html.DisplayFor(modelItem => item.cat)
|
||||
</td>
|
||||
<td>
|
||||
@Html.ActionLink("Edit", "Edit", new { id = item.ID }) |
|
||||
@Html.ActionLink("Details", "Details", new { id = item.ID }) |
|
||||
@Html.ActionLink("Delete", "Delete", new { id = item.ID })
|
||||
@Html.ActionLink("Read", "../news/Details", new { id = item.ID })|
|
||||
@if (ViewBag.role > 0 || ViewBag.uid == item.userID)
|
||||
{
|
||||
|
||||
@Html.ActionLink("Edit", "../news/Edit", new { id = item.ID })
|
||||
<span>|</span>
|
||||
@Html.ActionLink("Delete", "../news/Delete", new { id = item.ID })
|
||||
|
||||
}
|
||||
</td>
|
||||
</tr>
|
||||
}
|
||||
|
||||
@ -29,9 +29,14 @@
|
||||
@Html.DisplayFor(modelItem => item.title)
|
||||
</td>
|
||||
<td>
|
||||
@Html.ActionLink("Edit", "Edit", new { id=item.code }) |
|
||||
@Html.ActionLink("Details", "Details", new { id = item.code }) |
|
||||
@if (ViewBag.role > 0)
|
||||
{
|
||||
@Html.ActionLink("Edit", "Edit", new { id = item.code })
|
||||
<span>|</span>
|
||||
@Html.ActionLink("Delete", "Delete", new { id = item.code })
|
||||
|
||||
}
|
||||
</td>
|
||||
</tr>
|
||||
}
|
||||
|
||||
@ -27,7 +27,7 @@
|
||||
<div class="form-group">
|
||||
@Html.LabelFor(model => model.password, htmlAttributes: new { @class = "control-label col-md-2" })
|
||||
<div class="col-md-10">
|
||||
@Html.EditorFor(model => model.password, new { htmlAttributes = new { @class = "form-control" } })
|
||||
<input type="password" name="password" class="form-control"/>
|
||||
@Html.ValidationMessageFor(model => model.password, "", new { @class = "text-danger" })
|
||||
</div>
|
||||
</div>
|
||||
|
||||
58
Views/users/Edituser.cshtml
Normal file
@ -0,0 +1,58 @@
|
||||
@model WebApplication1.Models.user
|
||||
|
||||
@{
|
||||
ViewBag.Title = "Edituser";
|
||||
var allRoles = "addNews ,newsManagement, userManagment, tag&catManagment".Split(',');
|
||||
var Roles = Model.role.Split(',');
|
||||
}
|
||||
|
||||
<h2>Edituser</h2>
|
||||
|
||||
@using (Html.BeginForm())
|
||||
{
|
||||
@Html.AntiForgeryToken()
|
||||
|
||||
<div class="form-horizontal">
|
||||
<h4>user</h4>
|
||||
<hr />
|
||||
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
|
||||
@Html.HiddenFor(model => model.ID)
|
||||
|
||||
|
||||
<div class="form-group">
|
||||
@Html.LabelFor(model => model.displayname, htmlAttributes: new { @class = "control-label col-md-2" })
|
||||
<div class="col-md-10">
|
||||
@Html.EditorFor(model => model.displayname, new { htmlAttributes = new { @class = "form-control" } })
|
||||
@Html.ValidationMessageFor(model => model.displayname, "", new { @class = "text-danger" })
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
@Html.LabelFor(model => model.role, htmlAttributes: new { @class = "control-label col-md-2" })
|
||||
<div class="col-md-10">
|
||||
|
||||
@foreach (var r in Roles) { @r}
|
||||
@for (int i = 0; i < allRoles.Length; i++)
|
||||
{
|
||||
var r = allRoles[i];
|
||||
<div class="form-check">
|
||||
<input class="form-check-input" type="checkbox" value="@r" name="roles" id="flexCheckDefault_@i" @(Roles.Contains(r) ? "checked" : "")>
|
||||
<label class="form-check-label" for="flexCheckDefault_@i">@r</label>
|
||||
</div>
|
||||
}
|
||||
|
||||
@Html.ValidationMessageFor(model => model.role, "", new { @class = "text-danger" })
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<div class="col-md-offset-2 col-md-10">
|
||||
<input type="submit" value="Save" class="btn btn-default" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
|
||||
<div>
|
||||
@Html.ActionLink("Back to List", "Index")
|
||||
</div>
|
||||
@ -15,7 +15,7 @@
|
||||
<hr />
|
||||
<dl class="dl-horizontal">
|
||||
<dt>
|
||||
@Html.DisplayNameFor(model => model.usename)
|
||||
Username
|
||||
</dt>
|
||||
|
||||
<dd>
|
||||
@ -23,15 +23,7 @@
|
||||
</dd>
|
||||
|
||||
<dt>
|
||||
@Html.DisplayNameFor(model => model.password)
|
||||
</dt>
|
||||
|
||||
<dd>
|
||||
@Html.DisplayFor(model => model.password)
|
||||
</dd>
|
||||
|
||||
<dt>
|
||||
@Html.DisplayNameFor(model => model.displayname)
|
||||
Display Name
|
||||
</dt>
|
||||
|
||||
<dd>
|
||||
@ -50,11 +42,17 @@
|
||||
@Html.ActionLink("edit account details", "Edit", null, new { @class = "btn btn-outline-dark" })
|
||||
|
||||
@Html.ActionLink("Logout", "LogOut", null, new { @class = "btn btn-outline-dark" })
|
||||
|
||||
@if (@ViewBag.role == "admin")
|
||||
{
|
||||
@Html.ActionLink("Manage users", "allusers", null, new { @class = "btn btn-outline-dark" })
|
||||
}
|
||||
</div>
|
||||
<br />
|
||||
<div class="col-md-offset-2 col-md-10">
|
||||
@Html.ActionLink("Delete Account", "Delete", null, new { @class = "btn btn-outline-dark" })
|
||||
</div>
|
||||
|
||||
</div>
|
||||
}
|
||||
|
||||
|
||||
@ -47,7 +47,7 @@
|
||||
|
||||
<div class="form-group">
|
||||
<label class="control-label col-md-2">Confirm password</label>
|
||||
<input type="password" , id="ConfirmPassword", oninput="checkPasswords()" class="form-control" />
|
||||
<input type="password" name="ConfirmPassword" id="ConfirmPassword" oninput="checkPasswords()" class="form-control" />
|
||||
<span asp-validation-for="ConfirmPassword" class="text-danger"></span>
|
||||
<span id="passwordMismatch" class="text-danger"></span>
|
||||
</div>
|
||||
|
||||
@ -14,9 +14,6 @@
|
||||
<th>
|
||||
@Html.DisplayNameFor(model => model.usename)
|
||||
</th>
|
||||
<th>
|
||||
@Html.DisplayNameFor(model => model.password)
|
||||
</th>
|
||||
<th>
|
||||
@Html.DisplayNameFor(model => model.displayname)
|
||||
</th>
|
||||
@ -28,15 +25,11 @@
|
||||
<td>
|
||||
@Html.DisplayFor(modelItem => item.usename)
|
||||
</td>
|
||||
<td>
|
||||
@Html.DisplayFor(modelItem => item.password)
|
||||
</td>
|
||||
<td>
|
||||
@Html.DisplayFor(modelItem => item.displayname)
|
||||
</td>
|
||||
<td>
|
||||
@Html.ActionLink("Edit", "Edit", new { id=item.ID }) |
|
||||
@Html.ActionLink("Details", "Details", new { id=item.ID }) |
|
||||
@Html.ActionLink("Edit", "Edituser", new { id=item.ID }) |
|
||||
@Html.ActionLink("Delete", "Delete", new { id=item.ID })
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
@ -189,6 +189,9 @@
|
||||
<Compile Include="Models\user.cs">
|
||||
<DependentUpon>Model1.tt</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Models\viewlog.cs">
|
||||
<DependentUpon>Model1.tt</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
@ -292,6 +295,7 @@
|
||||
<Content Include="Views\responses\Respond.cshtml" />
|
||||
<Content Include="Views\responses\Index.cshtml" />
|
||||
<Content Include="Views\responses\test.cshtml" />
|
||||
<Content Include="Views\users\Edituser.cshtml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Folder Include="App_Data\" />
|
||||
|
||||