📄 admincontroller.cs
字号:
// if (!Roles.IsUserInRole(UserName[i], RoleName[i]))
// Roles.AddUserToRole(UserName[i], RoleName[i]);
// }
// else
// {
// if (Roles.IsUserInRole(UserName[i], RoleName[i]))
// Roles.RemoveUserFromRole(UserName[i], RoleName[i]);
// }
// }
// ModelState.AddModelError("_FORM", "修改所属角色的用户成功!");
// ViewData["Data"] = "";
// return View();
//}
#endregion
#region ==========CreateRole==========
[Authorize]
public ActionResult CreateRole()
{
return View();
}
[Authorize]
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult CreateRole(string RoleName)
{
if (Roles.RoleExists(RoleName))
{
ModelState.AddModelError("_FORM", "创建角色失败,此角色已经存在!");
return View();
}
Roles.CreateRole(RoleName);
return RedirectToAction("Empty", new { id = SkyiSite.Tooltip.PassWordHelper.Instance.Encrypt_DES_String("创建角色成功") });
}
#endregion
SkyiSite.Tooltip.PassWordHelper psHelper = SkyiSite.Tooltip.PassWordHelper.Instance;
#region ==========Config==========
[Authorize]
public ActionResult Config()
{
string xmlFile = System.AppDomain.CurrentDomain.BaseDirectory + "Files/Admin/SitConfig.xml";
if (!System.IO.File.Exists(xmlFile))
{
ViewData["SiteConfig"] = GetWebSite();
}
else
{
try
{
DataTable table = new DataTable("xmlTableName");
table.ReadXml(xmlFile);
ViewData["SiteConfig"] = table;
}
catch
{
ViewData["SiteConfig"] = GetWebSite();
}
}
return View();
}
[Authorize]
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Config(bool IsReg, string NoAllowRegInfo, string RegInfo)
{
string xmlFile = System.AppDomain.CurrentDomain.BaseDirectory + "Files/Admin/SitConfig.xml";
if (!System.IO.File.Exists(xmlFile))
{
FileStream fs = System.IO.File.Create(xmlFile);
fs.Flush();
fs.Close();
fs.Dispose();
}
DataTable table = new DataTable("xmlTableName");
table.Columns.Add(new DataColumn("IsReg", typeof(String)));
table.Columns.Add(new DataColumn("NoAllowRegInfo", typeof(String)));
table.Columns.Add(new DataColumn("RegInfo", typeof(String)));
DataRow row = table.NewRow();
row[0] = psHelper.Encrypt_DES_String(IsReg.ToString());
row[1] = psHelper.Encrypt_DES_String(NoAllowRegInfo);
row[2] = psHelper.Encrypt_DES_String(RegInfo);
table.Rows.Add(row);
table.WriteXml(xmlFile, System.Data.XmlWriteMode.WriteSchema);
return RedirectToAction("Empty", new { id = SkyiSite.Tooltip.PassWordHelper.Instance.Encrypt_DES_String("网站配置信息保存成功") });
}
private DataTable GetWebSite()
{
DataTable table = new DataTable("xmlTableName");
table.Columns.Add(new DataColumn("IsReg", typeof(String)));
table.Columns.Add(new DataColumn("NoAllowRegInfo", typeof(String)));
table.Columns.Add(new DataColumn("RegInfo", typeof(String)));
DataRow row = table.NewRow();
row[0] = psHelper.Encrypt_DES_String("True");
row[1] = psHelper.Encrypt_DES_String("");
row[2] = psHelper.Encrypt_DES_String("");
table.Rows.Add(row);
return table;
}
#endregion
#region ==========DeleteRole==========
[Authorize]
public ActionResult DeleteRole(string id)
{
id = SkyiSite.Tooltip.PassWordHelper.Instance.Decrypt_DES_String(id);
string roles = "管理员|vip用户|普通用户";
if (roles.Contains(id.ToLower()))
{
return RedirectToAction("Empty", new { id = SkyiSite.Tooltip.PassWordHelper.Instance.Encrypt_DES_String("不能删除三个内置的角色!") });
}
if (Roles.GetUsersInRole(id).Length > 0)
{
return RedirectToAction("Empty", new { id = SkyiSite.Tooltip.PassWordHelper.Instance.Encrypt_DES_String("有用户属于此角色,不能删除!") });
}
bool isOk = Roles.DeleteRole(id);
if (!isOk)
{
return RedirectToAction("Empty", new { id = SkyiSite.Tooltip.PassWordHelper.Instance.Encrypt_DES_String("删除角色失败") });
}
return RedirectToAction("Empty", new { id = SkyiSite.Tooltip.PassWordHelper.Instance.Encrypt_DES_String("删除角色成功") });
}
#endregion
#region ==========SelectFunctionForRole==========
[Authorize]
public ActionResult SelectFunctionForRole(string id)
{
id = SkyiSite.Tooltip.PassWordHelper.Instance.Decrypt_DES_String(id);
SkyiSite.WebServices.SrvFunction srvFun = new SkyiSite.WebServices.SrvFunction();
ViewData["TreeString"] = srvFun.GetMzTVForRoleName(id);
return View();
}
[Authorize]
public ActionResult SelectFunctionForUser(string id)
{
id = SkyiSite.Tooltip.PassWordHelper.Instance.Decrypt_DES_String(id);
SkyiSite.WebServices.SrvFunction srvFun = new SkyiSite.WebServices.SrvFunction();
ViewData["TreeString"] = srvFun.GetMzTVForUserName(id);
return View();
}
#endregion
#region ==========Empty==========
[Authorize]
public ActionResult Empty(string id)
{
ViewData["Msg"] = SkyiSite.Tooltip.PassWordHelper.Instance.Decrypt_DES_String(id);
return View();
}
#endregion
#region ==========Email==========
[Authorize]
public ActionResult Email()
{
string filePath = System.AppDomain.CurrentDomain.BaseDirectory + "Files/Admin/Email.xml";
ViewData["Email"] = GetEmailInfo(filePath);
return View();
}
private SkyiSite.DBUtility.EmailInfo GetEmailInfo(string filePath)
{
if (!System.IO.File.Exists(filePath))
{
return SkyiSite.DBUtility.Email.Instance.InitializationEmail();
}
return SkyiSite.DBUtility.Email.Instance.ReadEmail(filePath);
}
[Authorize]
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Email(string Email, string Home, string UserName, string PassWord, string SendSuccessMessage, string SendFailMessage)
{
string filePath = System.AppDomain.CurrentDomain.BaseDirectory + "Files/Admin/Email.xml";
SkyiSite.DBUtility.EmailInfo emailInfo = new SkyiSite.DBUtility.EmailInfo(Email, UserName, PassWord, SendSuccessMessage, SendFailMessage, Home);
SkyiSite.DBUtility.Email.Instance.WriteEmail(emailInfo, filePath);
return RedirectToAction("Empty", new { id = SkyiSite.Tooltip.PassWordHelper.Instance.Encrypt_DES_String("Email配置信息保存成功") });
}
#endregion
/*
public ActionResult SelectFunctionForUser()
{
SkyiSite.WebServices.SrvFunction srvFun = new SkyiSite.WebServices.SrvFunction();
ViewData["TreeString"] = srvFun.GetMzTVForUser(Request.QueryString[0]);
return View();
}*/
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -