Beispiel #1
0
        public async Task TestMethod1()
        {
            var token = DESEncrypt.Encrypt(string.Format("{0}{1}", Guid.NewGuid().ToString("D"), DateTime.Now.Ticks));

            token = token.Substring(11, 31);
            var TX     = Guid.NewGuid().ToString("D").Substring(0, 10);
            var config = ClientConfiguration.LocalhostSilo();

            GrainClient.Initialize(config);
            var userService = GrainClient.GrainFactory.GetGrain <ITest>("key");
            //var response = await userService.GetTicksFromService() ;
            // var response = await userService.Login("123", "123");
            var tol = await userService.Holle();

            var tolp = await userService.GetName();

            IUserComponet user = GrainClient.GrainFactory.GetGrain <IUserComponet>("ke");
            //var response = await userService.GetTicksFromService() ;
            //  var response = await userService.Login("123", "123");
            LoginUser loginUser = null;
            var       tol0      = await user.Login("test", "test");

            if (tol0.LoginResult == Base.Info.Enums.LoginResultEnum.Success)
            {
                user.CreataToken(new Manager.Model.Model.TokenInfo()
                {
                    ExpiryTime = DateTime.Now.AddMinutes(2), SingToken = token, UserInfoId = tol0.ResultloginUser.Id
                }).Wait();
            }
        }
        public async Task <string> Login()
        {
            IUserComponet   _userComponet = GrainClient.GrainFactory.GetGrain <IUserComponet>("key");
            ISysLogComponet logRep        = GrainClient.GrainFactory.GetGrain <ISysLogComponet>("key");
            var             mx            = await _userComponet.Login("123", "123");

            return("OK");
        }
        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 = "登录失败,原因未知",
            });
        }