def users(): user_fixture_file = open('fixtures.yaml', 'rt') users = yaml.load(user_fixture_file.read())['users'] for user in users: app.logger.info('Created user: %s', user['username']) register_user(user['username'], user['email'], user['password'], admin=user['admin'], teams=user['teams'], confirmed=True, create_teams=True)
def post(self): args = registerPostParser.parse_args() user_id = args.get('user_id') username = args.get('username') name = args.get('name') email = args.get('email') password = args.get('password') os = args.get('os') browser = args.get('browser') remember = args.get('rememberMe', True) site_url = args.get('site_url', current_app.config['SITE_URL']) registration_result, valid_registration = validate_registration(username, email) if valid_registration: confirmed = (False if current_app.config['MAIL_AUTHENTICATION'] else True) user = register_user( username, email, password, user_id=user_id, confirmed=confirmed, anonymous=False ) login_user(user, remember=remember) parsed_user = row_to_dict(user) if current_app.config['MAIL_AUTHENTICATION']: site_url = '%s://%s' % (current_app.config['PREFERRED_URL_SCHEME'], site_url) token = generate_confirmation_token(email) confirm_url = '%s/auth/activate/%s' % (site_url, token) html = render_template('confirm_email.html', username=username, confirm_url=confirm_url, site_url=site_url, support_url='mailto:[email protected]', os=os, browser=browser ) send_email(email, 'Activate Your DIVE Account', html) message = 'A confirmation e-mail has been sent to %s' % email else: message = 'Successfully registered' response = jsonify({ 'status': 'success', 'message': message, 'user': { k: parsed_user[k] for k in ['anonymous', 'confirmed', 'email', 'id', 'username']} }) response = set_cookies(response, { 'username': user.username, 'email': user.email, 'user_id': user.id, 'confirmed': user.confirmed, 'anonymous': user.anonymous }, expires=datetime.utcnow() + COOKIE_DURATION) return response else: return jsonify({ 'status': 'error', 'message': registration_result }, status=401)