Esempio n. 1
0
        /// <summary>
        /// Get a new token for the parametrized user
        /// </summary>
        /// <param name="user"></param>
        /// <returns></returns>
        public async Task <UserToken> GetNewTokenAsync(User user)
        {
            if (user == null)
            {
                throw new ArgumentNullException(nameof(user));
            }

            UserToken userToken = _userTokenRepository.GetByUser(user);

            if (userToken == null)
            {
                userToken = UserToken.Create(user, _appSettings.TokenExpirationInHours);
                _userTokenRepository.Add(userToken);
            }
            else
            {
                userToken.CreateToken(_appSettings.TokenExpirationInHours);
                _userTokenRepository.Update(userToken);
            }
            await _userTokenRepository.SaveChangesAsync();

            return(userToken);
        }