Beispiel #1
0
        public MaybeEmpty <BE.User> Get(long userId)
        {
            var user = new BE.User()
            {
                Id = 1, Password = "******"
            };

            return(MaybeEmpty <BE.User> .Of(user));
        }
Beispiel #2
0
        public MaybeEmpty <BE.SessionToken> Get()
        {
            var sessionToken = new BE.SessionToken
            {
                User     = null,
                Token    = "",
                ExpireAt = DateTime.Now,
            };

            return(MaybeEmpty <BE.SessionToken> .Of(sessionToken));
        }
Beispiel #3
0
        public MaybeEmpty <BE.SessionToken> GenerateToken(BE.User user)
        {
            var token        = GenerateToken(TokenSize, true);
            var sessionToken = new BE.SessionToken()
            {
                User = user, Token = token, Active = true
            };

            _storage.Save(sessionToken);
            return(MaybeEmpty <BE.SessionToken> .Of(sessionToken));
        }
Beispiel #4
0
        public static MaybeEmpty <T> ReadBody <T>(HttpListenerRequest req)
        {
            using var receiveStream = req.InputStream;
            using var readStream    = new StreamReader(receiveStream, Encoding.UTF8);
            var rawBody = readStream.ReadToEnd();

            try
            {
                var request = JsonSerializer.Deserialize <T>(rawBody);
                return(MaybeEmpty <T> .Of(request));
            }
            catch
            {
                return(MaybeEmpty <T> .Empty());
            }
        }