Example #1
0
        public JsonResult SaveAccount(string action, string account, string pwd, string name, string adminFlag, string loginFlag, string debtFlag)
        {
            MSGReturnModel result = new MSGReturnModel();

            result.RETURN_FLAG = false;
            if (account.IsNullOrWhiteSpace() ||
                !EnumUtil.GetValues <Action_Type>().Select(x => x.ToString()).Contains(action))
            {
                result.DESCRIPTION = Message_Type.parameter_Error.GetDescription();
                return(Json(result));
            }
            IFRS9_User data = new IFRS9_User();

            data.User_Account = account.Trim();
            data.User_Name    = name == null ? string.Empty : name.Trim();
            if (action == Action_Type.Edit.ToString())
            {
                data.AdminFlag = adminFlag == "Y" ? true : false;
                data.LoginFlag = loginFlag == "Y" ? true : false;
                data.DebtType  = debtFlag;
                if (!pwd.IsNullOrWhiteSpace())
                {
                    data.User_Password = pwd.Trim();
                }
            }
            if (action == Action_Type.Add.ToString())
            {
                data.User_Password = pwd.Trim();
                data.DebtType      = debtFlag;
                data.AdminFlag     = adminFlag == "Y" ? true : false;
            }
            result = SystemRepository.saveAccount(action, data);
            if (result.RETURN_FLAG)
            {
                SetCacheData(SystemRepository.getAccount(string.Empty,
                                                         AccountController.CurrentUserInfo.Name));
            }
            return(Json(result));
        }
Example #2
0
        public ActionResult Logon(string userId, string pwd)
        {
            bool flag = false;
            var  now  = DateTime.Now;

            if (!ModelState.IsValid)
            {
                TempData["User"]  = userId;
                TempData["Login"] = Message_Type.login_Captcha_Fail.GetDescription();
                return(RedirectToAction("Login", "Account"));
            }
            else
            {
                MvcCaptcha.ResetCaptcha("ExampleCaptcha");
                FileRelated.createFile(@"D:\IFRS9Log");
                try
                {
                    // set up domain context
                    //PrincipalContext ctx = new PrincipalContext(ContextType.Domain);

                    // find the current user
                    //UserPrincipal aduser = UserPrincipal.Current;

                    //驗證AD帳號
                    flag = LdapAuthentication.isAuthenticatrd(userId, pwd);
                }
                catch
                { }
                var user = new IFRS9_User();
                using (IFRS9DBEntities db = new IFRS9DBEntities())
                {
                    if (flag) //AD帳號
                    {
                        user = db.IFRS9_User.AsNoTracking().FirstOrDefault(x => x.User_Account == userId);
                    }
                    else //非AD帳號
                    {
                        user = db.IFRS9_User
                               .Where(x => userId.Equals(x.User_Account))
                               .AsEnumerable()
                               .FirstOrDefault(x => pwd.stringToSHA512().Equals(x.User_Password));
                    }
                    if (user != null)
                    {
                        if (user.Effective)
                        {
                            this.LoginProcess(user.User_Account, false, now);
                            flag           = true;
                            user.LoginFlag = true;
                            string IP = System.Web.HttpContext.Current.Request
                                        .ServerVariables["HTTP_X_FORWARDED_FOR"];
                            if (string.IsNullOrEmpty(IP))
                            {
                                IP = System.Web.HttpContext.Current.Request
                                     .ServerVariables["REMOTE_ADDR"];
                            }
                            db.IFRS9_User_Log.Add(
                                new IFRS9_User_Log()
                            {
                                User_Account = user.User_Account,
                                Login_Time   = now,
                                Login_IP     = IP,
                                Login_Date   = now.Date
                            });
                            try
                            {
                                db.SaveChanges();
                            }
                            catch { }
                        }
                        else
                        {
                            TempData["Login"] = Message_Type.login_Effective_Fail
                                                .GetDescription();
                            ModelState.AddModelError("", Message_Type.login_Effective_Fail
                                                     .GetDescription());
                            flag = false;
                        }
                    }
                    else
                    {
                        TempData["Login"] = Message_Type.login_Fail.GetDescription();
                        ModelState.AddModelError("", Message_Type.login_Fail.GetDescription());
                        flag = false;
                    }
                }
                if (flag)
                {
                    TempData["Login"] = string.Empty;
                    return(RedirectToAction("Index", "Home"));
                }
                else
                {
                    TempData["User"] = userId;
                    return(RedirectToAction("Login", "Account"));
                }
            }
        }