示例#1
0
        public ActionResult Edit(UserEditVM userVM)
        {
            UserService _userService = new UserService();

            if (!ModelState.IsValid)
            {
                return(View(userVM));
            }

            //MD5無法解密,故用此判斷是否更改過密碼
            //無更改過密碼,已經為MD5密碼
            if (userVM.UserPassword.Equals(userVM.OriginPassword))
            {
            }
            else//更改過密碼,需加密為MD5
            {
                userVM.UserPassword = MD5Encoder.Encrypt(userVM.UserPassword);
            }

            Mapper.CreateMap <UserEditVM, UserEditSV>();
            UserEditSV userEditSV = Mapper.Map <UserEditSV>(userVM);

            userEditSV.UpdateDate = System.DateTime.Now;
            userEditSV.UpdateId   = Session["Account"].ToString();

            _userService.ModifyUser(userEditSV);

            if (Session["Account"].Equals("9999"))
            {
                return(RedirectToAction("Index"));
            }

            return(RedirectToAction("EditSuccess"));
        }
示例#2
0
        public ActionResult Register(RegisterVM registerVM)
        {
            if (!ModelState.IsValid)
            {
                return(View(registerVM));
            }

            _userService = new UserService();

            DateTime nowDate = System.DateTime.Now;

            Mapper.CreateMap <RegisterVM, User>();
            User user = Mapper.Map <User>(registerVM);

            user.UserPassword = MD5Encoder.Encrypt(registerVM.UserPassword);
            user.UserStatus   = "0";//0帳號未啟動 1帳號啟動
            user.CreateDate   = nowDate;
            user.CreateId     = "9999";
            user.UpdateDate   = nowDate;
            user.UpdateId     = "9999";

            using (UserRepository _repo = new UserRepository())
            { _repo.Insert(user); }


            return(RedirectToAction("RegistSuccess"));
        }
示例#3
0
        public ActionResult Login(LoginVM model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            // 登入時清空所有 Session 資料
            Session.RemoveAll();
            //MD5加密密碼
            string      encrypt      = MD5Encoder.Encrypt(model.Password);
            UserService _userService = new UserService();

            ValidateLoginSM validateLoginSV = _userService.ValidateLogin(model.AccountId, encrypt);
            int             loginStatus     = validateLoginSV.LoginStatus;

            if (loginStatus == 0)
            {
                ModelState.AddModelError(string.Empty, "登入失敗,請重新登入。");
                ModelState.AddModelError(string.Empty, "員工編號或密碼輸入錯誤。");

                return(View(model));
            }
            else if (loginStatus == 1)
            {
                ModelState.AddModelError(string.Empty, "登入失敗,請重新登入。");
                ModelState.AddModelError(string.Empty, "帳號未啟動,請聯絡管理員。");

                return(View(model));
            }
            else
            {
                Session["Id"]      = validateLoginSV.UserId;
                Session["Account"] = validateLoginSV.UserAccount;
                Session["Name"]    = validateLoginSV.UserName;

                if (Session["Account"].ToString().Equals("9999"))
                {
                    //return RedirectToAction("Index","User");
                    return(RedirectToAction("MasterIndex", "DiaryLogNew"));
                }

                return(RedirectToAction("Index", "DiaryLogNew", new { userId = validateLoginSV.UserId }));
            }
        }
示例#4
0
        /// <summary>
        /// 產生檢查碼。
        /// 並排除不作驗證的字串
        /// </summary>
        /// <param name="param"></param>
        /// <returns></returns>
        internal string BuildCheckMacValue(string param)
        {
            //排除不作驗證的字串
            string urlparams = RemoveIgnoreMacValues(param);

            //2. 參數最前面加上 HashKey、最後面加上 HashIV
            var szCheckMacValue = $"HashKey={_settings.HashKey}&{urlparams}&HashIV={_settings.HashIV}";

            //3. 將整串字串進行 URL encode
            //4. 轉為小寫
            szCheckMacValue = HttpUtility.UrlEncode(szCheckMacValue).ToLower();

            //5. 依 URLEncode 轉換表更換字元,在.net環境下不需要實作
            //6. 以 MD5 加密方式來產生雜凑值
            //7. 再轉大寫產生 CheckMacValue
            szCheckMacValue = MD5Encoder.Encrypt(szCheckMacValue);
            //轉換成大寫
            return(szCheckMacValue.ToUpper());
        }