Advertisement
Guest User

Untitled

a guest
Aug 22nd, 2017
460
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.65 KB | None | 0 0
  1. {
  2. "_id" : ObjectId("5995ba75a48bb0217c5fabe7"),
  3. "type" : "staff",
  4. "firstname" : "Thomas",
  5. "lastname" : "Dupont",
  6. "email" : "test.test@gmail.com",
  7. "password" : "$P$BtCPQaU7mcOqtT7Bmj4h4YUpcy/ont1",
  8. "role" : [
  9. "ADMIN"
  10. ],
  11. "apikey" : "4a6615e073f0267f1a6b258ed1750526",
  12. "job" : "dev",
  13. "phoneNumber" : "0651193342",
  14. "connectionFailed" : {
  15. "number" : 1,
  16. "time" : 1503411126
  17. }
  18. }
  19.  
  20. <?php
  21. // src/AppBundle/Document/User.php
  22.  
  23. namespace ApiBundleDocument;
  24.  
  25. use DoctrineODMMongoDBMappingAnnotations as MongoDB;
  26. use ApiBundleDocument{Staff, Customer};
  27.  
  28. /**
  29. * @MongoDBDocument
  30. * @MongoDBInheritanceType("SINGLE_COLLECTION")
  31. * @MongoDBDiscriminatorField("type")
  32. * @MongoDBDiscriminatorMap({"staff"="Staff", "customer"="Customer"})
  33. */
  34. class User
  35. {
  36. /**
  37. * @MongoDBId(strategy="auto")
  38. */
  39. protected $id;
  40.  
  41. /**
  42. * @MongoDBField(type="string")
  43. */
  44. protected $firstname;
  45.  
  46. /**
  47. * @MongoDBField(type="string")
  48. */
  49. protected $lastname;
  50.  
  51. /**
  52. * @MongoDBField(type="string")
  53. */
  54. protected $email;
  55.  
  56. /**
  57. * @MongoDBField(type="string")
  58. */
  59. protected $password;
  60.  
  61. /**
  62. * @MongoDBField(type="collection")
  63. */
  64. protected $role = [];
  65.  
  66. /**
  67. * @MongoDBField(type="string")
  68. */
  69. protected $apikey;
  70.  
  71. /**
  72. * @MongoDBHash
  73. */
  74. protected $connectionFailed;
  75.  
  76. /**
  77. * Set type
  78. *
  79. * @param string $type
  80. * @return $this
  81. */
  82. public function setType($type)
  83. {
  84. $this->type = $type;
  85. return $this;
  86. }
  87.  
  88. /**
  89. * Get type
  90. *
  91. * @return string $type
  92. */
  93. public function getType()
  94. {
  95. return get_called_class();
  96. }
  97.  
  98. /**
  99. * Get id
  100. *
  101. * @return id $id
  102. */
  103. public function getId()
  104. {
  105. return $this->id;
  106. }
  107.  
  108. /**
  109. * Set firstname
  110. *
  111. * @param string $firstname
  112. * @return $this
  113. */
  114. public function setFirstname($firstname)
  115. {
  116. $this->firstname = $firstname;
  117. return $this;
  118. }
  119.  
  120. /**
  121. * Get firstname
  122. *
  123. * @return string $firstname
  124. */
  125. public function getFirstname()
  126. {
  127. return $this->firstname;
  128. }
  129.  
  130. /**
  131. * Set lastname
  132. *
  133. * @param string $lastname
  134. * @return $this
  135. */
  136. public function setLastname($lastname)
  137. {
  138. $this->lastname = $lastname;
  139. return $this;
  140. }
  141.  
  142. /**
  143. * Get lastname
  144. *
  145. * @return string $lastname
  146. */
  147. public function getLastname()
  148. {
  149. return $this->lastname;
  150. }
  151.  
  152. /**
  153. * Set email
  154. *
  155. * @param string $email
  156. * @return $this
  157. */
  158. public function setEmail($email)
  159. {
  160. $this->email = $email;
  161. return $this;
  162. }
  163.  
  164. /**
  165. * Get email
  166. *
  167. * @return string $email
  168. */
  169. public function getEmail()
  170. {
  171. return $this->email;
  172. }
  173.  
  174. /**
  175. * Set password
  176. *
  177. * @param string $password
  178. * @return $this
  179. */
  180. public function setPassword($password)
  181. {
  182. $this->password = $password;
  183. return $this;
  184. }
  185.  
  186. /**
  187. * Get password
  188. *
  189. * @return string $password
  190. */
  191. public function getPassword()
  192. {
  193. return $this->password;
  194. }
  195.  
  196. /**
  197. * Set role
  198. *
  199. * @param collection $role
  200. * @return $this
  201. */
  202. public function setRole($role)
  203. {
  204. $this->role = $role;
  205. return $this;
  206. }
  207.  
  208. /**
  209. * Get role
  210. *
  211. * @return collection $role
  212. */
  213. public function getRole()
  214. {
  215. return $this->role;
  216. }
  217.  
  218. public function toArray() {
  219. $tmp = [];
  220. foreach($this as $key => $value) {
  221. $tmp[$key] = $value;
  222. }
  223. return $tmp;
  224. }
  225.  
  226. /**
  227. * Set apikey
  228. *
  229. * @return $this
  230. */
  231. public function setApikey()
  232. {
  233. $this->apikey = md5(uniqid());
  234. return $this;
  235. }
  236.  
  237. /**
  238. * Get apikey
  239. *
  240. * @return string $apikey
  241. */
  242. public function getApikey()
  243. {
  244. return $this->apikey;
  245. }
  246.  
  247. /**
  248. * Set connectionFailed
  249. *
  250. * @param hash $connectionFailed
  251. * @return $this
  252. */
  253. public function setConnectionFailed($connectionFailed)
  254. {
  255. $this->connectionFailed = $connectionFailed;
  256. return $this;
  257. }
  258.  
  259. /**
  260. * Get connectionFailed
  261. *
  262. * @return hash $connectionFailed
  263. */
  264. public function getConnectionFailed()
  265. {
  266. return $this->connectionFailed;
  267. }
  268. }
  269.  
  270. $user = $this->dm
  271. ->getRepository('ApiBundle:User')
  272. ->findOneBy(['email' => $email]);
  273. return $user->toArray();
  274.  
  275. php bin/console cache:clear
  276. rm -rf app/cache/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement