<commit_before>require File.expand_path 'app/auth/auth.rb'
require File.expand_path 'app/api/errors.rb'
require 'yodatra/crypto'

class PublicController < Yodatra::Base

  before do
    content_type 'application/json'
  end

  get '/' do
    "hello world".to_json
  end

  put '/login' do
    @one = User.find_by_email(params[:identifier])

    if @one.nil?
      status 400
      halt [Errors::LOGIN_FAIL].to_json
    end

    salt2 = Auth.generate_token(@one.email, @one.pbkdf)
    {:salt1 => @one.salt.unpack('H*').first, :salt2 => salt2.unpack('H*').first}.to_json
  end

  post %r{/register|/user} do
    if params[:password].nil?
      status 400
      halt [Errors::NO_PASSWORD_PROVIDED].to_json
    end

    salt, pbkdf = Yodatra::Crypto.generate_pbkdf(params[:password])
    @one = User.new :email => params[:identifier], :pbkdf => pbkdf, :salt => salt

    if @one.save
      @one.as_json(:except => [:pbkdf, :salt]).to_json
    else
      status 400
      @one.errors.full_messages.to_json
    end
  end



end<commit_msg>Be more flexible in the register/ action for the email field<commit_after>require File.expand_path 'app/auth/auth.rb'
require File.expand_path 'app/api/errors.rb'
require 'yodatra/crypto'

class PublicController < Yodatra::Base

  before do
    content_type 'application/json'
  end

  get '/' do
    "hello world".to_json
  end

  put '/login' do
    @one = User.find_by_email(params[:identifier])

    if @one.nil?
      status 400
      halt [Errors::LOGIN_FAIL].to_json
    end

    salt2 = Auth.generate_token(@one.email, @one.pbkdf)
    {:salt1 => @one.salt.unpack('H*').first, :salt2 => salt2.unpack('H*').first}.to_json
  end

  post %r{/register|/user} do
    if params[:password].nil?
      status 400
      halt [Errors::NO_PASSWORD_PROVIDED].to_json
    end

    salt, pbkdf = Yodatra::Crypto.generate_pbkdf(params[:password])
    @one = User.new :email => params[:identifier]||params[:email], :pbkdf => pbkdf, :salt => salt

    if @one.save
      @one.as_json(:except => [:pbkdf, :salt]).to_json
    else
      status 400
      @one.errors.full_messages.to_json
    end
  end



end
{'fraction_non_alphanumeric': 0.13997181775481446, 'fraction_numerical': 0.012212306247064349, 'mean_word_length': 3.1929133858267718, 'pattern_counts': {'":': 0, '<': 5, '<?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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7571544', 'n_tokens_mistral': 805, 'n_tokens_neox': 756, 'n_words': 157}