Beispiel #1
0
 public JsonResult CreateUser(BusinessUserModel model, string password)
 {
     JsonModel jsonModel;
     try
     {
         UserManager.CreateUser(model, password);
         jsonModel = JsonModel.Success(SiteCommonResource.MessageCreateUserSuccessfully);
         jsonModel.ObjectModel = model;
     }
     catch (Exception ex)
     {
         jsonModel = BaseException.HandleException(ex);
     }
     return Json(jsonModel);
 }
Beispiel #2
0
 public ActionResult SignIn()
 {
     BusinessUserModel model = new BusinessUserModel
     {
         UserName = base.LoginAccount
     };
     Session.Clear();
     return View(model);
 }
Beispiel #3
0
 /// <summary>
 /// 创建用户
 /// </summary>
 /// <param name="userModel">用户模型数据</param>
 /// <param name="password">密码</param>
 public static void CreateUser(BusinessUserModel userModel, string password)
 {
     if (userModel == null)
     {
         throw new ArgumentNullException("userModel");
     }
     if (string.IsNullOrWhiteSpace(password))
     {
         throw new ArgumentNullException("password");
     }
     userModel.RoleName = CheckRoleName(userModel.RoleName);
     userModel.UserName = CheckUserName(userModel.UserName);
     userModel.DisplayName = string.IsNullOrWhiteSpace(userModel.DisplayName)
         ? userModel.UserName : userModel.DisplayName.Trim();
     userModel.CreationTime = DateTime.Now;
     CheckPassword(password);
     using (WarehouseEntryDbContext dbContext = DbContextHelper.CreateDbContext())
     {
         SecurityRole role = GetSecurityRole(dbContext, userModel.RoleName);
         SecurityUser user = SecurityData.SelectUser(dbContext, userModel.UserName);
         if (user != null)
         {
             throw new ErrorException("UserNameNotUnique", user.UserName);
         }
         user = new SecurityUser
         {
             UserName = userModel.UserName,
             DisplayName = userModel.DisplayName,
             Password = EncryptPassword(password),
             Enabled = userModel.Enabled,
             CreationTime = userModel.CreationTime,
             SecurityRole = role
         };
         dbContext.SecurityUser.Add(user);
         dbContext.SaveChanges();
     }
 }