예제 #1
0
def create_test_user(user_dict):
    u = User(_id=user_dict['id'], name=user_dict['phone'], _is_test_user=True)
    u.password = TEST_USER_PASSWORD
    u.role = User.Role.tower.value
    u.active = True
    for k in user_dict.keys():
        setattr(u, k, user_dict[k])
    u.update_position(user_dict['last_lat_seen'], user_dict['last_long_seen'])
    logger.debug("created test user: {}".format(User.query.get(u.id)))
    return u
예제 #2
0
    def post(self):
        """
        DEPRECATED: Use /login to create a new user

        .. :quickref: User; Deprecated.

        :resheader Content-Type: application/json
        :<json string phone: 10 digit phone number
        :<json string email: User's email
        :<json string name: User's name
        :<json string name: User's password
        :<json float one_signal_player_id: user's one_signal_player_id

        :>json string: status
        :>json user_id: status

        :status 200: success
        :status 400: invalid params
        :status 401: authorization failed
        """

        # DEPRECATED
        logger.warning("Makin a new tower")
        args = request.get_json()

        if not g.user.is_admin:
            return {'status': 'Cant create a user - youre not an admin'}, 401

        # You must provide these args
        required_args = ['lat', 'lon', 'name', 'phone']
        for arg in required_args:
            if arg not in args:
                logger.info("Missed required value '{}'".format(arg))
                return bad_request("Missed required value '{}'".format(arg))

        user = User(_id=args['name'], name=args['name'], _is_test_user=False)
        user.is_android = True
        user.active = True
        user.phone = args['phone']
        user.role = User.Role.tower.value
        user.update_position(args['lat'], args['lon'])
        db.session.merge(user)
        db.session.commit()

        return {'status': 'New user created', 'user_id': str(user.id)}, 201