예제 #1
0
        public async Task <BaseModel <bool> > Logout(Guid userId, string token, string refreshToken)
        {
            BaseModel <bool> result = new BaseModel <bool>();

            try
            {
                var deleteResult = await _userRefreshTokens.DeleteOneAsync(u => u.RefreshToken == refreshToken);

                if (deleteResult.IsAcknowledged)
                {
                    InvalidToken invalidToken = new InvalidToken()
                    {
                        Token = token
                    };

                    await _invalidTokens.InsertOneAsync(invalidToken);

                    result.Data = true;
                }
                else
                {
                    throw new SystemException("Something went wrong while deleting access token.");
                }
            }
            catch (System.Exception)
            {
                throw new SystemException("Something went wrong while deleting access token.");
            }

            return(result);
        }
예제 #2
0
        public async Task <ActionResult> Logout()
        {
            try
            {
                string token = HttpContext.Request.Headers["authorization"].Single().Split(" ")[1];
                if (!(await _repository.ValidateToken(token)))
                {
                    return(Unauthorized());
                }

                InvalidToken  invalidToken = new InvalidToken();
                var           identity     = HttpContext.User.Identity as ClaimsIdentity;
                IList <Claim> claim        = identity.Claims.ToList();

                DateTime expirationDate = new DateTime(1970, 1, 1, 0, 0, 0, 0, System.DateTimeKind.Utc);
                expirationDate = expirationDate.AddSeconds(Double.Parse(claim[3].Value)).ToLocalTime();

                invalidToken.userId         = Int32.Parse(claim[0].Value);
                invalidToken.expirationDate = expirationDate;
                invalidToken.token          = token;

                await _repository.CreateInvalidToken(invalidToken);

                await _repository.SaveChanges();

                return(Ok());
            }
            catch (Exception)
            {
                return(new StatusCodeResult(StatusCodes.Status500InternalServerError));
            }
        }
예제 #3
0
        public void LexPreprocessor()
        {
            string[]     preprocessors = { "#define", "#undef", "#if", "#ifdef", "#ifndef", "#else", "#elif", "#endif", "#error", "#pragma", "#extension", "#version", "#line" };
            SyntaxType[] types         = { SyntaxType.DefinePreprocessorKeyword, SyntaxType.UndefinePreprocessorKeyword, SyntaxType.IfPreprocessorKeyword, SyntaxType.IfDefinedPreprocessorKeyword, SyntaxType.IfNotDefinedPreprocessorKeyword, SyntaxType.ElsePreprocessorKeyword, SyntaxType.ElseIfPreprocessorKeyword, SyntaxType.EndIfPreprocessorKeyword, SyntaxType.ErrorPreprocessorKeyword, SyntaxType.PragmaPreprocessorKeyword, SyntaxType.ExtensionPreprocessorKeyword, SyntaxType.VersionPreprocessorKeyword, SyntaxType.LinePreprocessorKeyword };

            GLSLLexer          lexer = new GLSLLexer();
            TextSource         source;
            LinkedList <Token> tokens;

            for (int i = 0; i < preprocessors.Length; i++)
            {
                source = new TextSource(preprocessors[i]);
                tokens = lexer.Run(source.CurrentSnapshot);

                Assert.AreEqual(2, tokens.Count);
                Assert.AreEqual(types[i], tokens.First.Value.SyntaxType);
            }

            source = new TextSource("#unknown");
            tokens = lexer.Run(source.CurrentSnapshot);

            Assert.AreEqual(2, tokens.Count);
            Assert.AreEqual(SyntaxType.InvalidToken, tokens.First.Value.SyntaxType);

            InvalidToken token = (InvalidToken)tokens.First.Value;

            Assert.AreEqual("#unknown", token.Text);
            Assert.AreEqual(SyntaxType.PreprocessorToken, token.ErrorType);
            Assert.AreEqual("#unknown is not a valid preprocessor", token.ErrorMessage);
        }
예제 #4
0
        public async Task <InvalidToken> CreateInvalidToken(InvalidToken invalidToken)
        {
            if (invalidToken == null)
            {
                throw new ArgumentNullException(nameof(invalidToken));
            }
            await _context.InvalidTokens.AddAsync(invalidToken);

            return(invalidToken);
        }
예제 #5
0
파일: Lexer.cs 프로젝트: srakowski/WeeC
        private static NextToken ReadToken(this IEnumerable <CodeCharacter> code)
        {
            code = code.SkipWhile(c => c.IsWhitespace);

            if (!code.Any())
            {
                var token = new EndOfFile();
                return(new NextToken(token, () => ReadToken(code)));
            }

            var firstTokenChar = code.First();

            if (firstTokenChar.IsStartOfIdentifier)
            {
                var identifier = code
                                 .TakeWhile(c => c.IsBodyOfIdentifier)
                                 .Aggregate("", (s, c) => s + c.Value);

                code = code.SkipWhile(c => c.IsBodyOfIdentifier);

                var token = KeywordTable.ContainsKey(identifier)
                    ? KeywordTable[identifier].Invoke() as Token
                    : new Identifier();

                token.Value        = identifier;
                token.LineNumber   = firstTokenChar.LineNumber;
                token.LinePosition = firstTokenChar.LinePosition;
                return(new NextToken(token, () => ReadToken(code)));
            }

            if (firstTokenChar.IsDigit)
            {
                var number = code
                             .TakeWhile(c => c.IsDigit)
                             .Aggregate("", (s, c) => s + c.Value);

                code = code.Skip(number.Length);

                var token = new IntegerConstant();
                token.Value        = number;
                token.LineNumber   = firstTokenChar.LineNumber;
                token.LinePosition = firstTokenChar.LinePosition;
                return(new NextToken(token, () => ReadToken(code)));
            }

            if (firstTokenChar.IsStartOfStringLiteral)
            {
                var stringLiteral = code
                                    .Skip(1)
                                    .TakeWhile(c => c.Value != '"')
                                    .Aggregate("\"", (s, c) => s + c.Value)
                                    + '"';

                Debug.WriteLine(stringLiteral);

                code = code.Skip(stringLiteral.Length);

                var token = new StringLiteral();
                token.Value        = stringLiteral;
                token.LineNumber   = firstTokenChar.LineNumber;
                token.LinePosition = firstTokenChar.LinePosition;
                return(new NextToken(token, () => ReadToken(code)));
            }

            var t = new InvalidToken() as Token;

            switch (firstTokenChar.Value)
            {
            case '(': t = new LeftParen(); break;

            case ')': t = new RightParen(); break;

            case '{': t = new LeftCurlyBrace(); break;

            case '}': t = new RightCurlyBrace(); break;

            case '[': t = new LeftSquareBracket(); break;

            case ']': t = new RightSquareBracket(); break;

            case ',': t = new Comma(); break;

            case '*': t = new Asterisk(); break;

            case ';': t = new Semicolon(); break;
            }

            code = code.Skip(1);

            t.Value        = firstTokenChar.Value.ToString();
            t.LineNumber   = firstTokenChar.LineNumber;
            t.LinePosition = firstTokenChar.LinePosition;
            return(new NextToken(t, () => ReadToken(code)));
        }