<commit_before><?php
/**
 * Created by JetBrains PhpStorm.
 * User: quantum
 * Date: 2/18/14
 * Time: 10:27 AM
 * To change this template use File | Settings | File Templates.
 */

namespace Exam\WebBundle\Service;

use Exam\DomainBundle\Entity\User\User;
use Exam\DomainBundle\Repository\ParticipantRepository;
use Exam\DomainBundle\Repository\UserRepository;
use JMS\DiExtraBundle\Annotation\InjectParams;
use Symfony\Component\HttpFoundation\Session\Session;
use JMS\DiExtraBundle\Annotation\Service;
use JMS\DiExtraBundle\Annotation\Inject;

/**
 * Class LoginService
 * @package Exam\WebBundle\Service
 * @Service("loginService")
 */
class LoginService {
    private $session,
            $userRepo,
            $repo;

    /**
     * @InjectParams({
     *      "session" = @Inject("session"),
     *      "userRepo" = @Inject("userRepo"),
     *      "repo" = @Inject("participantRepo")
     * })
     */
    public function __construct(Session $session,
                                UserRepository $userRepo,
                                ParticipantRepository $repo) {
        $this->session = $session;
        $this->userRepo = $userRepo;
        $this->repo = $repo;
    }

    public function checkParticipant($username, $password) {
        if($username == 'test') {
            if($password == '<PASSWORD>') {
                $participant = $this->getParticipant($this->getUser($username));
                $this->session->set('participant', $participant->getId());
            }
        }
    }

    public function isLogin() {
        return $this->session->has('participant');
    }

    public function logout() {
        if($this->isLogin()) {
            $this->session->clear();
        }
    }

    public function getUser($username) {
        return $this->userRepo->findOneBy(array('username' => $username));
    }

    public function getParticipant(User $user) {
        return $this->repo->findOneBy(array('user' => $user));
    }

    public function getCurrentParticipant() {
        return $this->repo->find($this->session->get('participant'));
    }
}<commit_msg>update login<commit_after><?php
/**
 * Created by JetBrains PhpStorm.
 * User: quantum
 * Date: 2/18/14
 * Time: 10:27 AM
 * To change this template use File | Settings | File Templates.
 */

namespace Exam\WebBundle\Service;

use Exam\DomainBundle\Entity\User\User;
use Exam\DomainBundle\Repository\ParticipantRepository;
use Exam\DomainBundle\Repository\UserRepository;
use JMS\DiExtraBundle\Annotation\InjectParams;
use Symfony\Component\HttpFoundation\Session\Session;
use JMS\DiExtraBundle\Annotation\Service;
use JMS\DiExtraBundle\Annotation\Inject;

/**
 * Class LoginService
 * @package Exam\WebBundle\Service
 * @Service("loginService")
 */
class LoginService {
    private $session,
            $userRepo,
            $repo;

    /**
     * @InjectParams({
     *      "session" = @Inject("session"),
     *      "userRepo" = @Inject("userRepo"),
     *      "repo" = @Inject("participantRepo")
     * })
     */
    public function __construct(Session $session,
                                UserRepository $userRepo,
                                ParticipantRepository $repo) {
        $this->session = $session;
        $this->userRepo = $userRepo;
        $this->repo = $repo;
    }

    public function checkParticipant($registrationNumber, $password) {
        $user = $this->userRepo->findOneBy(array(
            "username" => $registrationNumber,
            "password" => <PASSWORD>($password)
        ));

        if($user) {
            $participant = $this->getParticipant($user);
            $this->session->set('participant', $participant->getId());
        }
    }

    public function isLogin() {
        return $this->session->has('participant');
    }

    public function logout() {
        if($this->isLogin()) {
            $this->session->clear();
        }
    }

    public function getUser($username) {
        return $this->userRepo->findOneBy(array('username' => $username));
    }

    public function getParticipant(User $user) {
        return $this->repo->findOneBy(array('user' => $user));
    }

    public function getCurrentParticipant() {
        return $this->repo->find($this->session->get('participant'));
    }
}
{'fraction_non_alphanumeric': 0.14366065151160065, 'fraction_numerical': 0.004218420435903445, 'mean_word_length': 2.5477971737323357, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 54, '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': '7476695', 'n_tokens_mistral': 1258, 'n_tokens_neox': 1232, 'n_words': 222}