Example #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));
        }
Example #2
0
        //-------------------------------------------------------------------------
        void _onUCenterGuestAccess(UCenterResponseStatus status, GuestAccessResponse response, UCenterError error)
        {
            EbLog.Note("ClientSampleApp._onUCenterGuestLogin() UCenterResult=" + status);

            if (error != null)
            {
                EbLog.Note("ErrorCode=" + error.ErrorCode);
                EbLog.Note("ErrorMessage=" + error.Message);
            }
            else
            {
                EbLog.Note("AccountId=" + response.AccountId);
                EbLog.Note("AccountName=" + response.AccountName);
            }
        }