<commit_before><?php

namespace Rcm\Model\UserManagement;

use Rcm\Model\EntityMgrAware;
use Zend\Crypt\BlockCipher;
use Zend\Session\Container;
use Rcm\Entity\User;

class DoctrineUserManager extends EntityMgrAware
    implements UserManagerInterface
{
    protected $session;

    protected $cypher;

    const SESSION_NAME = 'rcm_user_manager';

    public function __construct(BlockCipher $cypher)
    {
        $this->cypher = $cypher;
        $this->session = new Container(self::SESSION_NAME);
    }

    public function logout()
    {
        $this->session->getManager()->destroy();
    }

    public function saveUser(User $user)
    {

    }


    public function isCurrentUser($username)
    {
        $user = $this->entityMgr->getRepository('\Rcm\Entity\User')
            ->findOneByUsername($username);

        if ($user) {
            return true;
        }

        return false;
    }

    /**
     * @return \Rcm\Entity\User | null
     */
    public function getLoggedInUser()
    {
        if (!$this->session->userId) {
            return null;
        }
        return $this->entityMgr->getRepository('\Rcm\Entity\User')
            ->find($this->session->userId);
    }

    /**
     * @param \Rcm\Entity\User $user
     */
    public function setLoggedInUser(User $user, $extra)
    {
        $this->session->userId = $user->getUserId();
    }

    /**
     * @return \Rcm\Entity\AdminPermissions|null
     */
    public function getLoggedInAdminPermissions()
    {
        $user = $this->getLoggedInUser();
        if (!$user) {
            return null;
        }
        return $this->entityMgr
            ->getRepository('\Rcm\Entity\AdminPermissions')
            ->findOneByAccountNumber($user->getAccount()->getAccountNumber());
    }

<commit_msg>WEBCART-80 WEBCART-81  Refactor profile editor script<commit_after><?php

namespace Rcm\Model\UserManagement;

use Rcm\Model\EntityMgrAware;
use Zend\Crypt\BlockCipher;
use Zend\Session\Container;
use Rcm\Entity\User;

class DoctrineUserManager extends EntityMgrAware
    implements UserManagerInterface
{
    protected $session;

    protected $cypher;

    const SESSION_NAME = 'rcm_user_manager';

    public function __construct(BlockCipher $cypher)
    {
        $this->cypher = $cypher;
        $this->session = new Container(self::SESSION_NAME);
    }

    public function logout()
    {
        $this->session->getManager()->destroy();
    }

    public function saveUser(User $user)
    {

    }


    public function isCurrentUser($username)
    {
        $user = $this->entityMgr->getRepository('\Rcm\Entity\User')
            ->findOneByUsername($username);

        if ($user) {
            return true;
        }

        return false;
    }

    /**
     * @return \Rcm\Entity\User | null
     */
    public function getLoggedInUser()
    {
        if (!$this->session->userId) {
            return null;
        }
        return $this->entityMgr->getRepository('\Rcm\Entity\User')
            ->find($this->session->userId);
    }

    /**
     * @param \Rcm\Entity\User $user
     */
    public function setLoggedInUser(User $user)
    {
        $this->session->userId = $user->getUserId();
    }

    /**
     * @return \Rcm\Entity\AdminPermissions|null
     */
    public function getLoggedInAdminPermissions()
    {
        $user = $this->getLoggedInUser();
        if (!$user) {
            return null;
        }
        return $this->entityMgr
            ->getRepository('\Rcm\Entity\AdminPermissions')
            ->findOneByAccountNumber($user->getAccount()->getAccountNumber());
    }


{'fraction_non_alphanumeric': 0.13132999443516974, 'fraction_numerical': 0.0011129660545353367, 'mean_word_length': 2.2504520795660037, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 51, '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': '2490523', 'n_tokens_mistral': 1091, 'n_tokens_neox': 1085, 'n_words': 186}