def ifAuthenticatedAddEntry(self, user_id, raw_password): # Distinction between User and SensorNode. ? (/signup produces a username.) # Sensor_ID is now 6digit string (was 4 digit numeric) (migration ok) print user_id try: user = User.objects.get(username=user_id) print "CHECKING USER " + user_id + ". IF PW " + raw_password + " is valid.." if user.check_password(raw_password): print "We were able to authenticate you." print "need to initialize a SensorNode with id as yours" sensor_node = SensorNode.objects.get(sensor_id=user_id) if not sensor_node: print "not found. creating" sensor_node = SensorNode(sensor_id=user_id) sensor_node.save() return True else: raise Exception('User not known.') except SensorNode.DoesNotExist: print "fail" except Exception as failure: print "wrong PW" + str(failure) return False
def signup(request): """The idea is that this will return a new nodeid & key.""" s = securelayer() # The master controller will create a new, unique name for connecting nodes. # If, and only if, the nodes have not connected before. # The client node is responsible for *saving* the received node_id # to persistent memory!!! # -> resource directory name = s.pswGenerator(6) # check if the newly, randomly generated name is UNIQUE! regenerate, if not. [user, password] = s.createNewUser(name) response_data = {} response_data['username'] = name response_data['password'] = password # Also, create a sensorNode with username! sensor_node = SensorNode(sensor_id=name) sensor_node.save() # I should test the new user (by running user.check_password) # to see if valid (guessing it always is...) print "INFO for check:" + name + "," + password u = User.objects.get(username=name) return JsonResponse(response_data)