Esempio n. 1
0
        public ActionResult Authorize(BI_USER userModel)
        {
            if (!ModelState.IsValid)
            {
                return(View(userModel));
            }

            using (TKTDSXEntities db = new TKTDSXEntities())
            {
                string strInput = userModel.Password.Trim();

                string decryptPass = CryptorEngine.Encrypt(strInput, true);

                var userDetails = db.BI_USER.Where(x => x.MANDT == "900" && x.SYSID == "P01" &&
                                                   x.Username == userModel.Username && x.Password == decryptPass).FirstOrDefault();
                if (userDetails == null)
                {
                    ModelState.AddModelError("", "Sign failed, please check input again.");

                    return(View("Index", userModel));
                }
                else
                {
                    Session["Username"] = userDetails;
                    return(RedirectToAction("Index", "Liveboard"));
                }
            }
        }
Esempio n. 2
0
        //
        // GET: /Login/

        public ActionResult Index()
        {
            Session["UserName"] = null;
            BI_USER DefaultUser = new BI_USER()
            {
                MANDT = "900", SYSID = "P01"
            };

            return(View("Index", DefaultUser));
        }
Esempio n. 3
0
        public ActionResult ChangePassword(UserManager user)
        {
            var loggedUser = Session["Username"] as BI_USER;

            user.Username = loggedUser.Username;
            if (user.JobPosition == null)
            {
                user.JobPosition = loggedUser.GhiChu;
            }

            if (loggedUser == null)
            {
                RedirectToAction("Index", "Login");
            }

            if ((user.CurrentPassword == null) && (user.Password == null) &&
                (user.PasswordCofirm == null))
            {
                return(View("ChangePassword", user));
            }


            if (!ModelState.IsValid)
            {
                return(View("ChangePassword", user));
            }
            using (TKTDSXEntities dc = new TKTDSXEntities())
            {
                string strPwd     = user.CurrentPassword.Trim();
                string strEncrypt = CryptorEngine.Encrypt(strPwd, true);
                //Check exist user
                BI_USER existUser = dc.BI_USER.Where(x => x.MANDT == "900" && x.SYSID == "P01" &&
                                                     x.Username == user.Username).FirstOrDefault();
                if ((user.CurrentPassword != null) && (strEncrypt != existUser.Password))
                {
                    ModelState.AddModelError("CurrentPassword", "Current Password Incorrect");
                    return(View("ChangePassword", user));
                }
                else
                {
                    user.CurrentPassword = existUser.Password;
                }

                if ((user.Password != user.PasswordCofirm) && ((user.Password != null) || (user.PasswordCofirm != null)))
                {
                    ModelState.AddModelError("Password", "New Password do not match with confirm password");
                    return(View("ChangePassword", user));
                }

                if (user.Password == existUser.Password)
                {
                    ModelState.AddModelError("Password", "New Password must different exist password");
                    return(View("ChangePassword", user));
                }
                else
                {
                    existUser.Password = user.Password;
                    existUser.GhiChu   = user.JobPosition;

                    string newPwd = existUser.Password.Trim();

                    string strEncryptPwd = CryptorEngine.Encrypt(newPwd, true);

                    existUser.Password = strEncryptPwd;

                    dc.BI_USER.Attach(existUser);
                    var entry = dc.Entry(existUser);
                    entry.Property(e => e.Password).IsModified = true;
                    entry.Property(e => e.GhiChu).IsModified   = true;
                    dc.SaveChanges();

                    Session["Username"]           = existUser;
                    ViewBag.SuccessChangePassword = "******";
                    return(View("ChangePassword", user));
                }
            }
        }