Exemplo n.º 1
0
        public ActionResult LogOn(LogOnModel model, string returnUrl)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    YnUser ynUser = AscmUserInfoService.GetInstance().TryGet(model.UserName);
                    /*
                    YnUser ynUser = YnUserService.GetInstance().Get(model.UserName);
                    if (ynUser == null)
                    {
                        //throw new Exception("用户不存在");
                        //判断是否erp用户
                        ynUser = YnUserService.GetInstance().Get("erp_"+model.UserName);
                        if (ynUser == null)
                        {
                            //判断是否mes用户
                        }
                    }
                    */
                    if (ynUser == null)
                    {
                        throw new Exception("用户不存在");
                    }
                    if (!string.IsNullOrEmpty(ynUser.extExpandType))
                    {
                        if (ynUser.extExpandType.Trim() == "erp")
                        {
                            //供应商登录显示供应商名称
                            AscmUserInfo ascmUserInfo = (AscmUserInfo)ynUser;
                            AscmUserInfoService.GetInstance().SetSupplier(ascmUserInfo);
                            if (ascmUserInfo.ascmSupplier != null)
                                ascmUserInfo.userName1 = ascmUserInfo.ascmSupplier.name;

                            if (!MembershipService.ValidateUser(ynUser.userId, model.Password))
                            {
                                if (Request.IsAjaxRequest())
                                {
                                    return Content("用户密码错误!");
                                }
                                //ModelState.AddModelError("", "提供的用户名或密码不正确。");
                                throw new Exception("提供的用户名或密码不正确。");
                            }
                        }
                        else if (ynUser.extExpandType.Trim() == "mes")
                        {
                            cn.com.midea.mespda.TransferService service = new cn.com.midea.mespda.TransferService();
                            cn.com.midea.mespda.OutputWebMessage message = service.UserLogin(model.UserName, model.Password);
                            if (!message.IsSuccess)
                            {
                                throw new Exception(message.ErrorMessage);
                            }
                        }
                    }
                    else
                    {
                        if (!MembershipService.ValidateUser(ynUser.userId, model.Password))
                        {
                            if (Request.IsAjaxRequest())
                            {
                                return Content("用户密码错误!");
                            }
                            //ModelState.AddModelError("", "提供的用户名或密码不正确。");
                            throw new Exception("提供的用户名或密码不正确。");
                        }
                    }

                    //HttpCookie cookie = Request.Cookies.Get("userName");
                    //Response.Cookies["userName"].Value = model.UserName;
                    string _userName = HttpUtility.UrlEncode(model.UserName);
                    Response.Cookies["userName"].Value = _userName;
                    Response.Cookies["userName"].Expires = DateTime.MaxValue;

                    int days = 0;
                    int iExpires = 0;
                    if (days > 0)
                        iExpires = 60 * 60 * 24 * days;//保存天数

                    //YnUser ynUser = YnUserService.GetInstance().Get(model.UserName);
                    FormsAuthenticationService.GetInstance().SignIn(ynUser.userId, 0, ynUser, true);
                    PageInit(null);
                    //this.ynSite.systemUser = true;//是系统用户
                    //this.ynSite.siteAdmin = YnUserService.GetInstance().IsSuperAdministrator(ynUser.userId) || YnUserService.GetInstance().IsAdministrator(ynUser.userId);
                    //this.ynSite.userName = ynUser.userName;//是系统用户
                    if (Request.IsAjaxRequest())
                    {
                        return JavaScript("document.location.href='';");
                    }
                    if (!String.IsNullOrEmpty(returnUrl))
                    {
                        return Redirect(returnUrl);
                    }
                    else
                    {
                        //return RedirectToAction("Index", "Home");
                        return RedirectToAction("YnFrame", "YnPublic");
                    }

                }
                catch (Exception ex)
                {
                    //throw ex;
                    ModelState.AddModelError("", ex.Message);
                }

            }

            // 如果我们进行到这一步时某个地方出错,则重新显示表单
            return View(model);
        }
