示例#1
0
        /// <summary>
        /// 获取token
        /// </summary>
        /// <param name="userinfo"></param>
        /// <returns></returns>
        public static TokenResultMsg GetSignToken(string staffId)
        {
            string tokenApi = AppSettingsConfig.GetTokenApi;
            Dictionary <string, string> parames = new Dictionary <string, string>();

            parames.Add("staffId", staffId);
            Tuple <string, string> parameters = GetQueryString(parames);
            TokenResultMsg         token      = WebApiHelper.Get <TokenResultMsg>(tokenApi, parameters.Item1, parameters.Item2, staffId, false);

            return(token);
        }
示例#2
0
        /// <summary>
        /// 获取token
        /// </summary>
        /// <returns></returns>
        public static TokenResultMsg GetSignToken(int staffId)
        {
            string tokenApi = AppSettingsConfig.GetTokenApi;
            Dictionary <string, string> parames = new Dictionary <string, string> {
                {
                    "staffId", staffId.ToString()
                }
            };
            Tuple <string, string> parameters = GetQueryString(parames);
            TokenResultMsg         token      = Get <TokenResultMsg>(tokenApi, parameters.Item1, parameters.Item2, staffId, false);

            return(token);
        }
        /// <summary>
        /// 验证
        /// </summary>
        /// <param name="actionContext"></param>
        /// <returns></returns>
        protected override bool IsAuthorized(HttpActionContext actionContext)
        {
            var ts = actionContext.Request.Headers.Where(c => c.Key.ToLower() == "token").FirstOrDefault().Value;

            if (ts != null && ts.Count() > 0)
            {
                var token = ts.First <string>();
                if (!TokenResultMsg.IsExistToken(token))
                {
                    return(false);
                }
                return(true);
            }
            if (actionContext.Request.Method == HttpMethod.Options)
            {
                return(true);
            }
            return(false);
        }
示例#4
0
文件: ServerApiTest.cs 项目: xgtz/EF2
        public void GetToken()
        {
            TokenResultMsg result = WebApiHelper.GetSignToken(ModuleId);

            Console.WriteLine(result.Data.ToString());
        }
示例#5
0
        public async Task <WebApiResult> Login([FromBody] LoginUser user)
        {
            IUserComponet   _userComponet = GrainClient.GrainFactory.GetGrain <IUserComponet>("key");
            ISysLogComponet logRep        = GrainClient.GrainFactory.GetGrain <ISysLogComponet>("key");
            string          username      = user.UserName;
            string          password      = user.Password;
            bool            IsRememberMe  = user.RemenberMe;

            if (string.IsNullOrEmpty(username) || string.IsNullOrEmpty(password))
            {
                return new WebApiResult
                       {
                           Code = Enuncode.Error
                       }
            }
            ;

            LoginUser u = null;

            var loginResult = await _userComponet.Login(username, password);

            if (loginResult.LoginResult == LoginResultEnum.Success)
            {
                u = loginResult.loginUser;

                var _tokens = TokenResultMsg.Createtoken(u.Id);


                //UserTokenManager.AddToken(ut);


                // 登录log

                var log = new Log()
                {
                    Action           = "Login",
                    Detail           = "会员登录:" + u.UserType + "|" + u.UserName,
                    CreateDate       = DateTime.Now,
                    CreatorLoginName = u.UserName,
                    IpAddress        = "127.0.0.1",
                    UserId           = 1
                };

                // await logRep.Add(log);
                Token = u.Id;
                var data = new
                {
                    id        = u.Id,
                    issaler   = u.IsSaler.HasValue ? u.IsSaler.Value : false,
                    username  = u.UserName,
                    token     = _tokens,
                    TargetUrl = $"Home/MainMenue"
                };
                return(new WebApiResult <dynamic>
                {
                    Code = Enuncode.Success,
                    Message = "Success",
                    Data = data
                });
            }

            if (loginResult.LoginResult == LoginResultEnum.UserNameUnExists)
            {
                return(new WebApiResult
                {
                    Code = Enuncode.Failed,
                    Message = "账号不存在",
                });
            }
            if (loginResult.LoginResult == LoginResultEnum.VerifyCodeError)
            {
                return(new WebApiResult
                {
                    Code = Enuncode.Failed,
                    Message = "验证码错误",
                });
            }
            if (loginResult.LoginResult == LoginResultEnum.UserNameOrPasswordError)
            {
                return(new WebApiResult
                {
                    Code = Enuncode.Failed,
                    Message = "账号密码错误",
                });
            }
            return(new WebApiResult
            {
                Code = Enuncode.Failed,
                Message = "登录失败,原因未知",
            });
        }