Ejemplo n.º 1
0
        public async Task <IActionResult> GuestAccess([FromBody] GuestAccessInfo info, CancellationToken token)
        {
            if (info == null)
            {
                throw new UCenterException(UCenterErrorCode.DeviceInfoNull);
            }

            if (string.IsNullOrEmpty(info.AppId))
            {
                throw new UCenterException(UCenterErrorCode.DeviceInfoNull);
            }

            EnsureDeviceInfo(info.Device);

            AccountEntity accountEntity;
            string        guestDeviceId     = $"{info.AppId}_{info.Device.Id}";
            var           guestDeviceEntity = await this.Database.GuestDevices.GetSingleAsync(guestDeviceId, token);

            if (guestDeviceEntity == null)
            {
                accountEntity = new AccountEntity()
                {
                    Id            = Guid.NewGuid().ToString(),
                    AccountName   = Guid.NewGuid().ToString(),
                    AccountType   = AccountType.Guest,
                    AccountStatus = AccountStatus.Active,
                    Token         = EncryptHashManager.GenerateToken()
                };
                await this.Database.Accounts.InsertAsync(accountEntity, token);

                guestDeviceEntity = new GuestDeviceEntity()
                {
                    Id        = $"{info.AppId}_{info.Device.Id}",
                    AccountId = accountEntity.Id,
                    AppId     = info.AppId,
                    Device    = info.Device
                };
                await this.Database.GuestDevices.InsertAsync(guestDeviceEntity, token);

                await this.TraceAccountEvent(accountEntity, "GuestRegister", info.Device, token : token);
            }
            else
            {
                accountEntity = await this.Database.Accounts.GetSingleAsync(guestDeviceEntity.AccountId, token);

                await this.TraceAccountEvent(accountEntity, "GuestLogin", info.Device, token : token);
            }

            await LogDeviceInfo(info.Device, token);

            var response = new GuestAccessResponse
            {
                AccountId   = accountEntity.Id,
                AccountName = accountEntity.AccountName,
                AccountType = accountEntity.AccountType,
                Token       = accountEntity.Token
            };

            return(this.CreateSuccessResult(response));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Login guest account.
        /// </summary>
        /// <param name="info">Indicating the account device information.</param>
        /// <returns>Async response.</returns>
        public async Task <GuestAccessResponse> GuestAccessAsync(GuestAccessInfo info)
        {
            var url      = this.GenerateApiEndpoint("accounts", "guestaccess");
            var response = await this.httpClient.SendAsyncWithException <GuestAccessInfo, GuestAccessResponse>(
                HttpMethod.Post,
                url,
                info);

            return(response);
        }
Ejemplo n.º 3
0
        //-------------------------------------------------------------------------
        public void guestAccess(GuestAccessInfo request, OnUCenterGuestAccess handler)
        {
            if (WWWGuestAccess != null)
            {
                return;
            }

            GuestAccessHandler = new Action <UCenterResponseStatus, GuestAccessResponse, UCenterError>(handler);

            string http_url = _genUrl("guestaccess");

            string param = EbTool.jsonSerialize(request);

            byte[] bytes = Encoding.UTF8.GetBytes(param);

            Dictionary <string, string> headers = _genHeader(bytes.Length);

            WWWGuestAccess = new WWW(http_url, bytes, headers);
        }
        public async Task E2E_AppClient_GuestAccess_And_Convert_Test()
        {
            var guestAccessInfo = new GuestAccessInfo()
            {
                AppId  = TestAppId,
                Device = TestDevice
            };
            var guestAccessResponse = await acClient.GuestAccessAsync(guestAccessInfo);

            Assert.IsNotNull(guestAccessResponse.AccountId);
            Assert.IsNotNull(guestAccessResponse.AccountName);
            Assert.AreEqual(guestAccessResponse.AccountType, AccountType.Guest);
            Assert.IsNotNull(guestAccessResponse.Token);

            var convertInfo = new GuestConvertInfo
            {
                AppId         = TestAppId,
                AccountId     = guestAccessResponse.AccountId,
                AccountName   = $"account.{GenerateRandomString()}",
                Password      = ValidAccountPassword,
                SuperPassword = ValidAccountPassword,
                Name          = GenerateRandomString(),
                Phone         = GenerateRandomString(),
                Email         = GenerateRandomString(),
                Identity      = GenerateRandomString(),
                Gender        = Gender.Female
            };

            var convertResponse = await acClient.GuestConvertAsync(convertInfo);

            Assert.IsNotNull(convertResponse.AccountId);
            Assert.IsNotNull(convertResponse.AccountId, convertInfo.AccountId);
            Assert.AreEqual(convertResponse.AccountName, convertInfo.AccountName);
            Assert.AreEqual(convertResponse.AccountType, AccountType.NormalAccount);
            Assert.AreEqual(convertResponse.AccountStatus, AccountStatus.Active);
            Assert.AreEqual(convertResponse.Identity, convertInfo.Identity);
            Assert.AreEqual(convertResponse.Name, convertInfo.Name);
            Assert.AreEqual(convertResponse.Phone, convertInfo.Phone);
            Assert.AreEqual(convertResponse.Email, convertInfo.Email);
            Assert.AreEqual(convertResponse.Gender, convertInfo.Gender);
        }
Ejemplo n.º 5
0
        //-------------------------------------------------------------------------
        public override void init()
        {
            EbLog.Note("ClientSampleApp.init()");

            EntityMgr.getDefaultEventPublisher().addHandler(Entity);

            // EtUCenterSDK示例
            var et_ucentersdk = EntityMgr.createEntity <EtUCenterSDK>(null, Entity);
            var co_ucentersdk = et_ucentersdk.getComponent <ClientUCenterSDK <DefUCenterSDK> >();

            //co_ucentersdk.UCenterDomain = "http://ucenter.playql.com/";
            co_ucentersdk.UCenterDomain = "http://ucenterdev.cragon.cn";

            // 获取Ip所在地
            //co_ucentersdk.getIpAddress(_onUCenterGetIpAddress);

            // 获取AppConfig
            //co_ucentersdk.getAppConfig("texaspoker", _onUCenterGetAppConfig);

            // 注册
            AccountRegisterInfo register_request = new AccountRegisterInfo();

            register_request.AccountName   = "aaaaabbbb";
            register_request.Password      = "******";
            register_request.SuperPassword = "******";
            //co_ucentersdk.register(register_request, _onUCenterRegister);

            // 登录
            AccountLoginInfo login_request = new AccountLoginInfo();

            login_request.AccountName = "lion";
            login_request.Password    = "******";
            login_request.Device      = _getDeviceInfo();
            //co_ucentersdk.login(login_request, _onUCenterLogin);

            // 游客登录
            GuestAccessInfo guestAccessInfo = new GuestAccessInfo()
            {
                AppId  = "fishing",
                Device = new DeviceInfo()
                {
                    Id = "U3DSample",
                }
            };

            co_ucentersdk.guestAccess(guestAccessInfo, _onUCenterGuestAccess);

            // 游客帐号转正
            //GuestConvertInfo convert_info = new GuestConvertInfo();
            //convert_info.AccountId = "dc798b4a-e43d-447f-896e-beba9439e3d0";
            //convert_info.AccountName = "sample_user";
            //convert_info.Password = "";
            //convert_info.SuperPassword = "";
            //convert_info.Gender = Gender.DeclineToState;
            //convert_info.Name = "";
            //convert_info.Identity = "";
            //convert_info.Phone = "";
            //convert_info.Email = "";
            //co_ucentersdk.guestConvert(convert_info, _onUCenterConvert);

            // 重置密码
            AccountResetPasswordInfo resetpassword_request = new AccountResetPasswordInfo();

            login_request.AccountName = "aaaaabbbb";
            login_request.Password    = "******";
            //co_ucentersdk.resetPassword(resetpassword_request, _onUCenterResetPassword);

            // 上传图片
            //string account_id = "8402633f-d6b0-4f13-9348-594f350d266b";
            //byte[] buffer = new byte[100];
            //MemoryStream ms = new MemoryStream(buffer);
            //co_ucentersdk.uploadProfileImage(account_id, ms, _onUCenterUploadProfileImage);
        }