Ejemplo n.º 1
0
        public static Token RefreshToken(string Token)
        {
            Token t = _tokenRepository.FindBy(x => x.TokenString == Token && x.IsDeleted == false && x.ValidTo > System.DateTime.Now).FirstOrDefault();

            if (!IsTokenExpired(t))
            {
                t.ValidTo = System.DateTime.Now.AddHours(8);
                _tokenRepository.Edit(t);
                _tokenRepository.Save();
                return(t);
            }
            return(CreateToken(t.ObjectUser, t.DeviceName));
        }
Ejemplo n.º 2
0
        public IDtoOutObjects Logout(DtoInLogout dtoInLogout)
        {
            DtoOutError error = new DtoOutError();

            if (TokenTools.Authentication(dtoInLogout.Token, dtoInLogout.DeviceName))
            {
                Token token = TokenTools.getTokenObjectFromString(dtoInLogout.Token);
                token.IsDeleted = true;
                tokensRepository.Edit(token);
                tokensRepository.Save();
                var         config      = new MapperConfiguration(cfg => { cfg.CreateMap <Token, DtoOutToken>(); });
                IMapper     mapper      = config.CreateMapper();
                DtoOutToken dtoOutToken = new DtoOutToken();
                mapper.Map(token, dtoOutToken);
                return(dtoOutToken);
            }
            else
            {
                NotAuthenticatedException ex = new NotAuthenticatedException();
                error.Exception = ex;
                return(error);
            }
        }