<commit_before>require 'sinatra/base'

class User
  attr_accessor :name, :uid, :email, :jwt, :role, :orcid

  def initialize(jwt)
    public_key = OpenSSL::PKey::RSA.new(ENV['JWT_PUBLIC_KEY'].to_s.gsub('\n', "\n"))
    jwt_hsh = JWT.decode(jwt, public_key, true, { :algorithm => 'RS256' }).first

    @jwt = jwt
    @uid = jwt_hsh.fetch("uid", nil)
    @name = jwt_hsh.fetch("name", nil)
    @email = jwt_hsh.fetch("email", nil)
    @role = jwt_hsh.fetch("role", nil)
  end

  alias_method :orcid, :uid

  # Helper method to check for admin user
  def is_admin?
    role == "admin"
  end<commit_msg>check for expired jwt token. datacite/datacite#158<commit_after>require 'sinatra/base'

class User
  attr_accessor :name, :uid, :email, :jwt, :role, :orcid

  def initialize(jwt)
    return false unless jwt.present?

    # decode token using SHA-256 hash algorithm
    public_key = OpenSSL::PKey::RSA.new(ENV['JWT_PUBLIC_KEY'].to_s.gsub('\n', "\n"))
    jwt_hsh = JWT.decode(jwt, public_key, true, { :algorithm => 'RS256' }).first

    # check whether token has expired
    return false unless Time.now.to_i < jwt_hsh["exp"]

    @jwt = jwt
    @uid = jwt_hsh.fetch("uid", nil)
    @name = jwt_hsh.fetch("name", nil)
    @email = jwt_hsh.fetch("email", nil)
    @role = jwt_hsh.fetch("role", nil)
  end
  
  alias_method :orcid, :uid

  # Helper method to check for admin user
  def is_admin?
    role == "admin"
  end
{'fraction_non_alphanumeric': 0.15172900494001412, 'fraction_numerical': 0.008468595624558928, 'mean_word_length': 3.6188925081433223, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6662925', 'n_tokens_mistral': 571, 'n_tokens_neox': 549, 'n_words': 130}