Exemplo n.º 1
0
        public ActionResult Login(LoginRequest request, string returnUrl)
        {
            if (ModelState.IsValid)
            {
                //if (ValidateUser(model.UserName, model.Password))
                if (request.LoginName.ToLower() == "admin")
                {
                    AuthenticationUserInfo authUserInfo = new AuthenticationUserInfo()//GetuserInfo(model.UserName);
                    {
                        ID       = "123456789",
                        UID      = "",
                        UserName = "******",
                        Roles    = "",
                    };
                    //if (userInfo.RoleName.ToLower() == "admin")
                    //{
                    //    role = "Admin";
                    //}

                    SecurityAuthentication.SetFormsAuthenticationTicket <AuthenticationUserInfo>(authUserInfo.ID, authUserInfo, TimeSpan.FromMinutes(20), true);

                    if (Url.IsLocalUrl(returnUrl) && returnUrl.Length > 1 && returnUrl.StartsWith("/") &&
                        !returnUrl.StartsWith("//") && !returnUrl.StartsWith("/\\"))
                    {
                        return(new RedirectResult(returnUrl));
                    }
                    else
                    {
                        return(new RedirectResult("~/"));
                    }
                }
                else
                {
                    ModelState.AddModelError("", "The user name or password provided is incorrect.");
                }
            }
            return(View(request));
        }
Exemplo n.º 2
0
        public ActionResult Header()
        {
            AuthenticationUserInfo authUserInfo = SecurityAuthentication.GetFormsAuthenticationTicket <AuthenticationUserInfo>("authUserInfo.ID");

            IEnumerable <MenuInfoViewModel> mainMenuList = new List <MenuInfoViewModel>()
            {
                new MenuInfoViewModel()
                {
                    MenuName = "动态信息"
                },
                new MenuInfoViewModel()
                {
                    MenuName = "用户管理"
                },
                new MenuInfoViewModel()
                {
                    MenuName = "商品管理"
                },
                new MenuInfoViewModel()
                {
                    MenuName = "订单管理"
                },
                new MenuInfoViewModel()
                {
                    MenuName = "报表管理"
                },
                new MenuInfoViewModel()
                {
                    MenuName = "系统管理"
                }
            };

            return(View(Tuple.Create(
                            authUserInfo, //Item1:AuthUserInfo
                            mainMenuList  //Item2:MemuInfoList
                            )));
        }
Exemplo n.º 3
0
        protected override bool AuthorizeCore(HttpContextBase httpContext)
        {
            if (httpContext.User.Identity.IsAuthenticated)
            {
                AuthenticationUserInfo authUserInfo = SecurityAuthentication.GetFormsAuthenticationTicket <AuthenticationUserInfo>("authUserInfo.ID");
                if (authUserInfo == null)
                {
                    return(false);
                }
                #region mm
                //                ApplicationSignInManager SignInManager = httpContext.GetOwinContext().Get<ApplicationSignInManager>();
                //                ApplicationUserManager UserManager = httpContext.GetOwinContext().GetUserManager<ApplicationUserManager>();
                //                string appid = string.Empty;
                //                string secret = string.Empty;


                //                appid = WxPayConfig.APPID;
                //                secret = WxPayConfig.APPSECRET;

                //                var code = httpContext.Request["Code"];
                //                string returnUrl = System.Web.HttpUtility.UrlDecode(httpContext.Request["ReturnUrl"] ?? "/");


                //                if (string.IsNullOrEmpty(code))
                //                {
                //                    string host = httpContext.Request.Url.Host;
                //                    string path = httpContext.Request.Path;
                //                    string redirectUrl = "http://" + host + path + "?ReturnUrl=" + System.Web.HttpUtility.UrlEncode(returnUrl);//重定向的url,这里不需要进行编码,在后面会自己编码
                //                    try
                //                    {
                //                        //todo:通过微信获取2.0授权的url
                //                        string url = Wechat.AuthorizeUrl(appid, redirectUrl, "state", "snsapi_base");

                //                        httpContext.Response.Redirect(url);
                //                    }
                //                    catch (System.Exception ex)
                //                    {
                //#if DEBUG
                //                        httpContext.Response.Write("构造网页授权获取code的URL时出错,错误是:" + ex.Message);
                //                        httpContext.Response.End();
                //#endif
                //                    }
                //                }
                //                else
                //                {
                //                    var client = new System.Net.WebClient();
                //                    client.Encoding = System.Text.Encoding.UTF8;
                //                    string url = Wechat.AccessTokenUrl(appid, secret, code);
                //                    var data = client.DownloadString(url);
                //                    var obj = JsonConvert.DeserializeObject<Dictionary<string, string>>(data);
                //                    string accessToken;
                //                    if (!obj.TryGetValue("access_token", out accessToken))
                //                    {
                //#if DEBUG
                //                        httpContext.Response.Write("构造网页授权获取access_token的URL时出错");
                //                        httpContext.Response.End();
                //#endif
                //                    }
                //                    var openid = obj["openid"];
                //                    Utils.WidgetCode.ServerInfo.SetCookies("WXopenid", openid, DateTime.MinValue);

                //                    var existUser = UserManager.Users.FirstOrDefault(p => p.OpenId == openid);
                //                    if (existUser != null)
                //                    {
                //                        SignInManager.SignInAsync(existUser, false, false);
                //                        httpContext.Response.Redirect(returnUrl);
                //                    }
                //                }
                #endregion
                return(true);
            }
            return(false);
        }