示例#1
0
 public IActionResult Create(IFormCollection collection, AdmUser admUser)
 {
     try
     {
         // TODO: Add insert logic here
         if (admUser.Id > 0)
         {
             admUser.Password = EncryptionAndDecryption.Encode(admUser.Password);
             DBHandler.Db.AdmUser.Update(admUser);
         }
         else
         {
             admUser.CreateTime = DateTime.Now;
             admUser.Password   = EncryptionAndDecryption.Encode(admUser.Password);
             // _DccyDbContext.AdmUser.Add(admUser);
             DBHandler.Db.AdmUser.Add(admUser);
         }
         int m = DBHandler.DbSavaChange();
         if (m > 0)
         {
             return(RedirectToAction(nameof(Index)));
         }
         else
         {
             return(null);
         }
     }
     catch (Exception ex)
     {
         return(RedirectToAction("Error", "Home", new ErrorViewModel {
             RequestId = ex.Message
         }));
     }
 }
示例#2
0
        // GET: AdmUser/Create
        public ActionResult Create()
        {
            AdmUser admUser = new AdmUser()
            {
                UserName      = "******",
                UserAccounts  = "123456",
                Password      = "******",
                Guid          = Guid.NewGuid().ToString().ToUpper(),
                DepId         = 2,
                RoleId        = 1,
                LastLoginTime = DateTime.Now,
                Sex           = 1,
                NumOfLogins   = 1
            };

            admUser.CreateTime = DateTime.Now;
            admUser.Password   = EncryptionAndDecryption.Encode(admUser.Password);
            // _DccyDbContext.AdmUser.Add(admUser);
            DBHandler.Db.AdmUser.Add(admUser);
            int m = DBHandler.DbSavaChange();

            return(View());
        }
        public ActionResult Login(string acountName, string password, string code)
        {
            AdmUser admUser = null;

            #region 用户名验证
            if (acountName != null && acountName.Length > 0 && acountName != "")
            {
                var user = DBHandler.Db.AdmUser.First(u => u.UserAccounts == acountName || u.Email == acountName || u.Tel == acountName);
                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.Encode(password);
                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(TempData["SecurityCode"]))
                {
                    HttpContext.Session.SetString("AdmUserSession", JsonConvert.SerializeObject(admUser));
                    return(RedirectToAction("Index", "Home", admUser));
                }
                else
                {
                    ViewBag.LoginMsg = "验证码输入错误!!!";
                    return(View("Index"));
                }
            }
            else
            {
                ViewBag.LoginMsg = "请输入合法的验证码!!!";
                return(View("Index"));
            }
            #endregion
        }
        public ActionResult Login(string acountName, string Tel, string password, string code)
        {
            AdmUser admUser = null;

            #region 用户名验证
            if (acountName != null && acountName.Length > 0 && acountName != "")
            {
                var user = DBHandler.Db.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.Encode(password);
                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(TempData["SecurityCode"]))
                {
                    HttpContext.Session.SetString("AdmUserSession", JsonConvert.SerializeObject(admUser));
                    Logger.Info(JsonConvert.SerializeObject("用户帐号:" + admUser.UserAccounts + ",用户名:" + admUser.UserName + ",用户Emal:" + admUser.Email + ",用户电话:" + admUser.Tel));
                    return(RedirectToRoute(new { Controller = "SysAdm", Action = "Index" }));
                }
                else
                {
                    ViewBag.LoginMsg = "验证码输入错误!!!";
                    return(View("Index"));
                }
            }
            else
            {
                ViewBag.LoginMsg = "请输入合法的验证码!!!";
                return(View("Index"));
            }
            #endregion
        }