Advertisement
Guest User

Untitled

a guest
Sep 2nd, 2016
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.85 KB | None | 0 0
  1. security:
  2. encoders:
  3. AppAppBundleEntityUser:
  4. algorithm: sha512
  5. encode-as-base64: true
  6. iterations: 10
  7.  
  8. providers:
  9. main:
  10. entity: { class: AppBundle:User, property: username }
  11.  
  12. firewalls:
  13. main:
  14. pattern: /.*
  15. form_login:
  16. check_path: /login_check/
  17. login_path: /login/
  18. logout: true
  19. security: true
  20. anonymous: true
  21.  
  22. access_control:
  23. - { path: /admin/.*, role: ROLE_ADMIN }
  24. - { path: /.*, role: IS_AUTHENTICATED_ANONYMOUSLY }
  25.  
  26. <?php
  27. namespace AppAppBundleEntity;
  28.  
  29. use DoctrineCommonCollectionsArrayCollection;;
  30. use DoctrineORMMapping as ORM;
  31. use SymfonyComponentSecurityCoreUserUserInterface;
  32.  
  33. /**
  34. * @ORMEntity
  35. * @ORMTable(name="user")
  36. * @ORMHasLifecycleCallbacks
  37. */
  38. class User implements UserInterface
  39. {
  40. /**
  41. * @ORMId
  42. * @ORMColumn(type="integer")
  43. * @ORMGeneratedValue(strategy="AUTO")
  44. */
  45. protected $id;
  46.  
  47. /**
  48. * @ORMColumn(type="string", length=255, unique=true)
  49. */
  50. protected $username;
  51.  
  52. /**
  53. * @ORMColumn(type="string", length=255)
  54. */
  55. protected $password;
  56.  
  57. /**
  58. * @ORMColumn(type="string", length=255)
  59. */
  60. protected $salt;
  61.  
  62. /**
  63. * @ORMManyToMany(targetEntity="Role")
  64. * @ORMJoinTable(name="user_role",
  65. * joinColumns={@ORMJoinColumn(name="user_id", referencedColumnName="id")},
  66. * inverseJoinColumns={@ORMJoinColumn(name="role_id", referencedColumnName="id")}
  67. * )
  68. */
  69. protected $userRoles;
  70.  
  71. /**
  72. * @ORMColumn(type="boolean")
  73. */
  74. protected $status;
  75.  
  76.  
  77. /**
  78. * @ORMColumn(type="string")
  79. */
  80. protected $email;
  81.  
  82. /**
  83. * @return mixed
  84. */
  85. public function getEmail()
  86. {
  87. return $this->email;
  88. }
  89.  
  90. /**
  91. * @param mixed $email
  92. */
  93. public function setEmail($email)
  94. {
  95. $this->email = $email;
  96. }
  97.  
  98. /**
  99. * @ORMColumn(name="is_active", type="boolean")
  100. */
  101. protected $isActive;
  102.  
  103. /**
  104. * @ORMColumn(type="datetime")
  105. */
  106. protected $date_added;
  107.  
  108. public function __construct()
  109. {
  110. $this->userRoles = new ArrayCollection();
  111. $this->setDateAdded(new DateTime());
  112. }
  113.  
  114. /**
  115. * Clear user privileges
  116. **/
  117. public function eraseCredentials()
  118. {
  119.  
  120. }
  121.  
  122. /**
  123. * @return array of Role object
  124. */
  125. public function getRoles()
  126. {
  127. return $this->getUserRoles();
  128. }
  129.  
  130. /**
  131. * Compare one user to another user
  132. * and determine if its same user
  133. *
  134. * @param UserInterface $user
  135. * @return boolean True if equals and false otherwise
  136. */
  137. public function equals(UserInterface $user)
  138. {
  139. return md5($this->getUsername()) == md5($user->getUsername());
  140. }
  141.  
  142. /**
  143. * Get id
  144. *
  145. * @return integer
  146. */
  147. public function getId()
  148. {
  149. return $this->id;
  150. }
  151.  
  152. /**
  153. * Set username
  154. *
  155. * @param string $username
  156. *
  157. * @return User
  158. */
  159. public function setUsername($username)
  160. {
  161. $this->username = $username;
  162.  
  163. return $this;
  164. }
  165.  
  166. /**
  167. * Get username
  168. *
  169. * @return string
  170. */
  171. public function getUsername()
  172. {
  173. return $this->username;
  174. }
  175.  
  176. /**
  177. * @return string
  178. */
  179. public function setPassword($password)
  180. {
  181. $this->password = $password;
  182.  
  183. return $password;
  184. }
  185.  
  186. /**
  187. * @return string
  188. */
  189. public function getPassword()
  190. {
  191. return $this->password;
  192. }
  193.  
  194. /**
  195. * @return string
  196. */
  197. public function setSalt($salt)
  198. {
  199. $this->salt = $salt;
  200.  
  201. return $this;
  202. }
  203.  
  204. /**
  205. * @return string
  206. */
  207. public function getSalt()
  208. {
  209. return $this->salt;
  210. }
  211.  
  212. /**
  213. * Set status
  214. *
  215. * @param boolean $status
  216. *
  217. * @return User
  218. */
  219. public function setStatus($status)
  220. {
  221. $this->status = $status;
  222.  
  223. return $this;
  224. }
  225.  
  226. /**
  227. * Get status
  228. *
  229. * @return boolean
  230. */
  231. public function getStatus()
  232. {
  233. return $this->status;
  234. }
  235.  
  236. /**
  237. * Set dateAdded
  238. *
  239. * @param DateTime $dateAdded
  240. *
  241. * @return User
  242. */
  243. public function setDateAdded($dateAdded)
  244. {
  245. $this->date_added = $dateAdded;
  246.  
  247. return $this;
  248. }
  249.  
  250. /**
  251. * Get dateAdded
  252. *
  253. * @return DateTime
  254. */
  255. public function getDateAdded()
  256. {
  257. return $this->date_added;
  258. }
  259.  
  260. /**
  261. * Get user roles
  262. *
  263. * @return ArrayCollection
  264. */
  265. public function getUserRoles()
  266. {
  267. return $this->userRoles;
  268. }
  269.  
  270. /**
  271. * Set isActive
  272. *
  273. * @param boolean $isActive
  274. *
  275. * @return User
  276. */
  277. public function setIsActive($isActive)
  278. {
  279. $this->isActive = $isActive;
  280.  
  281. return $this;
  282. }
  283.  
  284. /**
  285. * Get isActive
  286. *
  287. * @return boolean
  288. */
  289. public function getIsActive()
  290. {
  291. return $this->isActive;
  292. }
  293.  
  294. /**
  295. * Add userRole
  296. *
  297. * @param AppAppBundleEntityRole $userRole
  298. *
  299. * @return User
  300. */
  301. public function addUserRole(Role $userRole)
  302. {
  303. $this->userRoles[] = $userRole;
  304.  
  305. return $this;
  306. }
  307.  
  308. /**
  309. * Remove userRole
  310. *
  311. * @param AppAppBundleEntityRole $userRole
  312. */
  313. public function removeUserRole(Role $userRole)
  314. {
  315. $this->userRoles->removeElement($userRole);
  316. }
  317.  
  318. }
  319.  
  320. <?php
  321.  
  322. namespace AppAppBundleEntity;
  323.  
  324. use SymfonyComponentSecurityCoreRoleRoleInterface;
  325. use DoctrineORMMapping as ORM;
  326.  
  327. /**
  328. * @ORMEntity
  329. * @ORMTable(name="role")
  330. */
  331. class Role implements RoleInterface
  332. {
  333. /**
  334. * @ORMId
  335. * @ORMColumn(type="integer")
  336. * @ORMGeneratedValue(strategy="AUTO")
  337. *
  338. * @var integer $id
  339. */
  340. protected $id;
  341.  
  342. /**
  343. * @ORMColumn(type="string")
  344. *
  345. * @var string $name
  346. */
  347. protected $name;
  348.  
  349. /**
  350. * @ORMColumn(type="datetime", name="created_at")
  351. *
  352. * @var DateTime $createdAt
  353. */
  354. protected $createdAt;
  355.  
  356. /**
  357. * Геттер для id.
  358. *
  359. * @return integer The id.
  360. */
  361. public function getId()
  362. {
  363. return $this->id;
  364. }
  365.  
  366. /**
  367. * Геттер для названия роли.
  368. *
  369. * @return string The name.
  370. */
  371. public function getName()
  372. {
  373. return $this->name;
  374. }
  375.  
  376. /**
  377. * Сеттер для названия роли.
  378. *
  379. * @param string $value The name.
  380. */
  381. public function setName($value)
  382. {
  383. $this->name = $value;
  384. }
  385.  
  386. /**
  387. * Геттер для даты создания роли.
  388. *
  389. * @return DateTime A DateTime object.
  390. */
  391. public function getCreatedAt()
  392. {
  393. return $this->createdAt;
  394. }
  395.  
  396. /**
  397. * Конструктор класса
  398. */
  399. public function __construct()
  400. {
  401. $this->createdAt = new DateTime();
  402. }
  403.  
  404. /**
  405. * Реализация метода, требуемого интерфейсом RoleInterface.
  406. *
  407. * @return string The role.
  408. */
  409. public function getRole()
  410. {
  411. return $this->getName();
  412. }
  413. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement