Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- doctrine:
- dbal:
- default_connection: website
- connections:
- #MySql
- aodb:
- driver: pdo_mysql
- host: "%database_host%"
- port: "%database_port%"
- dbname: "%ao_db_database_name%"
- user: "%database_user%"
- password: "%database_password%"
- charset: UTF8
- abdb:
- driver: pdo_mysql
- host: "%database_host%"
- port: "%database_port%"
- dbname: "%ab_db_database_name%"
- user: "%database_user%"
- password: "%database_password%"
- charset: UTF8
- website:
- mapping_types:
- enum: string
- driver: pdo_mysql
- host: "%database_host%"
- port: "%database_port%"
- dbname: "%web_database_name%"
- user: "%database_user%"
- password: "%database_password%"
- charset: UTF8
- #Postgresql
- pgsql:
- driver: pdo_pgsql
- host: "%psql_database_host%"
- port: "%psql_database_port%"
- dbname: "%psql_database_name%"
- user: "%psql_database_user%"
- password: "%psql_database_password%"
- charset: UTF8
- orm:
- auto_generate_proxy_classes: "%kernel.debug%"
- default_entity_manager: website
- entity_managers:
- website:
- connection: website
- mappings:
- WebsiteBundle: ~
- UserBundle: ~
- pgsql:
- connection: pgsql
- mappings:
- UserBundle: ~
- <?php
- namespace UserBundleEntity;
- use DoctrineORMMapping as ORM;
- use DoctrineDBALTypesType;
- use SymfonyComponentSecurityCoreUserEquatableInterface;
- use SymfonyComponentSecurityCoreUserUserInterface;
- Type::overrideType('datetime', 'DoctrineDBALTypesVarDateTimeType');
- Type::overrideType('datetimetz', 'DoctrineDBALTypesVarDateTimeType');
- Type::overrideType('time', 'DoctrineDBALTypesVarDateTimeType');
- /**
- * GameAccount
- *
- * @ORMTable(name="account")
- * @ORMEntity(repositoryClass="UserBundleRepositoryGameAccountRepository")
- */
- class GameAccount implements UserInterface, EquatableInterface
- {
- /**
- * @var int
- *
- * @ORMColumn(name="id", type="integer")
- * @ORMId
- * @ORMGeneratedValue(strategy="AUTO")
- */
- private $id;
- /**
- * @var string
- *
- * @ORMColumn(name="identifier", type="string", length=100, unique=true)
- */
- private $identifier;
- /**
- * @var string
- *
- * @ORMColumn(name="title", type="string", length=100)
- */
- private $title;
- /**
- * @var string
- *
- * @ORMColumn(name="password", type="string", length=100)
- */
- private $password;
- /**
- * @var string
- *
- * @ORMColumn(name="external_id", type="string", length=30)
- */
- private $externalId;
- /**
- * @var string
- *
- * @ORMColumn(name="salt", type="string", length=100)
- */
- private $salt;
- /**
- * @var string
- *
- * @ORMColumn(name="last_shard_name", type="string", length=100)
- */
- private $lastShardName;
- /**
- * @var string
- *
- * @ORMColumn(name="access_level", type="string", length=16)
- */
- private $accessLevel;
- /**
- * @var string
- *
- * @ORMColumn(name="current_access_level", type="string", length=16)
- */
- private $currentAccessLevel;
- /**
- * @var int
- *
- * @ORMColumn(name="status", type="integer")
- */
- private $status;
- /**
- * @var int
- *
- * @ORMColumn(name="flags", type="bigint")
- */
- private $flags;
- /**
- * @var int
- *
- * @ORMColumn(name="reseacher", type="smallint")
- */
- private $reseacher;
- /**
- * @var DateTime
- *
- * @ORMColumn(name="creation_time", type="datetimetz")
- */
- private $creationTime;
- /**
- * @var int
- *
- * @ORMColumn(name="hash_algorithm_id", type="bigint")
- */
- private $hashAlgorithmId;
- /**
- * @var string
- *
- * @ORMColumn(name="last_ip", type="string", length=15)
- */
- private $lastIp;
- /**
- * @var int
- *
- * @ORMColumn(name="is_last_login_from_pccafe", type="smallint")
- */
- private $isLastLoginFromPccafe;
- /**
- * @var DateTime
- *
- * @ORMColumn(name="last_game_start", type="datetimetz", nullable=true)
- */
- private $lastGameStart;
- /**
- * @var DateTime
- *
- * @ORMColumn(name="last_game_end", type="datetimetz", nullable=true)
- */
- private $lastGameEnd;
- /**
- * @var int
- *
- * @ORMColumn(name="last_avatar_id", type="bigint")
- */
- private $lastAvatarId;
- /**
- * @var DateTime
- *
- * @ORMColumn(name="subscribe_until", type="datetimetz", nullable=true)
- */
- private $subscribeUntil;
- /**
- * @var string
- *
- * @ORMColumn(name="alt_identifier", type="string", length=100, nullable=true)
- */
- private $altIdentifier;
- /**
- * @var string
- *
- * @ORMColumn(name="access_mode", type="string", length=30)
- */
- private $accessMode;
- /**
- * @var int
- *
- * @ORMColumn(name="time_played", type="bigint")
- */
- private $timePlayed;
- /**
- * @var int
- *
- * @ORMColumn(name="time_rested", type="bigint")
- */
- private $timeRested;
- /**
- * @var int
- *
- * @ORMColumn(name="refer_owner_id", type="integer")
- */
- private $referOwnerId;
- /**
- * @var int
- *
- * @ORMColumn(name="max_avatar_level", type="integer")
- */
- private $maxAvatarLevel;
- /**
- * @var string
- *
- * @ORMColumn(name="hardware", type="string", length=200)
- */
- private $hardware;
- /**
- * Get id
- *
- * @return int
- */
- public function getId()
- {
- return $this->id;
- }
- /**
- * Set identifier
- *
- * @param string $identifier
- *
- * @return GameAccount
- */
- public function setIdentifier($identifier)
- {
- $this->identifier = $identifier;
- return $this;
- }
- /**
- * Get identifier
- *
- * @return string
- */
- public function getIdentifier()
- {
- return $this->identifier;
- }
- /**
- * Set title
- *
- * @param string $title
- *
- * @return GameAccount
- */
- public function setTitle($title)
- {
- $this->title = $title;
- return $this;
- }
- /**
- * Get title
- *
- * @return string
- */
- public function getTitle()
- {
- return $this->title;
- }
- /**
- * Set password
- *
- * @param string $password
- *
- * @return GameAccount
- */
- public function setPassword($password)
- {
- $this->password = $password;
- return $this;
- }
- /**
- * Get password
- *
- * @return string
- */
- public function getPassword()
- {
- return $this->password;
- }
- /**
- * Set externalId
- *
- * @param string $externalId
- *
- * @return GameAccount
- */
- public function setExternalId($externalId)
- {
- $this->externalId = $externalId;
- return $this;
- }
- /**
- * Get externalId
- *
- * @return string
- */
- public function getExternalId()
- {
- return $this->externalId;
- }
- /**
- * Set salt
- *
- * @param string $salt
- *
- * @return GameAccount
- */
- public function setSalt($salt)
- {
- $this->salt = $salt;
- return $this;
- }
- /**
- * Get salt
- *
- * @return string
- */
- public function getSalt()
- {
- return $this->salt;
- }
- /**
- * Set lastShardName
- *
- * @param string $lastShardName
- *
- * @return GameAccount
- */
- public function setLastShardName($lastShardName)
- {
- $this->lastShardName = $lastShardName;
- return $this;
- }
- /**
- * Get lastShardName
- *
- * @return string
- */
- public function getLastShardName()
- {
- return $this->lastShardName;
- }
- /**
- * Set accessLevel
- *
- * @param string $accessLevel
- *
- * @return GameAccount
- */
- public function setAccessLevel($accessLevel)
- {
- $this->accessLevel = $accessLevel;
- return $this;
- }
- /**
- * Get accessLevel
- *
- * @return string
- */
- public function getAccessLevel()
- {
- return $this->accessLevel;
- }
- /**
- * Set currentAccessLevel
- *
- * @param string $currentAccessLevel
- *
- * @return GameAccount
- */
- public function setCurrentAccessLevel($currentAccessLevel)
- {
- $this->currentAccessLevel = $currentAccessLevel;
- return $this;
- }
- /**
- * Get currentAccessLevel
- *
- * @return string
- */
- public function getCurrentAccessLevel()
- {
- return $this->currentAccessLevel;
- }
- /**
- * Set status
- *
- * @param integer $status
- *
- * @return GameAccount
- */
- public function setStatus($status)
- {
- $this->status = $status;
- return $this;
- }
- /**
- * Get status
- *
- * @return int
- */
- public function getStatus()
- {
- return $this->status;
- }
- /**
- * Set flags
- *
- * @param integer $flags
- *
- * @return GameAccount
- */
- public function setFlags($flags)
- {
- $this->flags = $flags;
- return $this;
- }
- /**
- * Get flags
- *
- * @return int
- */
- public function getFlags()
- {
- return $this->flags;
- }
- /**
- * Set reseacher
- *
- * @param integer $reseacher
- *
- * @return GameAccount
- */
- public function setReseacher($reseacher)
- {
- $this->reseacher = $reseacher;
- return $this;
- }
- /**
- * Get reseacher
- *
- * @return int
- */
- public function getReseacher()
- {
- return $this->reseacher;
- }
- /**
- * Set creationTime
- *
- * @param DateTime $creationTime
- *
- * @return GameAccount
- */
- public function setCreationTime($creationTime)
- {
- $this->creationTime = $creationTime;
- return $this;
- }
- /**
- * Get creationTime
- *
- * @return DateTime
- */
- public function getCreationTime()
- {
- return $this->creationTime;
- }
- /**
- * Set hashAlgorithmId
- *
- * @param integer $hashAlgorithmId
- *
- * @return GameAccount
- */
- public function setHashAlgorithmId($hashAlgorithmId)
- {
- $this->hashAlgorithmId = $hashAlgorithmId;
- return $this;
- }
- /**
- * Get hashAlgorithmId
- *
- * @return int
- */
- public function getHashAlgorithmId()
- {
- return $this->hashAlgorithmId;
- }
- /**
- * Set lastIp
- *
- * @param string $lastIp
- *
- * @return GameAccount
- */
- public function setLastIp($lastIp)
- {
- $this->lastIp = $lastIp;
- return $this;
- }
- /**
- * Get lastIp
- *
- * @return string
- */
- public function getLastIp()
- {
- return $this->lastIp;
- }
- /**
- * Set isLastLoginFromPccafe
- *
- * @param integer $isLastLoginFromPccafe
- *
- * @return GameAccount
- */
- public function setIsLastLoginFromPccafe($isLastLoginFromPccafe)
- {
- $this->isLastLoginFromPccafe = $isLastLoginFromPccafe;
- return $this;
- }
- /**
- * Get isLastLoginFromPccafe
- *
- * @return int
- */
- public function getIsLastLoginFromPccafe()
- {
- return $this->isLastLoginFromPccafe;
- }
- /**
- * Set lastGameStart
- *
- * @param DateTime $lastGameStart
- *
- * @return GameAccount
- */
- public function setLastGameStart($lastGameStart)
- {
- $this->lastGameStart = $lastGameStart;
- return $this;
- }
- /**
- * Get lastGameStart
- *
- * @return DateTime
- */
- public function getLastGameStart()
- {
- return $this->lastGameStart;
- }
- /**
- * Set lastGameEnd
- *
- * @param DateTime $lastGameEnd
- *
- * @return GameAccount
- */
- public function setLastGameEnd($lastGameEnd)
- {
- $this->lastGameEnd = $lastGameEnd;
- return $this;
- }
- /**
- * Get lastGameEnd
- *
- * @return DateTime
- */
- public function getLastGameEnd()
- {
- return $this->lastGameEnd;
- }
- /**
- * Set lastAvatarId
- *
- * @param integer $lastAvatarId
- *
- * @return GameAccount
- */
- public function setLastAvatarId($lastAvatarId)
- {
- $this->lastAvatarId = $lastAvatarId;
- return $this;
- }
- /**
- * Get lastAvatarId
- *
- * @return int
- */
- public function getLastAvatarId()
- {
- return $this->lastAvatarId;
- }
- /**
- * Set subscribeUntil
- *
- * @param DateTime $subscribeUntil
- *
- * @return GameAccount
- */
- public function setSubscribeUntil($subscribeUntil)
- {
- $this->subscribeUntil = $subscribeUntil;
- return $this;
- }
- /**
- * Get subscribeUntil
- *
- * @return DateTime
- */
- public function getSubscribeUntil()
- {
- return $this->subscribeUntil;
- }
- /**
- * Set altIdentifier
- *
- * @param string $altIdentifier
- *
- * @return GameAccount
- */
- public function setAltIdentifier($altIdentifier)
- {
- $this->altIdentifier = $altIdentifier;
- return $this;
- }
- /**
- * Get altIdentifier
- *
- * @return string
- */
- public function getAltIdentifier()
- {
- return $this->altIdentifier;
- }
- /**
- * Set accessMode
- *
- * @param string $accessMode
- *
- * @return GameAccount
- */
- public function setAccessMode($accessMode)
- {
- $this->accessMode = $accessMode;
- return $this;
- }
- /**
- * Get accessMode
- *
- * @return string
- */
- public function getAccessMode()
- {
- return $this->accessMode;
- }
- /**
- * Set timePlayed
- *
- * @param integer $timePlayed
- *
- * @return GameAccount
- */
- public function setTimePlayed($timePlayed)
- {
- $this->timePlayed = $timePlayed;
- return $this;
- }
- /**
- * Get timePlayed
- *
- * @return int
- */
- public function getTimePlayed()
- {
- return $this->timePlayed;
- }
- /**
- * Set timeRested
- *
- * @param integer $timeRested
- *
- * @return GameAccount
- */
- public function setTimeRested($timeRested)
- {
- $this->timeRested = $timeRested;
- return $this;
- }
- /**
- * Get timeRested
- *
- * @return int
- */
- public function getTimeRested()
- {
- return $this->timeRested;
- }
- /**
- * Set referOwnerId
- *
- * @param integer $referOwnerId
- *
- * @return GameAccount
- */
- public function setReferOwnerId($referOwnerId)
- {
- $this->referOwnerId = $referOwnerId;
- return $this;
- }
- /**
- * Get referOwnerId
- *
- * @return int
- */
- public function getReferOwnerId()
- {
- return $this->referOwnerId;
- }
- /**
- * Set maxAvatarLevel
- *
- * @param integer $maxAvatarLevel
- *
- * @return GameAccount
- */
- public function seMaxAvatarLevel($maxAvatarLevel)
- {
- $this->maxAvatarLevel = $maxAvatarLevel;
- return $this;
- }
- /**
- * Get maxAvatarLevel
- *
- * @return int
- */
- public function getMaxAvatarLevel()
- {
- return $this->maxAvatarLevel;
- }
- /**
- * Set hardware
- *
- * @param string $hardware
- *
- * @return GameAccount
- */
- public function setHardware($hardware)
- {
- $this->hardware = $hardware;
- return $this;
- }
- /**
- * Get hardware
- *
- * @return string
- */
- public function getHardware()
- {
- return $this->hardware;
- }
- /**
- * Returns the roles granted to the user.
- *
- * <code>
- * public function getRoles()
- * {
- * return array('ROLE_USER');
- * }
- * </code>
- *
- * Alternatively, the roles might be stored on a ``roles`` property,
- * and populated in any number of different ways when the user object
- * is created.
- *
- * @return (Role|string)[] The user roles
- */
- public function getRoles()
- {
- return array('ROLE_USER');
- }
- /**
- * Returns the username used to authenticate the user.
- *
- * @return string The username
- */
- public function getUsername()
- {
- return $this->identifier;
- }
- /**
- * Removes sensitive data from the user.
- *
- * This is important if, at any given point, sensitive information like
- * the plain-text password is stored on this object.
- */
- public function eraseCredentials()
- {
- // TODO: Implement eraseCredentials() method.
- }
- /**
- * The equality comparison should neither be done by referential equality
- * nor by comparing identities (i.e. getId() === getId()).
- *
- * However, you do not need to compare every attribute, but only those that
- * are relevant for assessing whether re-authentication is required.
- *
- * Also implementation should consider that $user instance may implement
- * the extended user interface `AdvancedUserInterface`.
- *
- * @param UserInterface $user
- *
- * @return bool
- */
- public function isEqualTo(UserInterface $user)
- {
- // TODO: Implement isEqualTo() method.
- }
- }
- <?php
- namespace UserBundleController;
- use SymfonyBundleFrameworkBundleControllerController;
- use SymfonyComponentHttpFoundationRequest;
- use SymfonyComponentSecurityCoreAuthenticationTokenUsernamePasswordToken;
- use SymfonyComponentSecurityHttpEventInteractiveLoginEvent;
- use UserBundleEntityGameAccount;
- class SecurityController extends Controller
- {
- public function loginAction(Request $request)
- {
- $authentUtils = $this->get('security.authentication_utils');
- $error = $authentUtils->getLastAuthenticationError();
- $lastUsername = $authentUtils->getLastUsername();
- if($request->get('login') && $request->get('password'))
- {
- $proceed = $this->proceedAction($request->get('login'), $request->get('password'));
- if(!$proceed)
- {
- $error = 'Mauvais indentifiants';
- } else {
- $token = new UsernamePasswordToken($proceed, null, 'main', []);
- $this->get('security.token_storage')->setToken($token);
- $event = new InteractiveLoginEvent($request, $token);
- $this->get('event_dispatcher')->dispatch('security.interactive_login', $event);
- // dump($this->getUser()); exit;
- return $this->redirectToRoute('news');
- }
- }
- return $this->render('UserBundle:Security:login.html.twig',
- [
- 'last_username' => $lastUsername,
- 'error' => $error
- ]
- );
- }
- private function proceedAction($login, $password)
- {
- $ga_repo = $this
- ->getDoctrine()
- ->getManager('pgsql')
- ->getRepository('UserBundle:GameAccount')
- ;
- $login = $ga_repo->check_login($login);
- if(null !== $login)
- {
- if($login->getPassword() === $this->hashPassSalt($login, $password))
- {
- return $login;
- }
- } else {
- return false;
- }
- return false;
- }
- private function hashPassSalt($login, $password)
- {
- $ha_repo = $this
- ->getDoctrine()
- ->getManager('pgsql')
- ->getRepository('UserBundle:HashAlgorithms')
- ;
- if(null !== $hash = $ha_repo->hashPassSalt($login->getHashAlgorithmId()))
- {
- if('SHA-1' === $hash->getName())
- {
- return sha1($password. $login->getSalt());
- }
- else if ('MD5' === $hash->getName())
- {
- return md5($password.$login->getSalt());
- }
- else {
- return $password.$login->getSalt();
- }
- }
- return false;
- }
- }
- entity_managers:
- website:
- connection: website
- mappings:
- WebsiteBundle: ~
- pgsql:
- connection: pgsql
- mappings:
- UserBundle: ~
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement