完成首次运行初始化安装程序
This commit is contained in:
+12
-1
@@ -64,7 +64,18 @@ namespace COMCMS.Common
|
||||
/// <summary>
|
||||
/// 与小程序验签的盐值
|
||||
/// </summary>
|
||||
public static readonly string SIGNSALT = "comcms";// ConfigurationManager.AppSettings["SignSalt"];
|
||||
public static string SIGNSALT
|
||||
{
|
||||
get
|
||||
{
|
||||
string strPrefixKey = Configuration["SystemSetting:SignSalt"];
|
||||
if (string.IsNullOrEmpty(strPrefixKey))
|
||||
{
|
||||
strPrefixKey = "comcms";
|
||||
}
|
||||
return strPrefixKey;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -21,6 +21,13 @@ namespace COMCMS.Web.Areas.AdminCP.Controllers
|
||||
{
|
||||
return Redirect("/AdminCP");
|
||||
}
|
||||
|
||||
bool hasData = AdminMenu.FindCount(null, null, null, 0, 0) > 0;
|
||||
if (!hasData)
|
||||
{
|
||||
return Redirect("/Home/Install");
|
||||
}
|
||||
|
||||
string key = Utils.GetRandomChar(12);
|
||||
SessionHelper.WriteSession("des_key", key);
|
||||
ViewBag.key = key;
|
||||
|
||||
@@ -13,11 +13,11 @@
|
||||
<PackageReference Include="NewLife.XCode" Version="9.16.2020.403" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
|
||||
<PackageReference Include="Senparc.NeuChar" Version="1.2.106" />
|
||||
<PackageReference Include="Senparc.Weixin" Version="6.7.401" />
|
||||
<PackageReference Include="Senparc.Weixin.MP" Version="16.10.402" />
|
||||
<PackageReference Include="Senparc.Weixin" Version="6.7.500" />
|
||||
<PackageReference Include="Senparc.Weixin.MP" Version="16.10.500" />
|
||||
<PackageReference Include="Senparc.Weixin.MP.MvcExtension" Version="4.1.1" />
|
||||
<PackageReference Include="Senparc.Weixin.TenPay" Version="1.5.401" />
|
||||
<PackageReference Include="Senparc.Weixin.WxOpen" Version="3.8.401" />
|
||||
<PackageReference Include="Senparc.Weixin.TenPay" Version="1.5.500" />
|
||||
<PackageReference Include="Senparc.Weixin.WxOpen" Version="3.8.501" />
|
||||
<PackageReference Include="System.Data.SqlClient" Version="4.8.1" />
|
||||
<PackageReference Include="ZKWeb.System.Drawing" Version="4.0.1" />
|
||||
</ItemGroup>
|
||||
@@ -282,6 +282,9 @@
|
||||
<None Include="wwwroot\editor\ckeditor\plugins\wsc\LICENSE.md" />
|
||||
<None Include="wwwroot\editor\ckeditor\plugins\wsc\README.md" />
|
||||
<None Include="wwwroot\editor\ckeditor\skins\moono-lisa\readme.md" />
|
||||
<None Include="wwwroot\install\comcms_for_linux.sql" />
|
||||
<None Include="wwwroot\install\comcms_for_windows.sql" />
|
||||
<None Include="wwwroot\install\comcms_sqlserver.sql" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
@@ -28,9 +28,15 @@ namespace COMCMS.Web.Controllers
|
||||
{
|
||||
_env = env;
|
||||
}
|
||||
|
||||
#region 首页
|
||||
public IActionResult Index()
|
||||
{
|
||||
bool hasData = AdminMenu.FindCount(null, null, null, 0, 0) > 0;
|
||||
if (!hasData)
|
||||
{
|
||||
return Redirect("/Home/Install");
|
||||
}
|
||||
ViewBag.cfg = cfg;
|
||||
ViewBag.about = Article.FindById(1);//关于我们
|
||||
return View("~/Views/Home/Index.cshtml");
|
||||
@@ -54,12 +60,130 @@ namespace COMCMS.Web.Controllers
|
||||
{
|
||||
return EchoTip("COMCMS系统已经安装过,如果需要重新安装,请删除程序wwwroot目录下的install.lock文件!", false, "/");
|
||||
}
|
||||
//判断数据库类型 mysql mssql 暂时只支持这两种
|
||||
string sqltype = "mysql";
|
||||
string sqlProviderName = Utils.GetSetting("connectionStrings:dbconn:providerName");
|
||||
if (sqlProviderName == "System.Data.SqlClient")
|
||||
{
|
||||
sqltype = "mssql";
|
||||
}
|
||||
bool hasData = AdminMenu.FindCount(null, null, null, 0, 0) > 0;
|
||||
ViewBag.hasData = hasData;
|
||||
ViewBag.sqltype = sqltype;
|
||||
return View();
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region 执行初始化数据库数据
|
||||
[HttpPost]
|
||||
[ValidateAntiForgeryToken]
|
||||
public IActionResult DoInstall()
|
||||
{
|
||||
string sitename = Request.Form["sitename"];
|
||||
string siteurl = Request.Form["siteurl"];
|
||||
string mysqltype = Request.Form["mysqltype"];
|
||||
string username = Request.Form["username"];
|
||||
string password = Request.Form["password"];
|
||||
string password2 = Request.Form["password2"];
|
||||
|
||||
if (string.IsNullOrEmpty(sitename))
|
||||
{
|
||||
tip.Message = "请填写网站名称!";
|
||||
return Json(tip);
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(username))
|
||||
{
|
||||
tip.Message = "请输入用户名!";
|
||||
return Json(tip);
|
||||
}
|
||||
if (username.Trim().Length<5)
|
||||
{
|
||||
tip.Message = "用户名不能小于4个字符!";
|
||||
return Json(tip);
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(password) || Utils.GetStringLength(password) < 5)
|
||||
{
|
||||
tip.Message = "登录密码不能为空或者长度小于5!";
|
||||
return Json(tip);
|
||||
}
|
||||
if(password != password2)
|
||||
{
|
||||
tip.Message = "两次输入密码不一致,请重新输入!";
|
||||
return Json(tip);
|
||||
}
|
||||
string sqltype = "mysql";
|
||||
string sqlProviderName = Utils.GetSetting("connectionStrings:dbconn:providerName");
|
||||
if (sqlProviderName == "System.Data.SqlClient")
|
||||
{
|
||||
sqltype = "mssql";
|
||||
}
|
||||
|
||||
if(sqltype =="mysql" && string.IsNullOrEmpty(mysqltype))
|
||||
{
|
||||
tip.Message = "请选择系统Mysql服务器类型!";
|
||||
return Json(tip);
|
||||
}
|
||||
|
||||
string lockPath = $"{_env.WebRootPath}{Path.DirectorySeparatorChar}install.lock";
|
||||
if (System.IO.File.Exists(lockPath))
|
||||
{
|
||||
tip.Message = "COMCMS系统已经安装过,如果需要重新安装,请删除程序wwwroot目录下的install.lock文件!";
|
||||
return Json(tip);
|
||||
}
|
||||
|
||||
//判断需要的sql文件
|
||||
string sqlname = "comcms_sqlserver.sql";
|
||||
if(sqltype == "mysql")
|
||||
{
|
||||
if (mysqltype == "linux")
|
||||
sqlname = "comcms_for_linux.sql";
|
||||
else
|
||||
sqlname = "comcms_for_windows.sql";
|
||||
}
|
||||
|
||||
string sqlPath = $"{_env.WebRootPath}{Path.DirectorySeparatorChar}install{Path.DirectorySeparatorChar}";
|
||||
string sqlFullPath = Path.Combine(sqlPath, sqlname);
|
||||
|
||||
if (!System.IO.File.Exists(sqlFullPath))
|
||||
{
|
||||
tip.Message = "缺少初始化SQL文件!";
|
||||
return Json(tip);
|
||||
}
|
||||
string fullsql = System.IO.File.ReadAllText(sqlFullPath);
|
||||
|
||||
Admin.FindAll(fullsql);//执行
|
||||
|
||||
//初始化
|
||||
Config cfg = Config.FindById(1);
|
||||
if(cfg != null)
|
||||
{
|
||||
cfg.SiteName = sitename;
|
||||
cfg.SiteUrl = siteurl;
|
||||
cfg.Update();
|
||||
}
|
||||
|
||||
Admin admin = Admin.Find(Admin._.Id == 1);
|
||||
if(admin != null)
|
||||
{
|
||||
admin.UserName = username;
|
||||
admin.Salt = Utils.GetRandomChar(10);
|
||||
admin.PassWord = Utils.MD5(admin.Salt + password);
|
||||
admin.Update();
|
||||
}
|
||||
|
||||
|
||||
//写入Lock文件
|
||||
System.IO.File.WriteAllText(lockPath, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
|
||||
|
||||
tip.Message = "导入数据成功!";
|
||||
tip.Status = JsonTip.SUCCESS;
|
||||
tip.ReturnUrl = "/";
|
||||
return Json(tip);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region 测试
|
||||
//[Route("c/{*path}/index2.html")]
|
||||
//public IActionResult Test(string path = "")
|
||||
|
||||
@@ -0,0 +1,99 @@
|
||||
@{
|
||||
Layout = null;
|
||||
}
|
||||
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>COMCMS 初始化</title>
|
||||
<link href="~/lib/bootstrap/dist/css/bootstrap.min.css" rel="stylesheet" />
|
||||
<link href="~/hplus/css/style.css" rel="stylesheet" />
|
||||
<link href="~/hplus/css/font-awesome.min.css" rel="stylesheet" />
|
||||
<link href="~/hplus/css/animate.min.css" rel="stylesheet" />
|
||||
<link href="~/hplus/css/login.css" rel="stylesheet" />
|
||||
|
||||
<!--[if lt IE 8]>
|
||||
<meta http-equiv="refresh" content="0;Ie" />
|
||||
<![endif]-->
|
||||
<script>if (window.top !== window.self) { window.top.location = window.location; }</script>
|
||||
<script src="~/js/des.js"></script>
|
||||
<script>var encrypt_key = '@ViewBag.key';</script>
|
||||
</head>
|
||||
<body class="gray-bg">
|
||||
<div class="middle-box text-center loginscreen animated fadeInDown">
|
||||
<div>
|
||||
<div class="text-center m-b-md" style="font-size:64px">
|
||||
COMCMS
|
||||
</div>
|
||||
<h3>初始化系统数据</h3>
|
||||
<form asp-controller="Home" asp-action="DoInstall" id="installForm" class="m-t" role="form" method="post" asp-antiforgery="true">
|
||||
<div class="form-group">
|
||||
<input type="text" name="sitename" id="sitename" class="form-control" placeholder="网站名称" required="" value="comcms">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<input type="text" name="siteurl" id="siteurl" class="form-control" placeholder="网站URL地址" required="" value="@Utils.GetServerUrl()">
|
||||
</div>
|
||||
@if (ViewBag.sqltype == "mysql")
|
||||
{
|
||||
<div class="form-group">
|
||||
<select class="form-control" name="mysqltype" id="mysqltype">
|
||||
<option value="windows">Windows 下 Mysql(数据库表不区分大小写)</option>
|
||||
<option value="linux">Linux 下 Mysql(数据库表区分大小写)</option>
|
||||
</select>
|
||||
</div>
|
||||
}
|
||||
<div class="form-group">
|
||||
<input type="text" name="username" id="username" class="form-control" placeholder="超级管理员登录账号" required="">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<input type="password" name="password" id="password" class="form-control" placeholder="超级管理员登录密码" required="">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<input type="password" name="password2" id="password2" class="form-control" placeholder="确认登录密码" required="">
|
||||
</div>
|
||||
<button type="submit" class="btn btn-primary block full-width m-b">确认安装</button>
|
||||
<p class="text-muted text-center">
|
||||
COMCMS © 2014-@DateTime.Now.Year
|
||||
</p>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
<!-- 全局js -->
|
||||
<environment names="Development">
|
||||
<script src="~/lib/jquery/dist/jquery.js"></script>
|
||||
<script src="~/lib/bootstrap/dist/js/bootstrap.js"></script>
|
||||
<script src="~/js/validation/jquery.validate.js"></script>
|
||||
<script src="~/js/validation/messages_zh.js"></script>
|
||||
<script src="~/js/layer/layer.js"></script>
|
||||
<script src="~/js/jquery.form.js"></script>
|
||||
<script src="~/js/rtpost.js"></script>
|
||||
</environment>
|
||||
<environment names="Staging,Production">
|
||||
<script src="~/lib/jquery/dist/jquery.js"></script>
|
||||
<script src="~/lib/bootstrap/dist/js/bootstrap.js"></script>
|
||||
<script src="~/js/validation/jquery.validate.min.js"></script>
|
||||
<script src="~/js/validation/messages_zh.min.js"></script>
|
||||
<script src="~/js/layer/layer.js"></script>
|
||||
<script src="~/js/jquery.form.min.js"></script>
|
||||
<script src="~/js/rtpost.js"></script>
|
||||
</environment>
|
||||
<script>
|
||||
$(function () {
|
||||
var rules = {
|
||||
username: {
|
||||
required: true,
|
||||
minlength: 5
|
||||
},
|
||||
password: {
|
||||
required: true,
|
||||
minlength: 5
|
||||
}
|
||||
};
|
||||
DoPost("installForm", rules,"提交初始化安装");
|
||||
});
|
||||
</script>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
@@ -9,11 +9,12 @@
|
||||
"FileAllowedExtensions": "zip,rar,7z,doc,docx,xls,xlsx,ppt,pptx,csv,pdf,txt,gz,gzip,gif,png,jpg,jpeg,bmp,avi,fla,flv,swf,mp4,mp3,mov,mid,mpg,mpeg,rm,rmvb,wma,wav,wmv",
|
||||
"ImageAllowedExtensions": "gif,png,jpg,jpeg,bmp",
|
||||
"MediaAllowedExtensions": "flv,mp4,mp3,wmv,swf,mov",
|
||||
"COMCMSPrefixKey": "abc_"
|
||||
"COMCMSPrefixKey": "abc_",
|
||||
"SignSalt": "comcms"
|
||||
},
|
||||
"connectionStrings": {
|
||||
"dbconn": {
|
||||
"connectionString": "Server=.;Port=3306;Database=comcms2;Uid=root;Pwd=root;SslMode=None;charset=utf8mb4",
|
||||
"connectionString": "Server=.;Port=3306;Database=comcms;Uid=root;Pwd=root;SslMode=None;charset=utf8mb4",
|
||||
"providerName": "MySql.Data.MySqlClient"
|
||||
},
|
||||
"mssqlconnon": {
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -4,12 +4,13 @@ COMCMS NETCORE版本,一个简单的CMS后台管理系统,带前台演示。
|
||||
|
||||
|
||||
### 更新日志
|
||||
- 2020-04-27 增加程序初始化数据,支持Mysql(windows和linux)、Sqlserver 数据库
|
||||
- 2020-03-06 更新新的demo地址
|
||||
|
||||
### 技术简要
|
||||
|
||||
- .net core 3.1 (请注意升级本地SDK 或者runtime)
|
||||
- 数据库:Mysql 5.7 /Mysql 8.0
|
||||
- 数据库:Mysql 5.7 /Mysql 8.0 / SqlServer 2008+
|
||||
- ORM:数据库操作使用XCode,目前支持mysql、sqlserver。详细见:https://github.com/NewLifeX/X
|
||||
- 据库驱动使用:MySQL官方驱动,8.0.19
|
||||
- 后台模板是H+
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user