public ActionResult CreateAccount(CreateAccountViewModel accountModel)
 {
     if (ModelState.IsValid)
     {
         //验证用户名唯一
         var uEx = _bLLUser.Exist(s => s.UserName == accountModel.Username);
         if (uEx)
         {
             return(Json(false));
         }
         //验证用户邮箱唯一
         uEx = _bLLUser.Exist(s => s.UserMail == accountModel.UserEmail);
         if (uEx)
         {
             return(Json(false));
         }
         var u = new User()
         {
             UserId       = Guid.NewGuid(),
             UserName     = accountModel.Username,
             UserPassword = HashHelper.GetHashedString(HashType.SHA256, accountModel.UserPassword),
             UserMail     = accountModel.UserEmail
         };
         try
         {
             var count = _bLLUser.Insert(u);
             if (count == 1)
             {
                 OperLogHelper.AddOperLog(
                     $"添加用户 {accountModel.Username}-{accountModel.UserEmail} 成功",
                     OperLogModule.Account, UserName);
                 return(Json(true));
             }
         }
         catch (Exception ex)
         {
             Logger.Error(ex);
         }
     }
     return(Json(false));
 }
예제 #2
0
 public ActionResult CreateAccount(CreateAccountViewModel accountModel)
 {
     if (ModelState.IsValid)
     {
         //验证用户名唯一
         var u = _bLLUser.Fetch(s => s.UserName == accountModel.Username);
         if (u != null)
         {
             return(Json(false));
         }
         //验证用户邮箱唯一
         u = _bLLUser.Fetch(s => s.UserMail == accountModel.UserEmail);
         if (u != null)
         {
             return(Json(false));
         }
         u = new User()
         {
             UserId       = Guid.NewGuid(),
             UserName     = accountModel.Username,
             UserPassword = SecurityHelper.SHA256_Encrypt(accountModel.UserPassword),
             UserMail     = accountModel.UserEmail
         };
         try
         {
             var count = _bLLUser.Insert(u);
             if (count == 1)
             {
                 OperLogHelper.AddOperLog(
                     string.Format("添加用户 {0}-{1} 成功", accountModel.Username, accountModel.UserEmail),
                     OperLogModule.Account, Username);
                 return(Json(true));
             }
         }
         catch (Exception ex)
         {
             Logger.Error(ex);
         }
     }
     return(Json(false));
 }