示例#1
0
        public ActionResult SignOut()
        {
            FormsAuthentication.SignOut();

            #region remove all sessions and token cookie
            Session.RemoveAll();

            if (Request.Cookies[FormsAuthentication.FormsCookieName] != null)
            {
                CookiesHelper.RemoveCookiesByCookieskey(Request, Response, FormsAuthentication.FormsCookieName);
            }
            #endregion

            CacheHelper.Clear();

            return(RedirectToAction("Index", "Login"));
        }
示例#2
0
        public ActionResult SignIn(LoginUserMoel loginUser, string returnUrl)
        {
            HttpResponseMessage responMessage;
            var apiPath = ConfigurationManager.AppSettings["WebApiPath"].ToString();

            using (var client = new HttpClient())
            {
                var content = new StringContent(JsonConvert.SerializeObject(loginUser));
                content.Headers.ContentType = new MediaTypeHeaderValue("application/json");
                responMessage = client.PostAsync(apiPath + "Login/LoginIn", content).Result;
            }

            if (responMessage.IsSuccessStatusCode)
            {
                var user = JsonConvert.DeserializeObject <AuthorizedLoginUser>(responMessage.Content.ReadAsStringAsync().Result);

                #region put token/user info into Cookie and Session and SetAuthCookie make Identity true
                if (Request.Cookies[SessionConstants.LoginTicket] != null)
                {
                    CookiesHelper.RemoveCookiesByCookieskey(Request, Response, SessionConstants.LoginTicket);
                    CookiesHelper.RemoveCookiesByCookieskey(Request, Response, SessionConstants.CurrentAccountUID);
                    CookiesHelper.RemoveCookiesByCookieskey(Request, Response, SessionConstants.CurrentUserName);
                }
                else
                {
                    CookiesHelper.AddCookies(Response, SessionConstants.LoginTicket, user.Token, 1);
                    CookiesHelper.AddCookies(Response, SessionConstants.CurrentAccountUID, user.Account_UID.ToString(), 1);
                    CookiesHelper.AddCookies(Response, SessionConstants.CurrentUserName, user.User_Name, 1);
                }


                if (Request.Cookies["APIPath"] == null)
                {
                    CookiesHelper.AddCookies(Response, "APIPath", apiPath, 1);
                }

                FormsAuthentication.SetAuthCookie(loginUser.UserName, false);

                SetLogon(user);

                #endregion

                //get ticket of login user
                //var ticket = FormsAuthentication.Decrypt(user.Token);

                //set principal
                //IIdentity identity = new FormsIdentity(ticket);
                //IPrincipal principal = new GenericPrincipal(identity, null);
                //HttpContext.User = principal;
                if (user.RoleList != null && user.RoleList.Exists(x => x.Role_ID == "PlayBoardPlayUser"))  //.User_Name.Contains("播放看板")
                {
                    //硬编码的角色Role_ID,这个角色免密码登录,直接显示播放看板
                    //PlayBoardPlayUser 播放看板播放账号
                    return(RedirectToAction("Index", "PlayBoard", new { playUserUID = user.Account_UID }));
                }
                if (user.User_Name.Contains("电子看板"))
                {
                    return(RedirectToAction("Index", "Board"));
                }

                //如果用户是物料员则跳转到生成数据维护画面,如果不是则到导航画面
                if (user.MH_Flag)
                {
                    if (user.IsMulitProject)
                    {
                        Session[SessionConstants.MHFlag_MulitProject] = user.IsMulitProject;

                        return(RedirectToAction("ProjectList", "FlowChart"));
                    }
                    else if (user.USER_Ntid == "EQPUser")
                    {
                        return(RedirectToAction("EQPMaintenance", "Equipmentmaintenance", new { iseqp_user = "******" }));
                    }
                    else
                    {
                        var master_Uid = user.flowChartMaster_Uid;
                        if (master_Uid == null)
                        {
                            return(RedirectToAction("Index", "Home"));
                        }
                        else
                        {
                            return(RedirectToAction("ProductData", "ProductInput", new { flowChartMaster_Uid = master_Uid }));
                        }
                    }
                }
                else
                {
                    return(RedirectToAction("Index", "Home"));
                }
            }
            else
            {
                ViewBag.InvalidCode = string.Empty;

                switch (responMessage.StatusCode)
                {
                case HttpStatusCode.Forbidden:
                    ViewBag.InvalidCode = "ACCOUNTNOTENABLED";
                    break;

                case HttpStatusCode.NotFound:
                    ViewBag.InvalidCode = "ACCOUNTNOTEXIST";
                    break;

                case HttpStatusCode.Unauthorized:
                    ViewBag.InvalidCode = "WRONGPASSWORD";
                    break;

                case HttpStatusCode.InternalServerError:
                    throw new Exception("API Server Error");

                default:
                    break;
                }

                return(View("Index"));
            }
        }