def create_init_user(): """Create initial admin user for authentication purposes.""" data = { 'username': "******", 'password': "******", } user_model.create(data, users_table)
def join(self): loggedInUser = helper.getLoggedInUser() if loggedInUser: return error("You are logged in. You cannot create an account.", AlreadyLoggedInError) theData = json.loads(helper.getRequestBody()) valid, msg, errType = self.isValid(theData) result = None if valid: theData["password"] = md5hash(theData["password"]) del theData["passwordVerify"] theData["gravatar"] = "http://www.gravatar.com/avatar/%s?s=32" % md5hash(theData["email"]) theUser = user.create(theData) helper.setLoggedInUser(theUser) return data(theUser) else: return error(msg, errType)
def test_duplication_error(self): u = UserFactory.create() with expect.error_to_happen(mongoengine.NotUniqueError): user.create({"username": u.username})
def test_create_user_should_work(self): attr = UserFactory.attributes() u = user.create(attr) expect(u.username).to_equal(attr.get('username')) expect(u.email).to_equal(attr.get('email')) expect(u.password).to_equal(md5.new(attr.get('password')).hexdigest())
def handler(event, context): """Handler for the /signup endpoint. ==== POST ==== Sign-up and create a user using HTTP POST. Parameters are given in the JSON object of the http POST call. :param event['username']: User name of the user to create. :param event['password']: Password of the user to create. :param event['settings']: List of settings to add to the user being created. :type event['username']: string :type event['password']: string :type event['settings']: list of dicts :Example: curl -X POST -H 'Content-Type: application/json' -H 'Accept: application/json' -d '{ "username": "******", "password": "******", "settings": [ {"key", "value"} ], }' 'http://<server_addr>/signup' :raises UnableToPerformOperationError: If an invalid http_method is used to call the endpoint handler. """ if 'request' not in event: raise UnableToPerformOperationError http_method = event['request']['http_method'] if http_method == 'POST': event.pop("request", None) user_id = user_model.create(event, users_table) event = { "rocket_data": { "colors": "Silver, Blue", "mfg": "Estes", "motors": [ [ { "diameter": "13" } ] ], "name": "Gnome", "notes": "Recommended Motors: 1/2A3-2T, 1/2A3-4T, A3-4T, A10-3T", "preflight": [ "Insert wadding", "Roll up streamer, insert into body tube and insert nose cone", "Insert motor", "Insert motor starter and secure with plug" ], "recovery": "Streamer", "rod": "1/8\"" } } payload = { 'sub' : user_id } rocket_model.create(event, rockets_table, payload) return {"user_id": user_id} raise UnableToPerformOperationError