Exemple #1
0
        public ActionResult Signin(string ReturnUrl)
        {
            var model = new LogInModel
            {
                ReturnUrl = Url.Action("Index", "Home")
            };

            return(View(model));
        }
Exemple #2
0
        public ActionResult Signin(LogInModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View());
            }

            string ad  = model.Username;
            string pwd = model.Password;
            string msg = "";

            //CacheFactory.ClearCache(); //TODO remove

            try
            {
                UserBasicInfo domainUser = null;
                if (!CommonInfo.IsLogin())
                {
                    var user = SysUserInfo.GetUserInfoByAd(ad);
                    if (user == null)
                    {
                        msg = "账号不存在,请先注册! Login user not exist, please register first!";
                        ModelState.AddModelError("", msg);
                        return(View());
                    }

                    //验证域密码
                    if (user != null)
                    {
                        domainUser = new UserBasicInfo(user.id, user.ADAccount, user.Email, user.FullName, user.IsAdmin);
                    }
                    if (user == null /*|| false == ConfigInfo.DebugRun*/)
                    {
                        domainUser = new ActiveDirectoryHelper().GetDomainUser(ad, pwd, out msg);
                        if (domainUser == null)
                        {
                            ModelState.AddModelError("", msg);
                            return(View());
                        }
                        if (user != null)
                        {
                            domainUser = new UserBasicInfo(user.id, user.ADAccount, user.Email, user.FullName, user.IsAdmin);
                        }
                        // 更新用户邮箱
                        if (user != null && string.IsNullOrEmpty(domainUser.Email) == false &&
                            domainUser.Email != user.Email)
                        {
                            user.Email = domainUser.Email;
                            SysUserInfo.Update(user);
                        }
                    }
                    // 帐号被停用
                    if (!user.IsValid)
                    {
                        msg = "账号已被停用. Your account was disabled.";
                        ModelState.AddModelError("", msg);
                        return(View());
                    }
                }
                else
                {
                    domainUser = CommonInfo.CurrentUser;
                }
                CommonInfo.Login(domainUser);
                SysUserInfo.UpdateUserLoginTimeByAd(ad);
                return(RedirectToLocal(model.ReturnUrl));
            }
            catch (Exception ex)
            {
                LogHelper.WriteError(this.GetType(), ex);
                ModelState.AddModelError("", ex);
                return(View());
            }
        }