add access level
This commit is contained in:
@ -17,14 +17,23 @@ namespace WebApplication1.Controllers
|
||||
// GET: categories
|
||||
public ActionResult Index()
|
||||
{
|
||||
ViewBag.role = Convert.ToInt32(Session["Userrole"]);
|
||||
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)
|
||||
{
|
||||
ViewBag.role = Convert.ToInt32(Session["Userrole"]);
|
||||
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)
|
||||
{
|
||||
@ -81,7 +90,9 @@ namespace WebApplication1.Controllers
|
||||
{
|
||||
if (Session["User"] != null)
|
||||
{
|
||||
if (Convert.ToInt32(Session["Userrole"]) > 0)
|
||||
string userrole = Convert.ToString(Session["Userrole"]);
|
||||
|
||||
if (userrole.Contains("tag&catManagment"))
|
||||
{
|
||||
if (id == null)
|
||||
{
|
||||
@ -124,7 +135,9 @@ namespace WebApplication1.Controllers
|
||||
{
|
||||
if (Session["User"] != null)
|
||||
{
|
||||
if (Convert.ToInt32(Session["Userrole"]) > 0)
|
||||
string userrole = Convert.ToString(Session["Userrole"]);
|
||||
|
||||
if (userrole.Contains("tag&catManagment"))
|
||||
{
|
||||
if (id == null)
|
||||
{
|
||||
|
||||
@ -28,7 +28,12 @@ namespace WebApplication1.Controllers
|
||||
// GET: news
|
||||
public ActionResult Index()
|
||||
{
|
||||
ViewBag.role = Convert.ToInt32(Session["Userrole"]);
|
||||
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
|
||||
@ -103,14 +108,17 @@ namespace WebApplication1.Controllers
|
||||
{
|
||||
if (Session["User"] != null)
|
||||
{
|
||||
setLists();
|
||||
//var models= new Tuple<List<category>, List<tag>>(cat, tags);
|
||||
return View();
|
||||
}
|
||||
if (Session["User"] != null)
|
||||
{
|
||||
ViewBag.categoryTitle = db.categories.ToList();
|
||||
return View();
|
||||
string userrole = Convert.ToString(Session["Userrole"]);
|
||||
|
||||
if (userrole.Contains("addNews"))
|
||||
{
|
||||
ViewBag.categoryTitle = db.categories.ToList();
|
||||
return View();
|
||||
}
|
||||
else
|
||||
{
|
||||
return new HttpStatusCodeResult(HttpStatusCode.Unauthorized);
|
||||
}
|
||||
}
|
||||
else
|
||||
return RedirectToAction("login", "users");
|
||||
@ -128,9 +136,6 @@ namespace WebApplication1.Controllers
|
||||
if (Request.Files.Count > 0)
|
||||
{
|
||||
setLists();
|
||||
|
||||
|
||||
|
||||
|
||||
if (news.title != null && news.link != null && Cat != null && Tags != null)
|
||||
{
|
||||
@ -218,6 +223,8 @@ namespace WebApplication1.Controllers
|
||||
{
|
||||
if (Session["User"] != null)
|
||||
{
|
||||
string userrole = Convert.ToString(Session["Userrole"]);
|
||||
|
||||
|
||||
if (id == null)
|
||||
{
|
||||
@ -228,7 +235,7 @@ namespace WebApplication1.Controllers
|
||||
{
|
||||
return HttpNotFound();
|
||||
}
|
||||
else if ( news.userID == Convert.ToInt32(Session["Userid"]) || Convert.ToInt32(Session["Userrole"]) > 0)
|
||||
else if ( news.userID == Convert.ToInt32(Session["Userid"]) || userrole.Contains("newsManagement"))
|
||||
{
|
||||
return View(news);
|
||||
}
|
||||
@ -273,7 +280,7 @@ namespace WebApplication1.Controllers
|
||||
}
|
||||
else if (news.userID == Convert.ToInt32(Session["Userid"]) || Convert.ToInt32(Session["Userrole"]) > 0)
|
||||
{
|
||||
return View(news);
|
||||
return View(news);
|
||||
}
|
||||
else
|
||||
return new HttpStatusCodeResult(HttpStatusCode.Unauthorized);
|
||||
|
||||
@ -16,14 +16,24 @@ namespace WebApplication1.Models
|
||||
// GET: tags
|
||||
public ActionResult Index()
|
||||
{
|
||||
ViewBag.role = Convert.ToInt32(Session["Userrole"]);
|
||||
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)
|
||||
{
|
||||
ViewBag.role = Convert.ToInt32(Session["Userrole"]);
|
||||
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)
|
||||
{
|
||||
@ -44,7 +54,9 @@ namespace WebApplication1.Models
|
||||
{
|
||||
if (Session["User"] != null)
|
||||
{
|
||||
if (Convert.ToInt32(Session["Userrole"]) > 0)
|
||||
string userrole = Convert.ToString(Session["Userrole"]);
|
||||
|
||||
if (userrole.Contains("tag&catManagment"))
|
||||
{
|
||||
return View();
|
||||
}
|
||||
@ -80,7 +92,9 @@ namespace WebApplication1.Models
|
||||
{
|
||||
if (Session["User"] != null)
|
||||
{
|
||||
if (Convert.ToInt32(Session["Userrole"]) > 0)
|
||||
string userrole = Convert.ToString(Session["Userrole"]);
|
||||
|
||||
if (userrole.Contains("tag&catManagment"))
|
||||
{
|
||||
if (id == null)
|
||||
{
|
||||
@ -123,7 +137,9 @@ namespace WebApplication1.Models
|
||||
{
|
||||
if (Session["User"] != null)
|
||||
{
|
||||
if (Convert.ToInt32(Session["Userrole"]) > 0)
|
||||
string userrole = Convert.ToString(Session["Userrole"]);
|
||||
|
||||
if (userrole.Contains("tag&catManagment"))
|
||||
{
|
||||
if (id == null)
|
||||
{
|
||||
|
||||
@ -85,8 +85,14 @@ namespace WebApplication1.Controllers
|
||||
|
||||
|
||||
// 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";
|
||||
}
|
||||
@ -116,7 +122,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());
|
||||
}
|
||||
@ -152,6 +159,8 @@ namespace WebApplication1.Controllers
|
||||
//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");
|
||||
@ -286,8 +295,9 @@ namespace WebApplication1.Controllers
|
||||
{
|
||||
if (Session["User"] != null)
|
||||
{
|
||||
string userrole = Convert.ToString(Session["Userrole"]);
|
||||
|
||||
if (Convert.ToInt32(Session["Userrole"]) == 1)
|
||||
if (userrole.Contains("userManagment"))
|
||||
{
|
||||
|
||||
if (id == null)
|
||||
@ -306,7 +316,7 @@ namespace WebApplication1.Controllers
|
||||
|
||||
}
|
||||
else
|
||||
return View("Login");
|
||||
return RedirectToAction("Login");
|
||||
}
|
||||
|
||||
|
||||
@ -315,10 +325,21 @@ namespace WebApplication1.Controllers
|
||||
// more details see https://go.microsoft.com/fwlink/?LinkId=317598.
|
||||
[HttpPost]
|
||||
[ValidateAntiForgeryToken]
|
||||
public ActionResult Edituser([Bind(Include = "ID,usename,password,displayname,role")] user user)
|
||||
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;
|
||||
|
||||
Reference in New Issue
Block a user