Exemplo n.º 2
0
        /*[AcceptVerbs(HttpVerbs.Post)]*/
        public ActionResult LogOn(LogOnModel model, string returnUrl)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    YnUser ynUser = AscmUserInfoService.GetInstance().TryGet(model.UserName);

                    /*
                     * YnUser ynUser = YnUserService.GetInstance().Get(model.UserName);
                     * if (ynUser == null)
                     * {
                     *  //throw new Exception("用户不存在");
                     *  //判断是否erp用户
                     *  ynUser = YnUserService.GetInstance().Get("erp_"+model.UserName);
                     *  if (ynUser == null)
                     *  {
                     *      //判断是否mes用户
                     *  }
                     * }
                     */
                    if (ynUser == null)
                    {
                        throw new Exception("用户不存在");
                    }
                    if (!string.IsNullOrEmpty(ynUser.extExpandType))
                    {
                        if (ynUser.extExpandType.Trim() == "erp")
                        {
                            //供应商登录显示供应商名称
                            AscmUserInfo ascmUserInfo = (AscmUserInfo)ynUser;
                            AscmUserInfoService.GetInstance().SetSupplier(ascmUserInfo);
                            if (ascmUserInfo.ascmSupplier != null)
                            {
                                ascmUserInfo.userName1 = ascmUserInfo.ascmSupplier.name;
                            }

                            if (!MembershipService.ValidateUser(ynUser.userId, model.Password))
                            {
                                if (Request.IsAjaxRequest())
                                {
                                    return(Content("用户密码错误!"));
                                }
                                //ModelState.AddModelError("", "提供的用户名或密码不正确。");
                                throw new Exception("提供的用户名或密码不正确。");
                            }
                        }
                        else if (ynUser.extExpandType.Trim() == "mes")
                        {
                            cn.com.midea.mespda.TransferService  service = new cn.com.midea.mespda.TransferService();
                            cn.com.midea.mespda.OutputWebMessage message = service.UserLogin(model.UserName, model.Password);
                            if (!message.IsSuccess)
                            {
                                throw new Exception(message.ErrorMessage);
                            }
                        }
                    }
                    else
                    {
                        if (!MembershipService.ValidateUser(ynUser.userId, model.Password))
                        {
                            if (Request.IsAjaxRequest())
                            {
                                return(Content("用户密码错误!"));
                            }
                            //ModelState.AddModelError("", "提供的用户名或密码不正确。");
                            throw new Exception("提供的用户名或密码不正确。");
                        }
                    }

                    //HttpCookie cookie = Request.Cookies.Get("userName");
                    //Response.Cookies["userName"].Value = model.UserName;
                    string _userName = HttpUtility.UrlEncode(model.UserName);
                    Response.Cookies["userName"].Value   = _userName;
                    Response.Cookies["userName"].Expires = DateTime.MaxValue;

                    int days     = 0;
                    int iExpires = 0;
                    if (days > 0)
                    {
                        iExpires = 60 * 60 * 24 * days;//保存天数
                    }
                    //YnUser ynUser = YnUserService.GetInstance().Get(model.UserName);
                    FormsAuthenticationService.GetInstance().SignIn(ynUser.userId, 0, ynUser, true);
                    PageInit(null);
                    //this.ynSite.systemUser = true;//是系统用户
                    //this.ynSite.siteAdmin = YnUserService.GetInstance().IsSuperAdministrator(ynUser.userId) || YnUserService.GetInstance().IsAdministrator(ynUser.userId);
                    //this.ynSite.userName = ynUser.userName;//是系统用户
                    if (Request.IsAjaxRequest())
                    {
                        return(JavaScript("document.location.href='';"));
                    }
                    if (!String.IsNullOrEmpty(returnUrl))
                    {
                        return(Redirect(returnUrl));
                    }
                    else
                    {
                        //return RedirectToAction("Index", "Home");
                        return(RedirectToAction("YnFrame", "YnPublic"));
                    }
                }
                catch (Exception ex)
                {
                    //throw ex;
                    ModelState.AddModelError("", ex.Message);
                }
            }

            // 如果我们进行到这一步时某个地方出错,则重新显示表单
            return(View(model));
        }