<commit_before><?php

namespace Lorry\Presenter\Account;

use Lorry\Presenter;
use Lorry\Exception\FileNotFoundException;
use Lorry\Exception\ForbiddenException;
use Lorry\Exception\BadRequestException;

class Activate extends Presenter
{

    public function get($username)
    {
        $user = $this->manager->getRepository('Lorry\Model\User')->findOneBy(array('username' => $username));
        if (!$user) {
            throw new FileNotFoundException('user '.$username);
        }

        $expires = filter_input(INPUT_GET, 'expires');
        $address = filter_input(INPUT_GET, 'address');

        $hash = filter_input(INPUT_GET, 'hash');
        if (empty($hash)) {
            throw new BadRequestException();
        }

        try {
            $expected = $this->security->signActivation($user, $expires,
                $address);
        } catch (\InvalidArgumentException $ex) {
            throw new BadRequestException();
        }

        if (hash_equals($expected, $hash) !== true) {
            throw new ForbiddenException('hash does not match expected value');
        }

        if ($expires < time()) {
            throw new ForbiddenException('token expired');
        }

        if ($address != $user->getEmail()) {
            throw new ForbiddenException('token is for another email address');
        }

        $user->activate();
        $user->save();<commit_msg>fix broken user activation<commit_after><?php

namespace Lorry\Presenter\Account;

use Lorry\Presenter;
use Lorry\Exception\FileNotFoundException;
use Lorry\Exception\ForbiddenException;
use Lorry\Exception\BadRequestException;

class Activate extends Presenter
{

    public function get($username)
    {
        $user = $this->manager->getRepository('Lorry\Model\User')->findOneBy(array('username' => $username));
        if (!$user) {
            throw new FileNotFoundException('user '.$username);
        }

        $expires = filter_input(INPUT_GET, 'expires');
        $address = filter_input(INPUT_GET, 'address');

        $hash = filter_input(INPUT_GET, 'hash');
        if (empty($hash)) {
            throw new BadRequestException();
        }

        try {
            $expected = $this->security->signActivation($user, $expires,
                $address);
        } catch (\InvalidArgumentException $ex) {
            throw new BadRequestException();
        }

        if (hash_equals($expected, $hash) !== true) {
            throw new ForbiddenException('hash does not match expected value');
        }

        if ($expires < time()) {
            throw new ForbiddenException('token expired');
        }

        if ($address != $user->getEmail()) {
            throw new ForbiddenException('token is for another email address');
        }

        $user->activate();
        $this->manager->flush();
{'fraction_non_alphanumeric': 0.12921547745828896, 'fraction_numerical': 0.0, 'mean_word_length': 2.5006211180124223, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 22, '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': '2744898', 'n_tokens_mistral': 754, 'n_tokens_neox': 743, 'n_words': 170}