public async Task <IActionResult> Create([Bind("Guid,UserAccounts,UserName,Password,LastLoginTime,RoleId,DepId,Sex,Email,Tel,Address,DetailedAddress,NumOfLogins,ThumbnailImage,Id,CreateTime,IsDelete,Description,TimestampV")] AdmUser admUser) { if (ModelState.IsValid) { AdmUser user = _context.AdmUser.Where(u => u.UserAccounts == admUser.UserAccounts || u.UserName == admUser.UserName || u.Tel == admUser.Tel).ToList().FirstOrDefault(); if (user != null && user.Id > 0) { if (user.IsDelete == true) { ViewBag.Message = "此用户已存在,但暂时为停用状态"; return(View(user)); } else { ViewBag.Message = "此用户已存在"; return(View(user)); } } admUser.CreateTime = DateTime.Now; admUser.Guid = Guid.NewGuid().ToString().ToUpper(); admUser.PGuid = admUserModel.Guid; admUser.Password = _encryptionAndDecryption.AESEncrypt(admUser.Password, _appSetting.EncryptKey); _context.Add(admUser); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(admUser)); }
public async Task <IActionResult> Create([Bind("Guid,UserAccounts,UserName,Password,LastLoginTime,RoleId,DepId,Sex,Email,Tel,Address,DetailedAddress,NumOfLogins,ThumbnailImage,Id,CreateTime,IsDelete,Description,TimestampV")] AdmUser admUser) { if (ModelState.IsValid) { admUser.CreateTime = DateTime.Now; admUser.Guid = Guid.NewGuid().ToString().ToUpper(); admUser.Password = _encryptionAndDecryption.AESEncrypt(admUser.Password, _appSetting.EncryptKey); _context.Add(admUser); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(admUser)); }
public ActionResult Login(string acountName, string Tel, string password, string code) { AdmUser admUser = null; #region 用户名验证 if (acountName != null && acountName.Length > 0 && acountName != "") { var user = _dbContext.AdmUser.FirstOrDefault(u => u.UserAccounts == acountName || u.Email == acountName || u.Tel == acountName || u.UserName == acountName || u.Tel == Tel || u.UserAccounts == Tel || u.UserName == Tel || u.Email == Tel); if (user != null && user.Id > 0) { admUser = user; } else { ViewBag.LoginMsg = "请输入合法的登录帐号或帐号不存在!!!"; return(View("Index")); } } else { ViewBag.LoginMsg = "请输入合法的登录帐号!!!"; return(View("Index")); } #endregion #region 密码验证 if (password != null && password.Length > 0 && password != "") { var userPwdEncode = _encryptionAndDecryption.AESEncrypt(password, _appSetting.EncryptKey); if (admUser.Password.Equals(userPwdEncode)) { } else { ViewBag.LoginMsg = "密码错误!!!"; return(View("Index")); } } else { ViewBag.LoginMsg = "请输入合法的登录密码!!!"; return(View("Index")); } #endregion #region 验证码 if (code != null && code.Length > 0 && code != "") { if (code.Equals(SecurityCode_Odd)) { SecurityCode_Odd = null; HttpContext.Session.SetString("AdmUserSession", JsonConvert.SerializeObject(admUser)); Logger.Info(JsonConvert.SerializeObject(admUser.UserAccounts + "," + admUser.UserName + "," + admUser.Email + "," + admUser.Tel)); return(RedirectToRoute(new { Controller = "SysAdm", Action = "Index" })); } else { ViewBag.LoginMsg = "验证码输入错误!!!"; return(View("Index")); } } else { ViewBag.LoginMsg = "请输入合法的验证码!!!"; return(View("Index")); } #endregion }