Exemplo n.º 1
0
        public bool TrySignIn(
            string email,
            string password,
            out AccessToken token)
        {
            if (email == null)
            {
                throw new ArgumentNullException(nameof(email));
            }
            if (password == null)
            {
                throw new ArgumentNullException(nameof(password));
            }

            User user = _usersRepository.GetByEmail(email);

            if (user == null || !user.IsPasswordValid(password))
            {
                token = null;
                return(false);
            }

            token = new AccessToken
            {
                ValidUntilValue = GetExprirationTime().UtcDateTime,
                Token           = Guid.NewGuid().ToString(),
                UserId          = user.Id,
            };

            _accessTokenRepository.Insert(token);
            _accessTokenRepository.SaveChanges();
            return(true);
        }
 public AccessToken Add(AccessToken model)
 {
     _accessTokenRepository.Insert(model);
     return(model);
 }