<commit_before><?php namespace App\Controllers\Auth;

use App\Controllers\Controller;
use App\Models\User;
use Betasyntax\Core\Application;
use PHPMailer;

class AuthController extends Controller
{
  public $app;
  protected $token = '';
  protected static $activation_code;
  protected $authUrl = '/authenticate';
  protected $resetPassUrl = '/account/password/reset';
  protected $loginUrl  = '/login';
  protected $signupUrl = '/signup';
  protected $signupSuccessUrl = '/account/created';
  protected $resetPassViewUrl = '/account/password/reset/view';
  protected $auth;

  public function __construct() 
  {
    $this->middleware = ['logger'];
    $this->app = app();
    $this->app->auth = $this->app->container->get('Betasyntax\Authentication');
  }

  public function csrf_token() 
  {
    if (empty($this->session->token)) {
      $this->app->session->token = bin2hex(random_bytes(32));
    }
    $this->token = $this->app->session->token;
    // dd($this->token);
  }

  public function login()
  {
    $this->csrf_token();
    $c = array(
      'slug'=>'login',
      'token'=>$this->token,
      'action' =>$this->authUrl,
      'resetPassUrl'=>$this->resetPassUrl
    );
    return view('Auth/login.haml',$c);
  }

  public function logout()
  {
    session_unset();
    session_destroy();
    return redirect('/');
  }
  
  public function signup()
  { 
    $this->csrf_token();
    $c = array(
      'slug'=>'login',
      'token'=>$this->token,
      'email'=>isset($_GET['email']) ? $_GET['email'] : '',
      'action' => $this->signupUrl
    );
    return view('Auth/signup.haml',$c);
  }

  public function accountCreated() 
  {
    $c = array(
      'slug'=>'login'
    );
    return view('Auth/new_account.haml',$c);
  }

  public function accountActivate($token) {
    $c = array(
      'slug'=>'activated'
    );
    // var_dump($token['token']);
    $user = User::search('activation_code','=',$token['token'],1);
    if(isset($user->activation_code)) {
      $user->activation_code='';
      $user->status = 'enabled';
      if(User::save()) {
        $this->flash->success('Account activated. Login below.');
        return redirect(app()->loginUrl);
      } 
    } else {
      return redirect(app()->loginUrl);
    }
  }

  public function email_activation_code($req,$reset=false)
  {
    $user = User::search('email','=',$req['email'],1);

    $mail = new PHPMailer();
    $mail->IsSMTP();
    $mail->CharSet="UTF-8";
    $mail->SMTPSecure = 'tls';
    // $mail->SMTPDebug = 2;                            // Enable verbose debug output
    $mail->Host = 'smtp.gmail.com';
    $mail->Port = 587;
    $mail->Username = '<EMAIL>';
    $mail->Password = '<PASSWORD>!';
    $mail->SMTPAuth = true;

    $mail->From = '<EMAIL>';
    $mail->FromName = 'tester';
    $mail->AddAddress('<EMAIL>');
    $mail->AddReplyTo('<EMAIL>', 'Information');

    $mail->IsHTML(true);
    $action='account/activate/';
    $sub = 'Please activate your account.';
    $cnt1  = 'activate your account';
    if($reset) {<commit_msg>Update AuthController.php<commit_after><?php namespace App\Controllers\Auth;

use App\Controllers\Controller;
use App\Models\User;
use Betasyntax\Core\Application;
use PHPMailer;

class AuthController extends Controller
{
  public $app;
  protected $token = '';
  protected static $activation_code;
  protected $authUrl = '/authenticate';
  protected $resetPassUrl = '/account/password/reset';
  protected $loginUrl  = '/login';
  protected $signupUrl = '/signup';
  protected $signupSuccessUrl = '/account/created';
  protected $resetPassViewUrl = '/account/password/reset/view';
  protected $auth;

  public function __construct() 
  {
    $this->middleware = ['logger'];
    $this->app = app();
    $this->app->auth = $this->app->container->get('Betasyntax\Authentication');
  }

  public function csrf_token() 
  {
    if (empty($this->session->token)) {
      $this->app->session->token = bin2hex(random_bytes(32));
    }
    $this->token = $this->app->session->token;
    // dd($this->token);
  }

  public function login()
  {
    $this->csrf_token();
    $c = array(
      'slug'=>'login',
      'token'=>$this->token,
      'action' =>$this->authUrl,
      'resetPassUrl'=>$this->resetPassUrl
    );
    return view('Auth/login.haml',$c);
  }

  public function logout()
  {
    session_unset();
    session_destroy();
    return redirect('/');
  }
  
  public function signup()
  { 
    $this->csrf_token();
    $c = array(
      'slug'=>'login',
      'token'=>$this->token,
      'email'=>isset($_GET['email']) ? $_GET['email'] : '',
      'action' => $this->signupUrl
    );
    return view('Auth/signup.haml',$c);
  }

  public function accountCreated() 
  {
    $c = array(
      'slug'=>'login'
    );
    return view('Auth/new_account.haml',$c);
  }

  public function accountActivate($token) {
    $c = array(
      'slug'=>'activated'
    );
    // var_dump($token['token']);
    $user = User::search('activation_code','=',$token['token'],1);
    if(isset($user->activation_code)) {
      $user->activation_code='';
      $user->status = 'enabled';
      if(User::save()) {
        $this->flash->success('Account activated. Login below.');
        return redirect(app()->loginUrl);
      } 
    } else {
      return redirect(app()->loginUrl);
    }
  }

  public function email_activation_code($req,$reset=false)
  {
    $user = User::search('email','=',$req['email'],1);

    $mail = new PHPMailer();
    $mail->IsSMTP();
    $mail->CharSet="UTF-8";
    $mail->SMTPSecure = 'tls';
    // $mail->SMTPDebug = 2;                            // Enable verbose debug output
    $mail->Host = 'smtp.gmail.com';
    $mail->Port = 587;
    $mail->Username = '<EMAIL>';
    $mail->Password = '<PASSWORD>';
    $mail->SMTPAuth = true;

    $mail->From = '<EMAIL>';
    $mail->FromName = 'Your Company Name';
    $mail->AddAddress('<EMAIL>');
    $mail->AddReplyTo('<EMAIL>', 'Information');

    $mail->IsHTML(true);
    $action='account/activate/';
    $sub = 'Please activate your account.';
    $cnt1  = 'activate your account';
    if($reset) {
{'fraction_non_alphanumeric': 0.1942894650475878, 'fraction_numerical': 0.0036101083032490976, 'mean_word_length': 3.066044029352902, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 123, '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': '4997329', 'n_tokens_mistral': 2036, 'n_tokens_neox': 2015, 'n_words': 349}