Пример #1
0
        public bool ProcessRequest(IServiceContext context)
        {
            this.currentContext = context;

            if (context.Request.MethodName.Substring(0, 5) == "Login")
            {
                this.User           = new UserModel();
                this.User.LoginName = (string)context.Request.Parameters[0];
                this.User.LoginPwd  = (string)context.Request.Parameters[1];
                //Login2 方法为加密的登陆方法
                if (context.Request.MethodName == "Login2")
                {
                    this.User.LoginName = EncryptHelper.DesDecrypt(this.User.LoginName);
                    this.User.LoginPwd  = EncryptHelper.DesDecrypt(this.User.LoginPwd);
                }

                UserLoginInfoModel result = Login();
                if (result.LoginResult)
                {
                    //分配服务地址
                    DispatchService disp = new DispatchService();
                    disp.CurrentContext = context;
                    ServiceRegModel server = disp.DoDispatch();
                    //在外网测试有问提,暂时屏蔽 2012.5.24
                    result.ServiceUri = server.GetUri();

                    //如果登录成功,设置登录凭据
                    ServiceIdentity newUser = new ServiceIdentity();
                    newUser.Id              = result.User.UserID;
                    newUser.Name            = result.User.LoginName;
                    newUser.Expire          = new TimeSpan(0, 0, 20); //20秒过期,客户端必须订阅CheckUserIdentity 方法
                    newUser.IsAuthenticated = true;
                    newUser.Uri             = result.ServiceUri;
                    System.Diagnostics.Debug.WriteLine("--------------newUser.Uri={0} ; Client IP:{1}", newUser.Uri, context.Request.ClientIP);

                    ServiceAuthentication auth = new ServiceAuthentication(context);
                    //如果相同的用户账号已经在别的机器登录过,则取消之前的登录凭据
                    ServiceIdentity oldUser = auth.FindIdentity(newUser);
                    if (oldUser != null)
                    {
                        auth.SignOut(oldUser);
                    }

                    auth.Authenticate(newUser);
                }
                context.Response.WriteJsonString(result);

                return(false);
            }
            context.SessionRequired = true;
            return(true);
        }
Пример #2
0
        /// <summary>
        /// 注销登录
        /// </summary>
        /// <returns></returns>
        public bool Logout()
        {
            ServiceAuthentication auth = new ServiceAuthentication(this.currentContext);
            ServiceIdentity       user = auth.GetIdentity();

            if (user != null)
            {
                UserBIZ biz = new UserBIZ();
                biz.SaveLogoutLog(user.Id);
                return(auth.SignOut(user));
            }
            return(false);
        }