Пример #1
0
        public async Task <IActionResult> Index([FromQuery(Name = "access_token")] string accessToken)
        {
            IActionResult result;

            if (accessToken != null)
            {
                var token = await _dbContext.AccessTokens.SingleOrDefaultAsync(t => t.Token == accessToken);

                if (token != null)
                {
                    _dbContext.Remove(token);
                    await _dbContext.SaveChangesAsync();

                    result = Ok(new object());
                }
                else
                {
                    result = NotFound();
                }
            }
            else
            {
                result = Unauthorized();
            }

            return(result);
        }
Пример #2
0
        public async Task <UserInteractiveAuthResponseBase> CreateGuestAccountAsync()
        {
            const string homeServer = "peykon.ga";
            await Task.Delay(1);

            string userName;
            bool   userIdExists;

            do
            {
                userName     = GenerateAlphanumericString(10);
                userIdExists =
                    await _dbContext.Users.AnyAsync(u => u.Name.Equals(userName, StringComparison.OrdinalIgnoreCase));
            } while (userIdExists);

            var guestUser = new User
            {
                Name = userName,
                Kind = UserAccountKind.Guest,
            };

            _dbContext.Add(guestUser);
            _dbContext.AccessTokens.Add(new AccessToken
            {
                User     = guestUser,
                DeviceId = "guest_device",
                Token    = GenerateAlphanumericString(256),
            });
            await _dbContext.SaveChangesAsync();

            var resposne = new RegisterResponse
            {
                AccessToken = guestUser.AccessTokens.Single().Token,
                HomeServer  = homeServer,
                UserId      = $"@{guestUser.Name}:{homeServer}",
                DeviceId    = guestUser.AccessTokens.Single().DeviceId,
            };

            return(resposne);
        }