示例#1
0
        public ActionResult Login(LogOnModel model, int siteId)
        {
            var systemFlag = systemMgr.GetEntityPreferenceValue(Entity.SYS.EntityPreference.CodeEnum.SystemFlag);
            ViewBag.IsShow = systemFlag == "1";

            if (ModelState.IsValid)
            {
                PortalSetting portalSetting = this.portalSettingMgr.GetPortalSetting(siteId);

                SecurityService.SecurityService securityService = new SecurityService.SecurityService();
                securityService.Url = ServiceURLHelper.ReplaceServiceUrl(securityService.Url, portalSetting.SIServerAddress, portalSetting.SIPort.ToString());

                string userToken = string.Empty;
                string returnVal = securityService.VerifyUserPasswordAndGetUserToken(model.UserName, model.Password);

                switch (returnVal)
                {
                    case "NullAccouunt":
                        ModelState.AddModelError(string.Empty, "帐号不存在.");
                        break;
                    case "Invalid":
                        ModelState.AddModelError(string.Empty, "帐号已经停用");
                        break;
                    case "PasswordExpired":
                        ModelState.AddModelError(string.Empty, "用户帐号密码已经过期");
                        return RedirectToAction("ChangePassword", new { siteId = siteId, userCode=model.UserName });
                    case "AccountLocked":
                        ModelState.AddModelError(string.Empty, "帐号已锁定。请联系管理员!");
                        break;
                    case "AccountLocked1":
                        ModelState.AddModelError(string.Empty, "密码连续3次错误,帐号已锁定。请联系管理员!");
                        break;
                    case "PasswordError":
                        ModelState.AddModelError(string.Empty, "密码错误,请重试.");
                        break;
                    default:
                        userToken = returnVal;
                        break;
                }
                if (!string.IsNullOrWhiteSpace(userToken))
                {
                    return Redirect("http://" + portalSetting.WebServerAddress + ":" + portalSetting.WebPort + (string.IsNullOrWhiteSpace(portalSetting.WebVirtualPath) ? "" : ("/" + portalSetting.WebVirtualPath)) + "/Account/TokenLogin?userName="******"&userToken=" + userToken);
                }
            }

            LoadSiteList();
            return View(model);
        }
示例#2
0
        public ActionResult ChangePassword(ChangePasswordModel model, int siteId)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    PortalSetting portalSetting = this.portalSettingMgr.GetPortalSetting(siteId);
                    SecurityService.SecurityService securityService = new SecurityService.SecurityService();
                    securityService.Url = ServiceURLHelper.ReplaceServiceUrl(securityService.Url, portalSetting.SIServerAddress, portalSetting.SIPort.ToString());
                    if (string.IsNullOrWhiteSpace(model.OldPassword))
                    {
                        throw new BusinessException(" 旧密码不能为空. ");
                    }
                    securityService.ChangePassword(model.UserCode, model.OldPassword,model.NewPassword);
                    User user = this.securityMgr.GetUser(model.UserCode);
                    Session.Add(WebConstants.UserSessionKey, user);
                    string userToken = securityService.VerifyUserPasswordAndGetUserToken(user.Code, model.NewPassword);

                    if (!string.IsNullOrWhiteSpace(userToken))
                    {
                        return Redirect("http://" + portalSetting.WebServerAddress + ":" + portalSetting.WebPort + (string.IsNullOrWhiteSpace(portalSetting.WebVirtualPath) ? "" : ("/" + portalSetting.WebVirtualPath)) + "/Account/TokenLogin?userName="******"&userToken=" + userToken);
                    }
                }
                catch (BusinessException ex)
                {
                    SaveBusinessExceptionMessage(ex);
                }
                catch (SoapException ex)
                {
                    SaveErrorMessage(ex.Actor);
                    //SaveBusinessExceptionMessage(ex);
                }
                catch(Exception ex)
                {
                    SaveErrorMessage(ex.Message);
                    //SaveBusinessExceptionMessage(ex);
                }
            }
            return View(model);
        }
示例#3
0
        public ActionResult RedirectSite(string siteId)
        {
            User user = SecurityContextHolder.Get();
            PortalSetting portalSetting = this.portalSettingMgr.GetPortalSetting(int.Parse(siteId));

            SecurityService.SecurityService securityService = new SecurityService.SecurityService();
            securityService.Url = ServiceURLHelper.ReplaceServiceUrl(securityService.Url, portalSetting.SIServerAddress, portalSetting.SIPort.ToString());

            string userToken = securityService.GenerateUserToken(user.Code);
            if (userToken == null)
            {
                return RedirectToAction("Default", "Main");
            }
            else
            {
                return Redirect("http://" + portalSetting.WebServerAddress + ":" + portalSetting.WebPort + (string.IsNullOrWhiteSpace(portalSetting.WebVirtualPath) ? "" : ("/" + portalSetting.WebVirtualPath)) + "/Account/TokenLogin?userName="******"&userToken=" + userToken);
            }
        }