@@ -139,8 +139,9 @@ def get(self, request):
139139 # If the device MAC is already registered on the network but with a different IP,
140140 # This could happen if the DHCP has changed the IP of the client.
141141
142- # * If the registered device is owned by another user, we delete the old device and we register the new one.
143- if device .user != request .user :
142+ # * If the registered device is owned by another user, and that the device is currently disconnected,
143+ # we delete the old device and we register the new one.
144+ if device .user != request .user and not device .enabled :
144145 if user_devices .count () >= request .user .max_device_nb :
145146 user ["too_many_devices" ] = True
146147
@@ -156,6 +157,11 @@ def get(self, request):
156157
157158 DeviceManager .create_user_device (request .user , client_ip )
158159 # * If the registered device is owned by the requesting user, we change the IP of the registered device.
160+ elif device .user != request .user and device .enabled :
161+ return Response (
162+ {"error" : [_ ("This device is already used by another user" )]},
163+ status = status .HTTP_403_FORBIDDEN
164+ )
159165 else :
160166 device .ip = client_ip
161167 device .save ()
@@ -253,15 +259,15 @@ def post(self, request):
253259 if user is None :
254260 try :
255261 User .objects .get (username = data ["username" ])
256-
262+
257263 # If we get here, it means the user exists but the password is wrong: no need to check the website API
258264 return Response (
259265 {"error" : [_ ("Bad username or password" )]},
260266 status = status .HTTP_403_FORBIDDEN ,
261267 )
262268 except :
263269 pass
264-
270+
265271 # No user found locally, we try to login with the insalan website if we are LAN mode.
266272 if LAN :
267273 username = data ["username" ]
0 commit comments