示例#1
0
 /// <summary>
 /// 备份
 /// </summary>
 /// <returns></returns>
 public JsonResult Backup()
 {
     string host = Utility.ConfigurationHelper.GetValue("MysqlHost");
     string port = Utility.ConfigurationHelper.GetValue("MysqlPort");
     string user = Utility.ConfigurationHelper.GetValue("MysqlUser");
     string password = Utility.ConfigurationHelper.GetValue("MysqlPwd");
     string db = Utility.ConfigurationHelper.GetValue("MysqlDb");
     string bakPath = Utility.ConfigurationHelper.GetValue("MysqlBakPath");
     string dumpPath = Utility.ConfigurationHelper.GetValue("MysqlDumpPath");
     var phicyPath = HostingEnvironment.MapPath(bakPath);
     string random = DateHelper.GetTimeStamp();
     if (!Directory.Exists(phicyPath))
     {
         Directory.CreateDirectory(phicyPath);
     }
     bakPath = phicyPath + random + "smallcode.sql";
     //string cmdStr = "mysqldump -h" + host + " -P" + port + " -u" + user + " -p" + password + " " + db + " > " + bakPath;
     StringBuilder sbcommand = new StringBuilder();
     sbcommand.AppendFormat("mysqldump --quick --host=" + host + " --default-character-set=utf8 --lock-tables --verbose  --force --port=" + port + " --user="******" --password="******" " + db + " -r \"{0}\"", bakPath);
     try
     {
         ExecuteCmd(sbcommand.ToString(), dumpPath);
         log.Info(new LogContent(CurrentUser.Username + "备份了数据库" + bakPath, LogType.记录.ToString(), HttpHelper.GetIPAddress()));
         AjaxModel model = new AjaxModel();
         model.Statu = "ok";
         model.Msg = "备份成功!";
         return Json(model);
     }
     catch (Exception ex)
     {
         log.Error(new LogContent(CurrentUser.Username + "备份数据库出错" + ex.Message, LogType.异常.ToString(), HttpHelper.GetIPAddress()));
         AjaxModel model = new AjaxModel();
         model.Statu = "err";
         model.Msg = "备份失败!";
         return Json(model);
     }
 }
示例#2
0
 public ActionResult Save(string Title, string Text)
 {
     AjaxModel model = new AjaxModel();
     if (CurrentUser!=null)
     {
         int user_id = CurrentUser.Id;
         Demand demand = new Entity.Demand();
         IBLL.IDemandBLL bll = BLLSessionFactory.GetBLLSession().IDemandBLL;
         User user = new Entity.User();
         user = bllSession.IUserBLL.GetEntity(user_id);
         if(Title.Length==0)
         {
             model.Statu = "title";
             model.Data = "请输入标题!";
             model.Msg = "请输入标题!";
         }
         else if (Title.Length >25)
         {
             model.Statu = "title";
             model.Data = "标题过长,请重新输入!";
             model.Msg = "标题过长,请重新输入!";
         }
         else if (Text.Length == 0)
         {
             model.Statu = "text";
             model.Data = "请填写需求!";
             model.Msg = "请填写需求!";
         }
         bool isBanned=false;
         WordFilterHelper<Demand>.TextFilter(Text,out isBanned);
         if(isBanned)
         {
             model.Statu = "isBanned";
             model.Data = "文章内容包含敏感词,请修改后重新提交!";
         }
         else
         {
             try
             {
                 demand.Title = Title.Trim();
                 demand.Text = Text.Trim();
                 demand.State = 0;
                 demand.UserId = user_id;
                 demand.DateTime = DateTime.Now;
                 bll.Insert(demand);
                 model.Statu = "ok";
                 model.Msg = "提交成功!";
                 model.BackUrl = "/Demand";
                 log.Info(new LogContent(user.Username + "用户提交需求", LogType.记录.ToString(), HttpHelper.GetIPAddress()));
             }
             catch (Exception e)
             {
                 model.Statu = "err";
                 model.Msg = "提交出错请重试!";
                 log.Error(new LogContent(user.Username + "用户提交需求出错" + e.Message, LogType.异常.ToString(), HttpHelper.GetIPAddress()));
             }
         }
     }
     else
     {
         model.Statu = "go_login";
         model.Msg = "请登录后再提交页面!";
         model.BackUrl = "/User/Login";
     }
     return Json(model);
 }
示例#3
0
 public ActionResult Up_Vote(int Id)
 {
     AjaxModel model = new AjaxModel();
     Demand demand = new Entity.Demand();
     demand = bllSession.IDemandBLL.GetEntity(Id);
     try
     {
         demand.Vote = demand.Vote + 1;
         bllSession.IDemandBLL.Update(demand);
         model.Statu = "ok";
         model.Msg = "提交成功!";
         log.Info(new LogContent("用户点赞", LogType.记录.ToString(), HttpHelper.GetIPAddress()));
     }
     catch(Exception e)
     {
         model.Statu = "err";
         model.Msg = "数据异常,请刷新重试!";
         log.Error(new LogContent("用户点赞出错"+ e.Message, LogType.异常.ToString(), HttpHelper.GetIPAddress()));
     }
     return Json(model);
 }
示例#4
0
 public ActionResult Login(string Username, string Password, string ReturnUrl)
 {
     AjaxModel model = new AjaxModel();
     IBLL.IUserBLL bll = BLLSessionFactory.GetBLLSession().IUserBLL;
     User user = new User();
     Password = Encryt.GetMD5(Password.Trim());
     user = bll.Login(Username.Trim(), Password);
     if (user == null)
     {
         model.Data = user;
         model.Msg = "用户名或者密码不正确!";
         model.Statu = "err";
     }
     else
     {
         FormsAuthentication.SetAuthCookie(Username.Trim(), false);
         model.Data = user;
         model.Statu = "ok";
         model.BackUrl = ReturnUrl == null ? "/Home/Index" : ReturnUrl;
         log.Info(new LogContent(Username + ":登陆", LogType.记录.ToString(), HttpHelper.GetIPAddress()));
     }
     return Json(model);
 }
示例#5
0
 public ActionResult RegisterDetail(string Username, string Password, string Email)
 {
     AjaxModel model = new AjaxModel();
     User user = new Entity.User();
     try
     {
         if (bllSession.IUserBLL.GetUserByEmail(Email) != null)
         {
             model.Statu = "err";
             model.Msg = "该邮箱已经存在!";
         }
         else
         {
             IBLL.IUserBLL bll = BLLSessionFactory.GetBLLSession().IUserBLL;
             user = bll.GetUserByName(Username);
             if (user != null)
             {
                 model.Statu = "err";
                 model.Msg = "该用户名已经存在!";
             }
             else
             {
                 user = new Entity.User();
                 user.Username = Username.Trim();
                 user.Password = Encryt.GetMD5(Password.Trim());
                 user.Time = DateTime.Now;
                 user.Email = Email;
                 bll.Insert(user);
                 model.Statu = "ok";
                 model.Msg = "注册用户成功!";
             }
         }
     }
     catch
     {
         model.Statu = "err";
         model.Msg = "注册用户出错请重试!";
     }
     return Json(model);
 }