示例#1
0
        public async Task <string> GenerateAnonymousUserId(HttpResponse response)
        {
            var user = new AnonymousUser();
            await _anonymousUsersRepository.Create(user);

            await Context.SaveChangesAsync();

            var userId = user.Id.ToString();
            var token  = AnonymousUsersService.GenerateTokenFromUserId(userId);

            response.Cookies.Append("anonymous_user_id_token", token);
            return(userId);
        }
示例#2
0
        public async Task <string> GetAnonymousUserId(HttpRequest request)
        {
            var tokenString = request.Cookies["anonymous_user_id_token"];

            if (string.IsNullOrEmpty(tokenString))
            {
                return(null);
            }

            var userId = AnonymousUsersService.GetUserId(tokenString);

            if (string.IsNullOrEmpty(userId))
            {
                return("");
            }
            var userGuid = Guid.Parse(userId);
            var exist    = await _anonymousUsersRepository.ExistAsync(userGuid);

            return(exist ? userId : "");
        }