<commit_before>class PaywallController < ApplicationController
  require 'securerandom'
  def login
    if(params.has_key?'email')
      user= User.find_by_email(params['email'])
      if(user.present?)
        cred= user.credential
        if(cred.present?)
          if(cred.password== params['password'])
            session[:user_id] = user.id;
            redirect_to :action => 'settings'
          end
        end
      end
    end
  end

  def home
    id = session[:user_id].to_i;
    if(id===0)
      redirect_to :action => 'login'
    else
    user = User.find(id);
    @mail = user.email
    end
  end
  def whitelist
    @user= User.new
    id = session[:user_id].to_i;
    @id=id
    if(id===0)
      redirect_to :action => 'login'
    else
      @user = User.find(id);
      @mail = @user.email
    end
  end
  def whitelist_delete
    logger.debug params.inspect
    @id = params['whitelist']['id']
    Whitelist.all.destroy(@id)
    respond_to do |format|
      format.js   { render :template => 'paywall/delete_list.js.erb' }
    end
  end
  def whitelist_add
    logger.debug params.inspect
    email = params['whitelist']['email'];
    @w = Whitelist.new
    @w.email = email;
    id = params['whitelist']['id'].to_i;
    user = User.find(id)
    user.whitelists << @w
    @w.save
    user.save
    respond_to do |format|
      format.js   { render :template => 'paywall/add_list.js.erb' }
    end
  end
  def settings
    @user= User.new
    id = session[:user_id].to_i;
    @id=id
    if(id===0)
      redirect_to :action => 'login'
    else
      @user = User.find(id);
      @mail = @user.email
    end
  end
  def logout
    reset_session
    redirect_to :action => 'login'
  end

  def update_user
    id = params['user']['id'].to_i;
    @user = User.find(id)
    #@user.email = params['user']['email']
    @user.BTC_address = params['user']['name']
    @user.reward = params['user']['reward'].to_f
    @user.save
    respond_to do |format|
      format.js   { render :template => 'paywall/user_update' }
    end
  end

  def transactions
    id = session[:user_id].to_i;
    if(id===0)
      redirect_to :action => 'login'
    else
      @user = User.find(id);
      @mail = @user.email
    end
  end
  def register
    @notif = "";
    if(params.has_key?'email');
      user = User.new;
      cred = Credential.new;
      user.email = params['email'];
      flt = params['reward'];
      flt = flt.to_f;
      user.reward = flt;
      cred.username = user.email.split('@').first;
      cred.password = <PASSWORD>(10);
      user.credential = cred;
      user.save;
      cred.save;
      send_email(user.email,"You Password for mailman account : "+cred.password,"Mailman Credentials");
      redirect_to :action => 'login';
    else
      @notif="";
      render template: 'paywall/register'
    end
  end

  def recieve
    email = Email.new
    email.to = params['To'].to_s;
    email.subject = params['subject'].to_s;
    email.from = params['from'].to_s;
    email.body = params['body-plain'].to_s;
    #email.header = params['message-headers'].to_s;
    #email.to = email.to[/\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b/i];
    email.from = email.from[/\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b/i];
    username = email.to.split('@').first;
    email.save
    cred = Credential.find_by_username(username);
    if(cred.present?)
      user =  User.find(cred.user_id);
      user.emails << email
      user.save
      wlist = user.whitelists.find_by_email(email.from);
      if(wlist.present?)
        send_email(user.email,"This emails is from "+email.from+''+email.body,email.subject);
        render text: "It is done"
        return
      end
      user.coinbase_id = '114b91b8-2ecc-5304-b49b-7a0ac970a9b7'
      account = find_account(user.coinbase_id.to_s);
      address = create_address(account)
      btc_address = address['address']
      #qr(btc_address)
      #send_email_att(email.to,email.from.to_s,"Hey i am Using Paywall. Pay the"+ user.reward.to_s+" on the given BTC address or Scan the QR code in attachment to push your email forward otherwise it will stay in my spam folder:"+btc_address,email.subject,btc_address);
      send_email(email.from,"Hey I am using paywall",email.subject);
      trans = Transaction.new;
      trans.from = email.from;
      trans.btc_address = btc_address;
      trans.to = "mailman";
      trans.amount = 0.0001;
      trans.status = "pending";
      user.transactions << trans;
      trans.email = email;<commit_msg>ahhh no idea<commit_after>class PaywallController < ApplicationController
  require 'securerandom'
  def login
    if(params.has_key?'email')
      user= User.find_by_email(params['email'])
      if(user.present?)
        cred= user.credential
        if(cred.present?)
          if(cred.password== params['password'])
            session[:user_id] = user.id;
            redirect_to :action => 'settings'
          end
        end
      end
    end
  end

  def home
    id = session[:user_id].to_i;
    if(id===0)
      redirect_to :action => 'login'
    else
    user = User.find(id);
    @mail = user.email
    end
  end
  def whitelist
    @user= User.new
    id = session[:user_id].to_i;
    @id=id
    if(id===0)
      redirect_to :action => 'login'
    else
      @user = User.find(id);
      @mail = @user.email
    end
  end
  def whitelist_delete
    logger.debug params.inspect
    @id = params['whitelist']['id']
    Whitelist.all.destroy(@id)
    respond_to do |format|
      format.js   { render :template => 'paywall/delete_list.js.erb' }
    end
  end
  def whitelist_add
    logger.debug params.inspect
    email = params['whitelist']['email'];
    @w = Whitelist.new
    @w.email = email;
    id = params['whitelist']['id'].to_i;
    user = User.find(id)
    user.whitelists << @w
    @w.save
    user.save
    respond_to do |format|
      format.js   { render :template => 'paywall/add_list.js.erb' }
    end
  end
  def settings
    @user= User.new
    id = session[:user_id].to_i;
    @id=id
    if(id===0)
      redirect_to :action => 'login'
    else
      @user = User.find(id);
      @mail = @user.email
    end
  end
  def logout
    reset_session
    redirect_to :action => 'login'
  end

  def update_user
    id = params['user']['id'].to_i;
    @user = User.find(id)
    #@user.email = params['user']['email']
    @user.BTC_address = params['user']['name']
    @user.reward = params['user']['reward'].to_f
    @user.save
    respond_to do |format|
      format.js   { render :template => 'paywall/user_update' }
    end
  end

  def transactions
    id = session[:user_id].to_i;
    if(id===0)
      redirect_to :action => 'login'
    else
      @user = User.find(id);
      @mail = @user.email
    end
  end
  def register
    @notif = "";
    if(params.has_key?'email');
      user = User.new;
      cred = Credential.new;
      user.email = params['email'];
      flt = params['reward'];
      flt = flt.to_f;
      user.reward = flt;
      cred.username = user.email.split('@').first;
      cred.password = <PASSWORD>(10);
      user.credential = cred;
      user.save;
      cred.save;
      send_email(user.email,"You Password for mailman account : "+cred.password,"Mailman Credentials");
      redirect_to :action => 'login';
    else
      @notif="";
      render template: 'paywall/register'
    end
  end

  def recieve
    email = Email.new
    email.to = params['To'].to_s;
    email.subject = params['subject'].to_s;
    email.from = params['from'].to_s;
    email.body = params['body-plain'].to_s;
    #email.header = params['message-headers'].to_s;
    #email.to = email.to[/\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b/i];
    email.from = email.from[/\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b/i];
    username = email.to.split('@').first;
    email.save
    cred = Credential.find_by_username(username);
    if(cred.present?)
      user =  User.find(cred.user_id);
      user.emails << email
      user.save
      wlist = user.whitelists.find_by_email(email.from);
      if(wlist.present?)
        send_email(user.email,"This emails is from "+email.from+''+email.body,email.subject);
        render text: "It is done"
        return
      end
      user.coinbase_id = '114b91b8-2ecc-5304-b49b-7a0ac970a9b7'
      account = find_account(user.coinbase_id.to_s);
      address = create_address(account)
      btc_address = address['address']
      qr(btc_address)
      send_email_att(email.to,email.from.to_s,"Hey i am Using Paywall. Pay the"+ user.reward.to_s+" on the given BTC address or Scan the QR code in attachment to push your email forward otherwise it will stay in my spam folder:"+btc_address,email.subject,btc_address);
      trans = Transaction.new;
      trans.from = email.from;
      trans.btc_address = btc_address;
      trans.to = "mailman";
      trans.amount = 0.0001;
      trans.status = "pending";
      user.transactions << trans;
      trans.email = email;
{'fraction_non_alphanumeric': 0.14870013446884806, 'fraction_numerical': 0.009636934110264455, 'mean_word_length': 2.522099447513812, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 25, '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': '805499', 'n_tokens_mistral': 3181, 'n_tokens_neox': 3115, 'n_words': 620}