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;
|
||||
|
||||
@ -67,7 +67,7 @@
|
||||
<Property Name="usename" 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>
|
||||
@ -152,7 +152,7 @@
|
||||
<Property Name="usename" 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>
|
||||
|
||||
@ -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; }
|
||||
}
|
||||
}
|
||||
|
||||
@ -2,6 +2,8 @@
|
||||
|
||||
@{
|
||||
ViewBag.Title = "Edituser";
|
||||
var allRoles = "addNews ,newsManagement, userManagment, tag&catManagment".Split(',');
|
||||
var Roles = Model.role.Split(',');
|
||||
}
|
||||
|
||||
<h2>Edituser</h2>
|
||||
@ -9,7 +11,7 @@
|
||||
@using (Html.BeginForm())
|
||||
{
|
||||
@Html.AntiForgeryToken()
|
||||
|
||||
|
||||
<div class="form-horizontal">
|
||||
<h4>user</h4>
|
||||
<hr />
|
||||
@ -28,10 +30,17 @@
|
||||
<div class="form-group">
|
||||
@Html.LabelFor(model => model.role, htmlAttributes: new { @class = "control-label col-md-2" })
|
||||
<div class="col-md-10">
|
||||
<select name="role" class="form-control">
|
||||
<option value="0">User</option>
|
||||
<option value="2">Admin</option>
|
||||
</select>
|
||||
|
||||
@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>
|
||||
|
||||
Reference in New Issue
Block a user