Passed
Push — master ( 919982...5e7ad6 )
by Anthony
03:16
created
Repository/AccountRepository.php 1 patch
Indentation   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -7,21 +7,21 @@
 block discarded – undo
7 7
 
8 8
 class AccountRepository extends EntityRepository
9 9
 {
10
-    /**
11
-     * function that return a list of all users that are not archived and different of current account
12
-     * @param User $current_account
13
-     * @param bool $archived
14
-     * @return array
15
-     */
16
-    public function findAllUserArchived(User $current_account, bool $archived = false): array
17
-    {
18
-        $query = $this->getEntityManager()->createQuery("SELECT fu FROM RibsAdminBundle:Account fu
10
+				/**
11
+				 * function that return a list of all users that are not archived and different of current account
12
+				 * @param User $current_account
13
+				 * @param bool $archived
14
+				 * @return array
15
+				 */
16
+				public function findAllUserArchived(User $current_account, bool $archived = false): array
17
+				{
18
+								$query = $this->getEntityManager()->createQuery("SELECT fu FROM RibsAdminBundle:Account fu
19 19
 			  JOIN RibsAdminBundle:User u  WITH fu.user = u
20 20
 			  WHERE u.archived = :archived and u != :current_account
21 21
 			")
22
-            ->setParameter("archived", $archived)
23
-            ->setParameter("current_account", $current_account);
22
+												->setParameter("archived", $archived)
23
+												->setParameter("current_account", $current_account);
24 24
 
25
-        return $query->getResult();
26
-    }
25
+								return $query->getResult();
26
+				}
27 27
 }
Please login to merge, or discard this patch.
Repository/AccessRightRepository.php 1 patch
Indentation   +24 added lines, -24 removed lines patch added patch discarded remove patch
@@ -8,33 +8,33 @@
 block discarded – undo
8 8
 
9 9
 class AccessRightRepository extends EntityRepository
10 10
 {
11
-    /**
12
-     * function that delete all user which are in a list of rights
13
-     * @param AccessRight $access_right
14
-     * @throws DBALException
15
-     */
16
-    public function deleteAllUsersList(AccessRight $access_right)
17
-    {
18
-        $query = $this->getEntityManager()->getConnection()->prepare("UPDATE user SET id_access_right = NULL WHERE
11
+				/**
12
+				 * function that delete all user which are in a list of rights
13
+				 * @param AccessRight $access_right
14
+				 * @throws DBALException
15
+				 */
16
+				public function deleteAllUsersList(AccessRight $access_right)
17
+				{
18
+								$query = $this->getEntityManager()->getConnection()->prepare("UPDATE user SET id_access_right = NULL WHERE
19 19
  			id_access_right = :id_access_right
20 20
  		");
21
-        $query->bindValue("id_access_right", $access_right->getId());
22
-        $query->execute();
23
-    }
21
+								$query->bindValue("id_access_right", $access_right->getId());
22
+								$query->execute();
23
+				}
24 24
 
25
-    /**
26
-     * function that add a user in an access right list
27
-     * @param int $access_right_id
28
-     * @param string $guid_admin
29
-     * @throws DBALException
30
-     */
31
-    public function setAccessRightListUser(int $access_right_id, string $guid_admin)
32
-    {
33
-        $query = $this->getEntityManager()->getConnection()->prepare("UPDATE user SET id_access_right = :id_access_right WHERE
25
+				/**
26
+				 * function that add a user in an access right list
27
+				 * @param int $access_right_id
28
+				 * @param string $guid_admin
29
+				 * @throws DBALException
30
+				 */
31
+				public function setAccessRightListUser(int $access_right_id, string $guid_admin)
32
+				{
33
+								$query = $this->getEntityManager()->getConnection()->prepare("UPDATE user SET id_access_right = :id_access_right WHERE
34 34
  			guid = :guid_user
35 35
  		");
36
-        $query->bindValue("id_access_right", $access_right_id, \PDO::PARAM_INT);
37
-        $query->bindValue("guid_user", $guid_admin, \PDO::PARAM_STR);
38
-        $query->execute();
39
-    }
36
+								$query->bindValue("id_access_right", $access_right_id, \PDO::PARAM_INT);
37
+								$query->bindValue("guid_user", $guid_admin, \PDO::PARAM_STR);
38
+								$query->execute();
39
+				}
40 40
 }
Please login to merge, or discard this patch.
Entity/AccountToken.php 1 patch
Indentation   +152 added lines, -152 removed lines patch added patch discarded remove patch
@@ -16,156 +16,156 @@
 block discarded – undo
16 16
  */
17 17
 class AccountToken
18 18
 {
19
-    use GuidTrait;
20
-
21
-    /**
22
-     * @ORM\Id
23
-     * @ORM\Column(type="integer")
24
-     * @ORM\GeneratedValue(strategy="AUTO")
25
-     */
26
-    protected $id;
27
-
28
-    /**
29
-     * @ORM\Column(type="string", length=200)
30
-     */
31
-    protected $token;
32
-
33
-    /**
34
-     * @ORM\Column(type="datetime", nullable=true)
35
-     */
36
-    protected $endToken;
37
-
38
-    /**
39
-     * @ORM\Column(type="string", length=200)
40
-     */
41
-    protected $userAgent;
42
-
43
-    /**
44
-     * @ORM\Column(type="string", length=200)
45
-     */
46
-    protected $ip;
47
-
48
-    /**
49
-     * @ORM\ManyToOne(targetEntity="Account", inversedBy="tokens")
50
-     * @ORM\JoinColumn(name="account_id", referencedColumnName="id", nullable=false)
51
-     */
52
-    protected $account;
53
-
54
-    /**
55
-     * @return mixed
56
-     */
57
-    public function getId()
58
-    {
59
-        return $this->id;
60
-    }
61
-
62
-    /**
63
-     * @param mixed $id
64
-     * @return AccountToken
65
-     */
66
-    public function setId($id)
67
-    {
68
-        $this->id = $id;
69
-
70
-        return $this;
71
-    }
72
-
73
-    /**
74
-     * @return mixed
75
-     */
76
-    public function getToken()
77
-    {
78
-        return $this->token;
79
-    }
80
-
81
-    /**
82
-     * @param mixed $token
83
-     * @return AccountToken
84
-     */
85
-    public function setToken($token)
86
-    {
87
-        $this->token = $token;
88
-
89
-        return $this;
90
-    }
91
-
92
-    /**
93
-     * @return mixed
94
-     */
95
-    public function getEndToken()
96
-    {
97
-        return $this->endToken;
98
-    }
99
-
100
-    /**
101
-     * @param mixed $endToken
102
-     * @return AccountToken
103
-     */
104
-    public function setEndToken($endToken)
105
-    {
106
-        $this->endToken = $endToken;
107
-
108
-        return $this;
109
-    }
110
-
111
-    /**
112
-     * @return mixed
113
-     */
114
-    public function getUserAgent()
115
-    {
116
-        return $this->userAgent;
117
-    }
118
-
119
-    /**
120
-     * @param mixed $userAgent
121
-     * @return AccountToken
122
-     */
123
-    public function setUserAgent($userAgent)
124
-    {
125
-        $this->userAgent = $userAgent;
126
-
127
-        return $this;
128
-    }
129
-
130
-    /**
131
-     * @return mixed
132
-     */
133
-    public function getIp()
134
-    {
135
-        return $this->ip;
136
-    }
137
-
138
-    /**
139
-     * @param mixed $ip
140
-     * @return AccountToken
141
-     */
142
-    public function setIp($ip)
143
-    {
144
-        $this->ip = $ip;
145
-
146
-        return $this;
147
-    }
148
-
149
-    /**
150
-     * Set Account entity (many to one).
151
-     *
152
-     * @param Account $account
153
-     * @return AccountToken
154
-     */
155
-    public function setAccount(Account $account = null)
156
-    {
157
-        $this->account = $account;
158
-
159
-        return $this;
160
-    }
161
-
162
-    /**
163
-     * Get Account entity (many to one).
164
-     *
165
-     * @return Account
166
-     */
167
-    public function getAccount()
168
-    {
169
-        return $this->account;
170
-    }
19
+				use GuidTrait;
20
+
21
+				/**
22
+				 * @ORM\Id
23
+				 * @ORM\Column(type="integer")
24
+				 * @ORM\GeneratedValue(strategy="AUTO")
25
+				 */
26
+				protected $id;
27
+
28
+				/**
29
+				 * @ORM\Column(type="string", length=200)
30
+				 */
31
+				protected $token;
32
+
33
+				/**
34
+				 * @ORM\Column(type="datetime", nullable=true)
35
+				 */
36
+				protected $endToken;
37
+
38
+				/**
39
+				 * @ORM\Column(type="string", length=200)
40
+				 */
41
+				protected $userAgent;
42
+
43
+				/**
44
+				 * @ORM\Column(type="string", length=200)
45
+				 */
46
+				protected $ip;
47
+
48
+				/**
49
+				 * @ORM\ManyToOne(targetEntity="Account", inversedBy="tokens")
50
+				 * @ORM\JoinColumn(name="account_id", referencedColumnName="id", nullable=false)
51
+				 */
52
+				protected $account;
53
+
54
+				/**
55
+				 * @return mixed
56
+				 */
57
+				public function getId()
58
+				{
59
+								return $this->id;
60
+				}
61
+
62
+				/**
63
+				 * @param mixed $id
64
+				 * @return AccountToken
65
+				 */
66
+				public function setId($id)
67
+				{
68
+								$this->id = $id;
69
+
70
+								return $this;
71
+				}
72
+
73
+				/**
74
+				 * @return mixed
75
+				 */
76
+				public function getToken()
77
+				{
78
+								return $this->token;
79
+				}
80
+
81
+				/**
82
+				 * @param mixed $token
83
+				 * @return AccountToken
84
+				 */
85
+				public function setToken($token)
86
+				{
87
+								$this->token = $token;
88
+
89
+								return $this;
90
+				}
91
+
92
+				/**
93
+				 * @return mixed
94
+				 */
95
+				public function getEndToken()
96
+				{
97
+								return $this->endToken;
98
+				}
99
+
100
+				/**
101
+				 * @param mixed $endToken
102
+				 * @return AccountToken
103
+				 */
104
+				public function setEndToken($endToken)
105
+				{
106
+								$this->endToken = $endToken;
107
+
108
+								return $this;
109
+				}
110
+
111
+				/**
112
+				 * @return mixed
113
+				 */
114
+				public function getUserAgent()
115
+				{
116
+								return $this->userAgent;
117
+				}
118
+
119
+				/**
120
+				 * @param mixed $userAgent
121
+				 * @return AccountToken
122
+				 */
123
+				public function setUserAgent($userAgent)
124
+				{
125
+								$this->userAgent = $userAgent;
126
+
127
+								return $this;
128
+				}
129
+
130
+				/**
131
+				 * @return mixed
132
+				 */
133
+				public function getIp()
134
+				{
135
+								return $this->ip;
136
+				}
137
+
138
+				/**
139
+				 * @param mixed $ip
140
+				 * @return AccountToken
141
+				 */
142
+				public function setIp($ip)
143
+				{
144
+								$this->ip = $ip;
145
+
146
+								return $this;
147
+				}
148
+
149
+				/**
150
+				 * Set Account entity (many to one).
151
+				 *
152
+				 * @param Account $account
153
+				 * @return AccountToken
154
+				 */
155
+				public function setAccount(Account $account = null)
156
+				{
157
+								$this->account = $account;
158
+
159
+								return $this;
160
+				}
161
+
162
+				/**
163
+				 * Get Account entity (many to one).
164
+				 *
165
+				 * @return Account
166
+				 */
167
+				public function getAccount()
168
+				{
169
+								return $this->account;
170
+				}
171 171
 }
Please login to merge, or discard this patch.
Service/AccessRights.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -96,7 +96,7 @@
 block discarded – undo
96 96
 		
97 97
 		$ribs_admin_rights = json_decode(file_get_contents($this->globals->getBaseBundlePath() . "/Resources/json/ribsadmin_rights.json"));
98 98
 		$modules_rights = $this->module->getModuleRights();
99
-		$ribs_admin_rights = (object)array_merge((array)$ribs_admin_rights, (array)$modules_rights);
99
+		$ribs_admin_rights = (object) array_merge((array) $ribs_admin_rights, (array) $modules_rights);
100 100
 		
101 101
 		if ($admin_page == "ribsadmin" && !$api && strpos($route, "login") === false && strpos($route, "register") === false) {
102 102
 			//redirection if user not connected
Please login to merge, or discard this patch.
Indentation   +31 added lines, -31 removed lines patch added patch discarded remove patch
@@ -43,10 +43,10 @@  discard block
 block discarded – undo
43 43
 	 */
44 44
 	private $module;
45 45
 
46
-    /**
47
-     * @var Api
48
-     */
49
-    private $api;
46
+				/**
47
+				 * @var Api
48
+				 */
49
+				private $api;
50 50
 	
51 51
 	/**
52 52
 	 * @var User
@@ -56,17 +56,17 @@  discard block
 block discarded – undo
56 56
 	/** @var TokenStorageInterface */
57 57
 	private $token_storage;
58 58
 
59
-    /**
60
-     * AccessRights constructor.
61
-     * @param ContainerInterface $container
62
-     * @param RouterInterface $router
63
-     * @param SessionInterface $session
64
-     * @param RequestStack $request
65
-     * @param TokenStorageInterface $tokenStorage
66
-     * @param Globals $globals
67
-     * @param ModuleService $module
68
-     * @param Api $api
69
-     */
59
+				/**
60
+				 * AccessRights constructor.
61
+				 * @param ContainerInterface $container
62
+				 * @param RouterInterface $router
63
+				 * @param SessionInterface $session
64
+				 * @param RequestStack $request
65
+				 * @param TokenStorageInterface $tokenStorage
66
+				 * @param Globals $globals
67
+				 * @param ModuleService $module
68
+				 * @param Api $api
69
+				 */
70 70
 	public function __construct(ContainerInterface $container, RouterInterface $router, SessionInterface $session, RequestStack $request, TokenStorageInterface $tokenStorage, Globals $globals, ModuleService $module, Api $api)
71 71
 	{
72 72
 		$this->container = $container;
@@ -78,8 +78,8 @@  discard block
 block discarded – undo
78 78
 		$this->api = $api;
79 79
 		$this->token_storage = $tokenStorage;
80 80
 		if ($this->token_storage->getToken() && is_object($this->token_storage->getToken()->getUser()) && $this->token_storage->getToken()->getUser()->getUser()) {
81
-            $this->user = $this->token_storage->getToken()->getUser()->getUser();
82
-        }
81
+												$this->user = $this->token_storage->getToken()->getUser()->getUser();
82
+								}
83 83
 	}
84 84
 	
85 85
 	public function onKernelController()
@@ -120,14 +120,14 @@  discard block
 block discarded – undo
120 120
 			
121 121
 			throw new AccessDeniedException("No access");
122 122
 		} else if ($api && strpos($route, "login") === false && strpos($route, "register") === false) {
123
-            if ($this->api->userIslogged($this->request->getCurrentRequest()->get("infos"), $this->request->getCurrentRequest()->get("token")) === false) {
124
-                throw new AccessDeniedException("User is not connected");
125
-            }
126
-        }
123
+												if ($this->api->userIslogged($this->request->getCurrentRequest()->get("infos"), $this->request->getCurrentRequest()->get("token")) === false) {
124
+																throw new AccessDeniedException("User is not connected");
125
+												}
126
+								}
127 127
 	}
128 128
 	
129 129
 	/**
130
-     * function that allow to test a right directly in the view
130
+	 * function that allow to test a right directly in the view
131 131
 	 * @param string $right
132 132
 	 * @return bool
133 133
 	 */
@@ -138,9 +138,9 @@  discard block
 block discarded – undo
138 138
 		
139 139
 		$all_rights = array_merge($user_rights, $list_rights);
140 140
 
141
-        if (in_array("*", $all_rights)) {
142
-            return true;
143
-        }
141
+								if (in_array("*", $all_rights)) {
142
+												return true;
143
+								}
144 144
 
145 145
 		if (in_array($right, $all_rights)) {
146 146
 			return true;
@@ -150,7 +150,7 @@  discard block
 block discarded – undo
150 150
 	}
151 151
 	
152 152
 	/**
153
-     * test if route_right is found in users rights
153
+	 * test if route_right is found in users rights
154 154
 	 * @param array $route_right
155 155
 	 * @return bool
156 156
 	 */
@@ -162,8 +162,8 @@  discard block
 block discarded – undo
162 162
 		$all_rights = array_merge($user_rights, $list_rights);
163 163
 
164 164
 		if (in_array("*", $all_rights)) {
165
-		    return true;
166
-        }
165
+						return true;
166
+								}
167 167
 
168 168
 		foreach ($all_rights as $right) {
169 169
 			if (in_array($right, $route_right)) {
@@ -175,7 +175,7 @@  discard block
 block discarded – undo
175 175
 	}
176 176
 	
177 177
 	/**
178
-     * function that search if the right contain an url or more
178
+	 * function that search if the right contain an url or more
179 179
 	 * @param $needle
180 180
 	 * @param $haystack
181 181
 	 * @return bool|mixed
@@ -199,7 +199,7 @@  discard block
 block discarded – undo
199 199
 	}
200 200
 	
201 201
 	/**
202
-     * function that retun a array that contain all user rights or empty array if no right found
202
+	 * function that retun a array that contain all user rights or empty array if no right found
203 203
 	 * @return array
204 204
 	 */
205 205
 	private function getUserRights(): array
@@ -214,7 +214,7 @@  discard block
 block discarded – undo
214 214
 	}
215 215
 	
216 216
 	/**
217
-     * function that retun a array that contain all rights of rattached list right of the current user
217
+	 * function that retun a array that contain all rights of rattached list right of the current user
218 218
 	 * @return array
219 219
 	 */
220 220
 	private function getRightsListOfUser(): array
Please login to merge, or discard this patch.
Service/UserLog.php 1 patch
Indentation   +47 added lines, -47 removed lines patch added patch discarded remove patch
@@ -9,51 +9,51 @@
 block discarded – undo
9 9
 
10 10
 class UserLog
11 11
 {
12
-    /**
13
-     * @var TokenStorageInterface
14
-     */
15
-    private $token_storage;
16
-
17
-    /**
18
-     * @var EntityManagerInterface a
19
-     */
20
-    private $em;
21
-
22
-    public function __construct(TokenStorageInterface $token_storage, EntityManagerInterface $em)
23
-    {
24
-        $this->token_storage = $token_storage;
25
-        $this->em = $em;
26
-    }
27
-
28
-    /**
29
-     * @param RequestEvent $request_event
30
-     */
31
-    public function onKernelRequest(RequestEvent $request_event)
32
-    {
33
-        if ($request_event->isMasterRequest()) {
34
-            $user = null;
35
-            if ($this->token_storage->getToken() && is_object($this->token_storage->getToken()->getUser()) && $this->token_storage->getToken()->getUser()->getUser()) {
36
-                $user = $this->token_storage->getToken()->getUser()->getUser();
37
-            }
38
-            $request = $request_event->getRequest();
39
-            $route = $request->get("_route");
40
-
41
-            if (in_array($route, ["_profiler", "_profiler_search_bar", "_wdt", "ribsadmin_userlogs", "ribsadmin_userlogs_show"])) {
42
-                return;
43
-            }
44
-
45
-            if ($user) {
46
-                $user_log = new UserLogs();
47
-                $user_log->setMethod($request->getMethod());
48
-                $user_log->setUser($user);
49
-                $user_log->setRoute($request->get("_route"));
50
-                $user_log->setUrl($request->getRequestUri());
51
-                $user_log->setFullUrl($request->getUri());
52
-                $user_log->setRequestFormat($request->getRequestFormat());
53
-                $user_log->setRequestParameters($request->request->all());
54
-                $this->em->persist($user_log);
55
-                $this->em->flush();
56
-            }
57
-        }
58
-    }
12
+				/**
13
+				 * @var TokenStorageInterface
14
+				 */
15
+				private $token_storage;
16
+
17
+				/**
18
+				 * @var EntityManagerInterface a
19
+				 */
20
+				private $em;
21
+
22
+				public function __construct(TokenStorageInterface $token_storage, EntityManagerInterface $em)
23
+				{
24
+								$this->token_storage = $token_storage;
25
+								$this->em = $em;
26
+				}
27
+
28
+				/**
29
+				 * @param RequestEvent $request_event
30
+				 */
31
+				public function onKernelRequest(RequestEvent $request_event)
32
+				{
33
+								if ($request_event->isMasterRequest()) {
34
+												$user = null;
35
+												if ($this->token_storage->getToken() && is_object($this->token_storage->getToken()->getUser()) && $this->token_storage->getToken()->getUser()->getUser()) {
36
+																$user = $this->token_storage->getToken()->getUser()->getUser();
37
+												}
38
+												$request = $request_event->getRequest();
39
+												$route = $request->get("_route");
40
+
41
+												if (in_array($route, ["_profiler", "_profiler_search_bar", "_wdt", "ribsadmin_userlogs", "ribsadmin_userlogs_show"])) {
42
+																return;
43
+												}
44
+
45
+												if ($user) {
46
+																$user_log = new UserLogs();
47
+																$user_log->setMethod($request->getMethod());
48
+																$user_log->setUser($user);
49
+																$user_log->setRoute($request->get("_route"));
50
+																$user_log->setUrl($request->getRequestUri());
51
+																$user_log->setFullUrl($request->getUri());
52
+																$user_log->setRequestFormat($request->getRequestFormat());
53
+																$user_log->setRequestParameters($request->request->all());
54
+																$this->em->persist($user_log);
55
+																$this->em->flush();
56
+												}
57
+								}
58
+				}
59 59
 }
Please login to merge, or discard this patch.
Service/Api.php 2 patches
Indentation   +188 added lines, -188 removed lines patch added patch discarded remove patch
@@ -23,192 +23,192 @@
 block discarded – undo
23 23
 
24 24
 class Api
25 25
 {
26
-    /**
27
-     * @var ContainerInterface
28
-     */
29
-    private $container;
30
-
31
-    /**
32
-     * @var EntityManagerInterface
33
-     */
34
-    private $em;
35
-
36
-    /**
37
-     * @var SessionInterface
38
-     */
39
-    private $session;
40
-
41
-    /**
42
-     * @var Account
43
-     */
44
-    private $account;
45
-
46
-    /**
47
-     * @var Request|null
48
-     */
49
-    private $request;
50
-
51
-    /**
52
-     * Api constructor.
53
-     * @param ContainerInterface $container
54
-     * @param EntityManagerInterface $em
55
-     * @param SessionInterface $session
56
-     * @param RequestStack $request_stack
57
-     */
58
-    public function __construct(ContainerInterface $container, EntityManagerInterface $em, SessionInterface $session, RequestStack $request_stack)
59
-    {
60
-        $this->container = $container;
61
-        $this->em = $em;
62
-        $this->session = $session;
63
-        $this->request = $request_stack->getCurrentRequest();
64
-    }
65
-
66
-    /**
67
-     * this method is used to test jwt and if the account is ok else send false
68
-     * @param string $infos_jwt
69
-     * @param string $token
70
-     * @return bool
71
-     * @throws Exception
72
-     */
73
-    public function userIslogged(string $infos_jwt, string $token): bool
74
-    {
75
-        $em = $this->em;
76
-        $jwt = Jwt::decode($infos_jwt, $token);
77
-
78
-        if ($jwt === false) {
79
-            return false;
80
-        }
81
-
82
-        $account_token_search = [
83
-            "token" => $token,
84
-            "userAgent" => $this->request->server->get("HTTP_USER_AGENT"),
85
-            "ip" => $this->request->server->get("REMOTE_ADDR")
86
-        ];
87
-        if (preg_match('/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows (ce|phone)|xda|xiino/i',$this->request->server->get("HTTP_USER_AGENT"))||preg_match('/1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i',substr($this->request->server->get("HTTP_USER_AGENT"),0,4))) {
88
-            $account_token_search = [
89
-                "token" => $token,
90
-                "userAgent" => $this->request->server->get("HTTP_USER_AGENT"),
91
-            ];
92
-        }
93
-
94
-        $account_token = $em->getRepository(AccountToken::class)->findOneBy($account_token_search);
95
-
96
-        if (!$account_token) {
97
-            return false;
98
-        }
99
-
100
-        $this->account = $em->getRepository(Account::class)->findOneBy([
101
-            "id" => $account_token->getAccount()->getId(),
102
-            "isActive" => true,
103
-        ]);
104
-
105
-        if (!$this->account) {
106
-            return false;
107
-        }
108
-
109
-        $this->account->setLastConnection(new \DateTime());
110
-        $em->persist($this->account);
111
-        $em->flush();
112
-
113
-        $this->getToken($this->account);
114
-        $this->session->set("jwt_infos", $jwt);
115
-        $this->session->set("account", $this->account);
116
-        $this->session->set("account_token", $account_token);
117
-
118
-        return true;
119
-    }
120
-
121
-    /**
122
-     * method that return the token for a account
123
-     * @param Account $account
124
-     * @return string
125
-     * @throws Exception
126
-     */
127
-    public function getToken(Account $account): string
128
-    {
129
-        $account_token = $this->em->getRepository(AccountToken::class)->findOneBy([
130
-            "account" => $account,
131
-            "userAgent" => $this->request->server->get("HTTP_USER_AGENT"),
132
-            "ip" => $this->request->server->get("REMOTE_ADDR")
133
-        ]);
134
-
135
-        $token = $account_token ? $account_token->getToken() : null;
136
-        $now = new \DateTime();
137
-
138
-        if ($token === null || $account_token->getEndToken() < $now) {
139
-            return $this->setToken($account, $account_token);
140
-        }
141
-
142
-        return $token;
143
-    }
144
-
145
-    /**
146
-     * @param Account $account
147
-     * @param $account_token
148
-     * @return string
149
-     * method that set a token for the account
150
-     * @throws Exception
151
-     */
152
-    public function setToken(Account $account, $account_token): string
153
-    {
154
-        $token = $this->generateToken();
155
-        $now = new \DateTime();
156
-        $end_token = $now->add(new \DateInterval("PT".$this->container->getParameter("ribs_admin.api_token_duration")."M"));
157
-
158
-        if (!$account_token) {
159
-            $account_token = new AccountToken();
160
-        }
161
-
162
-        $account_token->setToken($token);
163
-        $account_token->setUserAgent($this->request->server->get("HTTP_USER_AGENT"));
164
-        $account_token->setIp($this->request->server->get("REMOTE_ADDR"));
165
-        $account_token->setEndToken($end_token);
166
-        $account_token->setAccount($account);
167
-        $this->em->persist($account_token);
168
-        $this->em->flush();
169
-
170
-        $this->account = $account;
171
-        $this->session->set("account", $this->account);
172
-        $this->session->set("account_token", $account_token);
173
-
174
-        return $token;
175
-    }
176
-
177
-    /**
178
-     * generate a token for api
179
-     * @param int $length
180
-     * @return string
181
-     */
182
-    public function generateToken(int $length = 200): string
183
-    {
184
-        $string = "abcdefghijklmnopqrstuvwxyzABCDEFGHJKMNPQRSTUVWXYZ23456789";
185
-        $token = "";
186
-        srand((double)microtime() * 1000000);
187
-        for ($i = 0; $i < $length; $i++) {
188
-            $token .= $string[rand() % strlen($string)];
189
-        }
190
-
191
-        return $token;
192
-    }
193
-
194
-    /**
195
-     * method that encode an object to a json
196
-     * @param $object
197
-     * @param string $type
198
-     * @return mixed
199
-     * @throws ExceptionInterface
200
-     * @throws AnnotationException
201
-     */
202
-    public function serializeObject($object, $type = "json")
203
-    {
204
-        $classMetadataFactory = new ClassMetadataFactory(new AnnotationLoader(new AnnotationReader()));
205
-        $serializer = new Serializer([new DateTimeNormalizer(), new ObjectNormalizer($classMetadataFactory)], [new XmlEncoder(), new JsonEncoder()]);
206
-
207
-        return $serializer->normalize($object, $type, [
208
-            'circular_reference_handler' => function ($object) {
209
-                return $object->getId();
210
-            },
211
-            'groups' => 'main'
212
-        ]);
213
-    }
26
+				/**
27
+				 * @var ContainerInterface
28
+				 */
29
+				private $container;
30
+
31
+				/**
32
+				 * @var EntityManagerInterface
33
+				 */
34
+				private $em;
35
+
36
+				/**
37
+				 * @var SessionInterface
38
+				 */
39
+				private $session;
40
+
41
+				/**
42
+				 * @var Account
43
+				 */
44
+				private $account;
45
+
46
+				/**
47
+				 * @var Request|null
48
+				 */
49
+				private $request;
50
+
51
+				/**
52
+				 * Api constructor.
53
+				 * @param ContainerInterface $container
54
+				 * @param EntityManagerInterface $em
55
+				 * @param SessionInterface $session
56
+				 * @param RequestStack $request_stack
57
+				 */
58
+				public function __construct(ContainerInterface $container, EntityManagerInterface $em, SessionInterface $session, RequestStack $request_stack)
59
+				{
60
+								$this->container = $container;
61
+								$this->em = $em;
62
+								$this->session = $session;
63
+								$this->request = $request_stack->getCurrentRequest();
64
+				}
65
+
66
+				/**
67
+				 * this method is used to test jwt and if the account is ok else send false
68
+				 * @param string $infos_jwt
69
+				 * @param string $token
70
+				 * @return bool
71
+				 * @throws Exception
72
+				 */
73
+				public function userIslogged(string $infos_jwt, string $token): bool
74
+				{
75
+								$em = $this->em;
76
+								$jwt = Jwt::decode($infos_jwt, $token);
77
+
78
+								if ($jwt === false) {
79
+												return false;
80
+								}
81
+
82
+								$account_token_search = [
83
+												"token" => $token,
84
+												"userAgent" => $this->request->server->get("HTTP_USER_AGENT"),
85
+												"ip" => $this->request->server->get("REMOTE_ADDR")
86
+								];
87
+								if (preg_match('/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows (ce|phone)|xda|xiino/i',$this->request->server->get("HTTP_USER_AGENT"))||preg_match('/1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i',substr($this->request->server->get("HTTP_USER_AGENT"),0,4))) {
88
+												$account_token_search = [
89
+																"token" => $token,
90
+																"userAgent" => $this->request->server->get("HTTP_USER_AGENT"),
91
+												];
92
+								}
93
+
94
+								$account_token = $em->getRepository(AccountToken::class)->findOneBy($account_token_search);
95
+
96
+								if (!$account_token) {
97
+												return false;
98
+								}
99
+
100
+								$this->account = $em->getRepository(Account::class)->findOneBy([
101
+												"id" => $account_token->getAccount()->getId(),
102
+												"isActive" => true,
103
+								]);
104
+
105
+								if (!$this->account) {
106
+												return false;
107
+								}
108
+
109
+								$this->account->setLastConnection(new \DateTime());
110
+								$em->persist($this->account);
111
+								$em->flush();
112
+
113
+								$this->getToken($this->account);
114
+								$this->session->set("jwt_infos", $jwt);
115
+								$this->session->set("account", $this->account);
116
+								$this->session->set("account_token", $account_token);
117
+
118
+								return true;
119
+				}
120
+
121
+				/**
122
+				 * method that return the token for a account
123
+				 * @param Account $account
124
+				 * @return string
125
+				 * @throws Exception
126
+				 */
127
+				public function getToken(Account $account): string
128
+				{
129
+								$account_token = $this->em->getRepository(AccountToken::class)->findOneBy([
130
+												"account" => $account,
131
+												"userAgent" => $this->request->server->get("HTTP_USER_AGENT"),
132
+												"ip" => $this->request->server->get("REMOTE_ADDR")
133
+								]);
134
+
135
+								$token = $account_token ? $account_token->getToken() : null;
136
+								$now = new \DateTime();
137
+
138
+								if ($token === null || $account_token->getEndToken() < $now) {
139
+												return $this->setToken($account, $account_token);
140
+								}
141
+
142
+								return $token;
143
+				}
144
+
145
+				/**
146
+				 * @param Account $account
147
+				 * @param $account_token
148
+				 * @return string
149
+				 * method that set a token for the account
150
+				 * @throws Exception
151
+				 */
152
+				public function setToken(Account $account, $account_token): string
153
+				{
154
+								$token = $this->generateToken();
155
+								$now = new \DateTime();
156
+								$end_token = $now->add(new \DateInterval("PT".$this->container->getParameter("ribs_admin.api_token_duration")."M"));
157
+
158
+								if (!$account_token) {
159
+												$account_token = new AccountToken();
160
+								}
161
+
162
+								$account_token->setToken($token);
163
+								$account_token->setUserAgent($this->request->server->get("HTTP_USER_AGENT"));
164
+								$account_token->setIp($this->request->server->get("REMOTE_ADDR"));
165
+								$account_token->setEndToken($end_token);
166
+								$account_token->setAccount($account);
167
+								$this->em->persist($account_token);
168
+								$this->em->flush();
169
+
170
+								$this->account = $account;
171
+								$this->session->set("account", $this->account);
172
+								$this->session->set("account_token", $account_token);
173
+
174
+								return $token;
175
+				}
176
+
177
+				/**
178
+				 * generate a token for api
179
+				 * @param int $length
180
+				 * @return string
181
+				 */
182
+				public function generateToken(int $length = 200): string
183
+				{
184
+								$string = "abcdefghijklmnopqrstuvwxyzABCDEFGHJKMNPQRSTUVWXYZ23456789";
185
+								$token = "";
186
+								srand((double)microtime() * 1000000);
187
+								for ($i = 0; $i < $length; $i++) {
188
+												$token .= $string[rand() % strlen($string)];
189
+								}
190
+
191
+								return $token;
192
+				}
193
+
194
+				/**
195
+				 * method that encode an object to a json
196
+				 * @param $object
197
+				 * @param string $type
198
+				 * @return mixed
199
+				 * @throws ExceptionInterface
200
+				 * @throws AnnotationException
201
+				 */
202
+				public function serializeObject($object, $type = "json")
203
+				{
204
+								$classMetadataFactory = new ClassMetadataFactory(new AnnotationLoader(new AnnotationReader()));
205
+								$serializer = new Serializer([new DateTimeNormalizer(), new ObjectNormalizer($classMetadataFactory)], [new XmlEncoder(), new JsonEncoder()]);
206
+
207
+								return $serializer->normalize($object, $type, [
208
+												'circular_reference_handler' => function ($object) {
209
+																return $object->getId();
210
+												},
211
+												'groups' => 'main'
212
+								]);
213
+				}
214 214
 }
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -84,7 +84,7 @@  discard block
 block discarded – undo
84 84
             "userAgent" => $this->request->server->get("HTTP_USER_AGENT"),
85 85
             "ip" => $this->request->server->get("REMOTE_ADDR")
86 86
         ];
87
-        if (preg_match('/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows (ce|phone)|xda|xiino/i',$this->request->server->get("HTTP_USER_AGENT"))||preg_match('/1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i',substr($this->request->server->get("HTTP_USER_AGENT"),0,4))) {
87
+        if (preg_match('/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows (ce|phone)|xda|xiino/i', $this->request->server->get("HTTP_USER_AGENT")) || preg_match('/1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i', substr($this->request->server->get("HTTP_USER_AGENT"), 0, 4))) {
88 88
             $account_token_search = [
89 89
                 "token" => $token,
90 90
                 "userAgent" => $this->request->server->get("HTTP_USER_AGENT"),
@@ -153,7 +153,7 @@  discard block
 block discarded – undo
153 153
     {
154 154
         $token = $this->generateToken();
155 155
         $now = new \DateTime();
156
-        $end_token = $now->add(new \DateInterval("PT".$this->container->getParameter("ribs_admin.api_token_duration")."M"));
156
+        $end_token = $now->add(new \DateInterval("PT" . $this->container->getParameter("ribs_admin.api_token_duration") . "M"));
157 157
 
158 158
         if (!$account_token) {
159 159
             $account_token = new AccountToken();
@@ -183,7 +183,7 @@  discard block
 block discarded – undo
183 183
     {
184 184
         $string = "abcdefghijklmnopqrstuvwxyzABCDEFGHJKMNPQRSTUVWXYZ23456789";
185 185
         $token = "";
186
-        srand((double)microtime() * 1000000);
186
+        srand((double) microtime() * 1000000);
187 187
         for ($i = 0; $i < $length; $i++) {
188 188
             $token .= $string[rand() % strlen($string)];
189 189
         }
@@ -205,7 +205,7 @@  discard block
 block discarded – undo
205 205
         $serializer = new Serializer([new DateTimeNormalizer(), new ObjectNormalizer($classMetadataFactory)], [new XmlEncoder(), new JsonEncoder()]);
206 206
 
207 207
         return $serializer->normalize($object, $type, [
208
-            'circular_reference_handler' => function ($object) {
208
+            'circular_reference_handler' => function($object) {
209 209
                 return $object->getId();
210 210
             },
211 211
             'groups' => 'main'
Please login to merge, or discard this patch.
Service/Globals.php 2 patches
Indentation   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -11,11 +11,11 @@  discard block
 block discarded – undo
11 11
 	 */
12 12
 	private $container;
13 13
 
14
-    /**
15
-     * Globals constructor.
16
-     * @param ContainerInterface $container
17
-     */
18
-    public function __construct(ContainerInterface $container)
14
+				/**
15
+				 * Globals constructor.
16
+				 * @param ContainerInterface $container
17
+				 */
18
+				public function __construct(ContainerInterface $container)
19 19
 	{
20 20
 		$this->container = $container;
21 21
 	}
@@ -38,23 +38,23 @@  discard block
 block discarded – undo
38 38
 		return $package_name;
39 39
 	}
40 40
 
41
-    /**
42
-     * this method send base bundle path related to ribs-admin
43
-     * @param string|null $package
44
-     * @param bool $dev_mode
45
-     * @return string
46
-     */
41
+				/**
42
+				 * this method send base bundle path related to ribs-admin
43
+				 * @param string|null $package
44
+				 * @param bool $dev_mode
45
+				 * @return string
46
+				 */
47 47
 	public function getBaseBundlePath(string $package = "piou-piou/ribs-admin-bundle", bool $dev_mode = false): string
48 48
 	{
49 49
 		$path = $this->container->get('kernel')->getProjectDir();
50 50
 
51
-        $dev_mode = $package === "piou-piou/ribs-admin-bundle" ? $this->container->getParameter("ribs_admin.dev_mode"): $dev_mode;
51
+								$dev_mode = $package === "piou-piou/ribs-admin-bundle" ? $this->container->getParameter("ribs_admin.dev_mode"): $dev_mode;
52 52
 
53 53
 		if ($dev_mode === true) {
54 54
 			$package = "/lib/".$this->getPackageDevName($package);
55 55
 		} else {
56
-            $package = "/vendor/" . $package;
57
-        }
56
+												$package = "/vendor/" . $package;
57
+								}
58 58
 		
59 59
 		return $path . $package;
60 60
 	}
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -48,10 +48,10 @@
 block discarded – undo
48 48
 	{
49 49
 		$path = $this->container->get('kernel')->getProjectDir();
50 50
 
51
-        $dev_mode = $package === "piou-piou/ribs-admin-bundle" ? $this->container->getParameter("ribs_admin.dev_mode"): $dev_mode;
51
+        $dev_mode = $package === "piou-piou/ribs-admin-bundle" ? $this->container->getParameter("ribs_admin.dev_mode") : $dev_mode;
52 52
 
53 53
 		if ($dev_mode === true) {
54
-			$package = "/lib/".$this->getPackageDevName($package);
54
+			$package = "/lib/" . $this->getPackageDevName($package);
55 55
 		} else {
56 56
             $package = "/vendor/" . $package;
57 57
         }
Please login to merge, or discard this patch.
Entity/UserLogs.php 1 patch
Indentation   +202 added lines, -202 removed lines patch added patch discarded remove patch
@@ -13,207 +13,207 @@
 block discarded – undo
13 13
  */
14 14
 class UserLogs
15 15
 {
16
-    use GuidTrait;
17
-    use CreatedUpdatedTrait;
18
-
19
-    /**
20
-     * @var integer
21
-     *
22
-     * @ORM\Column(name="id", type="integer", nullable=false)
23
-     * @ORM\Id
24
-     * @ORM\GeneratedValue(strategy="IDENTITY")
25
-     */
26
-    private $id;
27
-
28
-    /**
29
-     * @ORM\ManyToOne(targetEntity="PiouPiou\RibsAdminBundle\Entity\User")
30
-     * @ORM\JoinColumn(name="user_id", referencedColumnName="id", nullable=false)
31
-     */
32
-    private $user;
33
-
34
-    /**
35
-     * @var string
36
-     *
37
-     * @ORM\Column(name="method", type="string", length=255, nullable=false)
38
-     */
39
-    private $method;
40
-
41
-    /**
42
-     * @var string
43
-     *
44
-     * @ORM\Column(name="route", type="string", length=255, nullable=false)
45
-     */
46
-    private $route;
47
-
48
-    /**
49
-     * @var string
50
-     *
51
-     * @ORM\Column(name="url", type="string", length=255, nullable=false)
52
-     */
53
-    private $url;
54
-
55
-    /**
56
-     * @var string
57
-     *
58
-     * @ORM\Column(name="full_url", type="string", length=255, nullable=false)
59
-     */
60
-    private $full_url;
61
-
62
-    /**
63
-     * @var string
64
-     *
65
-     * @ORM\Column(name="request_format", type="string", length=255, nullable=false)
66
-     */
67
-    private $request_format;
68
-
69
-    /**
70
-     * @var string
71
-     *
72
-     * @ORM\Column(name="equest_parameters", type="json", nullable=true)
73
-     */
74
-    private $request_parameters;
75
-
76
-    /**
77
-     * @return int
78
-     */
79
-    public function getId()
80
-    {
81
-        return $this->id;
82
-    }
83
-
84
-    /**
85
-     * @param int $id
86
-     */
87
-    public function setId($id)
88
-    {
89
-        $this->id = $id;
90
-    }
91
-
92
-    /**
93
-     * @return User
94
-     */
95
-    public function getUser(): User
96
-    {
97
-        return $this->user;
98
-    }
99
-
100
-    /**
101
-     * @param \User $user
102
-     */
103
-    public function setUser($user)
104
-    {
105
-        $this->user = $user;
106
-    }
107
-
108
-    /**
109
-     * @return string
110
-     */
111
-    public function getMethod(): string
112
-    {
113
-        return $this->method;
114
-    }
115
-
116
-    /**
117
-     * @param string $method
118
-     * @return UserLogs
119
-     */
120
-    public function setMethod(string $method): UserLogs
121
-    {
122
-        $this->method = $method;
123
-
124
-        return $this;
125
-    }
126
-
127
-    /**
128
-     * @return string
129
-     */
130
-    public function getRoute(): string
131
-    {
132
-        return $this->route;
133
-    }
134
-
135
-    /**
136
-     * @param string $route
137
-     * @return UserLogs
138
-     */
139
-    public function setRoute(string $route): UserLogs
140
-    {
141
-        $this->route = $route;
142
-
143
-        return $this;
144
-    }
145
-
146
-    /**
147
-     * @return string
148
-     */
149
-    public function getUrl(): string
150
-    {
151
-        return $this->url;
152
-    }
153
-
154
-    /**
155
-     * @param string $url
156
-     * @return UserLogs
157
-     */
158
-    public function setUrl(string $url): UserLogs
159
-    {
160
-        $this->url = $url;
161
-
162
-        return $this;
163
-    }
164
-
165
-    /**
166
-     * @return string
167
-     */
168
-    public function getFullUrl(): string
169
-    {
170
-        return $this->full_url;
171
-    }
172
-
173
-    /**
174
-     * @param string $full_url
175
-     * @return UserLogs
176
-     */
177
-    public function setFullUrl(string $full_url): UserLogs
178
-    {
179
-        $this->full_url = $full_url;
180
-
181
-        return $this;
182
-    }
183
-
184
-    /**
185
-     * @return string
186
-     */
187
-    public function getRequestFormat(): string
188
-    {
189
-        return $this->request_format;
190
-    }
191
-
192
-    /**
193
-     * @param string $request_format
194
-     * @return UserLogs
195
-     */
196
-    public function setRequestFormat(string $request_format): UserLogs
197
-    {
198
-        $this->request_format = $request_format;
199
-
200
-        return $this;
201
-    }
202
-
203
-    public function getRequestParameters()
204
-    {
205
-        return $this->request_parameters;
206
-    }
207
-
208
-    /**
209
-     * @param $request_parameters
210
-     * @return UserLogs
211
-     */
212
-    public function setRequestParameters($request_parameters): UserLogs
213
-    {
214
-        $this->request_parameters = $request_parameters;
215
-
216
-        return $this;
217
-    }
16
+				use GuidTrait;
17
+				use CreatedUpdatedTrait;
18
+
19
+				/**
20
+				 * @var integer
21
+				 *
22
+				 * @ORM\Column(name="id", type="integer", nullable=false)
23
+				 * @ORM\Id
24
+				 * @ORM\GeneratedValue(strategy="IDENTITY")
25
+				 */
26
+				private $id;
27
+
28
+				/**
29
+				 * @ORM\ManyToOne(targetEntity="PiouPiou\RibsAdminBundle\Entity\User")
30
+				 * @ORM\JoinColumn(name="user_id", referencedColumnName="id", nullable=false)
31
+				 */
32
+				private $user;
33
+
34
+				/**
35
+				 * @var string
36
+				 *
37
+				 * @ORM\Column(name="method", type="string", length=255, nullable=false)
38
+				 */
39
+				private $method;
40
+
41
+				/**
42
+				 * @var string
43
+				 *
44
+				 * @ORM\Column(name="route", type="string", length=255, nullable=false)
45
+				 */
46
+				private $route;
47
+
48
+				/**
49
+				 * @var string
50
+				 *
51
+				 * @ORM\Column(name="url", type="string", length=255, nullable=false)
52
+				 */
53
+				private $url;
54
+
55
+				/**
56
+				 * @var string
57
+				 *
58
+				 * @ORM\Column(name="full_url", type="string", length=255, nullable=false)
59
+				 */
60
+				private $full_url;
61
+
62
+				/**
63
+				 * @var string
64
+				 *
65
+				 * @ORM\Column(name="request_format", type="string", length=255, nullable=false)
66
+				 */
67
+				private $request_format;
68
+
69
+				/**
70
+				 * @var string
71
+				 *
72
+				 * @ORM\Column(name="equest_parameters", type="json", nullable=true)
73
+				 */
74
+				private $request_parameters;
75
+
76
+				/**
77
+				 * @return int
78
+				 */
79
+				public function getId()
80
+				{
81
+								return $this->id;
82
+				}
83
+
84
+				/**
85
+				 * @param int $id
86
+				 */
87
+				public function setId($id)
88
+				{
89
+								$this->id = $id;
90
+				}
91
+
92
+				/**
93
+				 * @return User
94
+				 */
95
+				public function getUser(): User
96
+				{
97
+								return $this->user;
98
+				}
99
+
100
+				/**
101
+				 * @param \User $user
102
+				 */
103
+				public function setUser($user)
104
+				{
105
+								$this->user = $user;
106
+				}
107
+
108
+				/**
109
+				 * @return string
110
+				 */
111
+				public function getMethod(): string
112
+				{
113
+								return $this->method;
114
+				}
115
+
116
+				/**
117
+				 * @param string $method
118
+				 * @return UserLogs
119
+				 */
120
+				public function setMethod(string $method): UserLogs
121
+				{
122
+								$this->method = $method;
123
+
124
+								return $this;
125
+				}
126
+
127
+				/**
128
+				 * @return string
129
+				 */
130
+				public function getRoute(): string
131
+				{
132
+								return $this->route;
133
+				}
134
+
135
+				/**
136
+				 * @param string $route
137
+				 * @return UserLogs
138
+				 */
139
+				public function setRoute(string $route): UserLogs
140
+				{
141
+								$this->route = $route;
142
+
143
+								return $this;
144
+				}
145
+
146
+				/**
147
+				 * @return string
148
+				 */
149
+				public function getUrl(): string
150
+				{
151
+								return $this->url;
152
+				}
153
+
154
+				/**
155
+				 * @param string $url
156
+				 * @return UserLogs
157
+				 */
158
+				public function setUrl(string $url): UserLogs
159
+				{
160
+								$this->url = $url;
161
+
162
+								return $this;
163
+				}
164
+
165
+				/**
166
+				 * @return string
167
+				 */
168
+				public function getFullUrl(): string
169
+				{
170
+								return $this->full_url;
171
+				}
172
+
173
+				/**
174
+				 * @param string $full_url
175
+				 * @return UserLogs
176
+				 */
177
+				public function setFullUrl(string $full_url): UserLogs
178
+				{
179
+								$this->full_url = $full_url;
180
+
181
+								return $this;
182
+				}
183
+
184
+				/**
185
+				 * @return string
186
+				 */
187
+				public function getRequestFormat(): string
188
+				{
189
+								return $this->request_format;
190
+				}
191
+
192
+				/**
193
+				 * @param string $request_format
194
+				 * @return UserLogs
195
+				 */
196
+				public function setRequestFormat(string $request_format): UserLogs
197
+				{
198
+								$this->request_format = $request_format;
199
+
200
+								return $this;
201
+				}
202
+
203
+				public function getRequestParameters()
204
+				{
205
+								return $this->request_parameters;
206
+				}
207
+
208
+				/**
209
+				 * @param $request_parameters
210
+				 * @return UserLogs
211
+				 */
212
+				public function setRequestParameters($request_parameters): UserLogs
213
+				{
214
+								$this->request_parameters = $request_parameters;
215
+
216
+								return $this;
217
+				}
218 218
 }
219 219
 
Please login to merge, or discard this patch.
Controller/UserLogsController.php 1 patch
Indentation   +36 added lines, -36 removed lines patch added patch discarded remove patch
@@ -10,44 +10,44 @@
 block discarded – undo
10 10
 
11 11
 class UserLogsController extends AbstractController
12 12
 {
13
-    /**
14
-     * list all user logs
15
-     * @Route("/user-logs/{page}", requirements={"page" = "\d+"}, name="ribsadmin_userlogs")
16
-     * @param ParameterBagInterface $parameterBag
17
-     * @param int $page
18
-     * @return Response
19
-     */
20
-    public function list(ParameterBagInterface $parameterBag, int $page = 1): Response
21
-    {
22
-        $em = $this->getDoctrine()->getManager();
23
-        $max_per_page = $parameterBag->get("ribs_admin.paginator_element_per_page");
13
+				/**
14
+				 * list all user logs
15
+				 * @Route("/user-logs/{page}", requirements={"page" = "\d+"}, name="ribsadmin_userlogs")
16
+				 * @param ParameterBagInterface $parameterBag
17
+				 * @param int $page
18
+				 * @return Response
19
+				 */
20
+				public function list(ParameterBagInterface $parameterBag, int $page = 1): Response
21
+				{
22
+								$em = $this->getDoctrine()->getManager();
23
+								$max_per_page = $parameterBag->get("ribs_admin.paginator_element_per_page");
24 24
 
25
-        $logs = $em->getRepository(UserLogs::class)->findAllPaginated($page, $max_per_page);
26
-        $pagination = array(
27
-            "page" => $page,
28
-            "page_number" => ceil(count($logs) / 20),
29
-            "route" => "ribsadmin_userlogs",
30
-            "parameters" => array()
31
-        );
25
+								$logs = $em->getRepository(UserLogs::class)->findAllPaginated($page, $max_per_page);
26
+								$pagination = array(
27
+												"page" => $page,
28
+												"page_number" => ceil(count($logs) / 20),
29
+												"route" => "ribsadmin_userlogs",
30
+												"parameters" => array()
31
+								);
32 32
 
33
-        return $this->render("@RibsAdmin/userlogs/list.html.twig", [
34
-            "logs" => $logs,
35
-            "pagination" => $pagination
36
-        ]);
37
-    }
33
+								return $this->render("@RibsAdmin/userlogs/list.html.twig", [
34
+												"logs" => $logs,
35
+												"pagination" => $pagination
36
+								]);
37
+				}
38 38
 
39
-    /**
40
-     * show detail of a user log
41
-     * @Route("/user-logs/show/{guid}", name="ribsadmin_userlogs_show")
42
-     * @param string $guid
43
-     * @return Response
44
-     */
45
-    public function show(string $guid): Response
46
-    {
47
-        $log = $this->getDoctrine()->getRepository(UserLogs::class)->findOneByGuid($guid);
39
+				/**
40
+				 * show detail of a user log
41
+				 * @Route("/user-logs/show/{guid}", name="ribsadmin_userlogs_show")
42
+				 * @param string $guid
43
+				 * @return Response
44
+				 */
45
+				public function show(string $guid): Response
46
+				{
47
+								$log = $this->getDoctrine()->getRepository(UserLogs::class)->findOneByGuid($guid);
48 48
 
49
-        return $this->render("@RibsAdmin/userlogs/show.html.twig", [
50
-            "log" => $log,
51
-        ]);
52
-    }
49
+								return $this->render("@RibsAdmin/userlogs/show.html.twig", [
50
+												"log" => $log,
51
+								]);
52
+				}
53 53
 }
Please login to merge, or discard this patch.