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
def run(): print("Creating new users") mark = User(_id='Mark', name='Mark') mark.password = '******' mark.phone = "8139577566" mark.is_android = True mark.update_position(38.997144, -77.12401) # DC mark.role = User.Role.tower.value adam = User(_id='Adam', name='Adam') adam.password = '******' adam.phone = "3475563921" adam.is_android = True adam.role = User.Role.tower.value adam.update_position(40.727328, -73.9876522) # NYC brent = User(_id='Brent', name='Brent') brent.password = '******' brent.phone = "5613061883" brent.is_android = True brent.role = User.Role.tower.value brent.update_position(30.4670643, -84.3972845) # Tallahasse # rayna = User(_id='rayna', name='rayna') # rayna.password = '******' # rayna.phone = "5613061883" # rayna.is_android = True # rayna.role = User.Role.tower.value # rayna.update_position(28.359309, -82.66591) # Tampa db.session.merge(adam) db.session.merge(mark) db.session.merge(brent) # db.session.merge(rayna) db.session.commit() print("Successfully created users :)")
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