<commit_before>class App < Sinatra::Base
  register Sinatra::Namespace

  # Begin users namespace
  namespace '/users' do
    def validate_body_for_create_user
      begin
        required_fields = {"required" => ["email", "first_name", "last_name", "role"]}
        schema = User::SCHEMA.merge(required_fields)
        JSON::Validator.validate!(schema, body_params)
      rescue Exception => e
        give_error(400, ERROR_INVALID_BODY, "The body is not valid.").to_json
      end
    end

    # Create new user
    post '/?' do
      validate_body_for_create_user
      user = case body_params["role"].downcase
      when "blind"
        Blind.new
      when "helper"
        Helper.new
      else
        give_error(400, ERROR_UNDEFINED_ROLE, "Undefined role.").to_json
      end
      if !body_params['password'].nil?
        password = <PASSWORD>_password(body_params['password'])
        user.update_attributes body_params.merge({ "password" => password })
      elsif !body_params['user_id'].nil?
        user.update_attributes body_params.merge({ "user_id" => body_params['user_id'] })
        user.is_external_user = true
      else
        give_error(400, ERROR_INVALID_BODY, "Missing parameter 'user_id' for registering a Facebook user or parameter 'password' for registering a regular user.").to_json
      end
      begin
        user.save!
        user.reload
      rescue Exception => e
        give_error(400, ERROR_USER_EMAIL_ALREADY_REGISTERED, "The e-mail is already registered.").to_json if e.message.match /email/i
      end
      EventBus.announce(:user_created, user_id: user.id)
      return user.to_json
    end

   

    # Get user by id
    get '/:user_id' do<commit_msg>log user in on creation<commit_after>class App < Sinatra::Base
  register Sinatra::Namespace

  # Begin users namespace
  namespace '/users' do
    def validate_body_for_create_user
      begin
        required_fields = {"required" => ["email", "first_name", "last_name", "role"]}
        schema = User::SCHEMA.merge(required_fields)
        JSON::Validator.validate!(schema, body_params)
      rescue Exception => e
        give_error(400, ERROR_INVALID_BODY, "The body is not valid.").to_json
      end
    end

    # Create new user
    post '/?' do
      validate_body_for_create_user
      user = case body_params["role"].downcase
      when "blind"
        Blind.new
      when "helper"
        Helper.new
      else
        give_error(400, ERROR_UNDEFINED_ROLE, "Undefined role.").to_json
      end
      if !body_params['password'].nil?
        password = <PASSWORD>_password(body_params['password'])
        user.update_attributes body_params.merge({ "password" => password })
      elsif !body_params['user_id'].nil?
        user.update_attributes body_params.merge({ "user_id" => body_params['user_id'] })
        user.is_external_user = true
      else
        give_error(400, ERROR_INVALID_BODY, "Missing parameter 'user_id' for registering a Facebook user or parameter 'password' for registering a regular user.").to_json
      end
      begin
        user.save!
        user.reset_expiry_time
        user.reload
      rescue Exception => e
        give_error(400, ERROR_USER_EMAIL_ALREADY_REGISTERED, "The e-mail is already registered.").to_json if e.message.match /email/i
      end
      EventBus.announce(:user_created, user_id: user.id)
      return user.to_json
    end

    # Get user by id
    get '/:user_id' do
{'fraction_non_alphanumeric': 0.10046592894583577, 'fraction_numerical': 0.006988934187536401, 'mean_word_length': 2.8422818791946307, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '179559', 'n_tokens_mistral': 1063, 'n_tokens_neox': 1020, 'n_words': 250}