def signup(): ''' Sign up view for new users, redirecting to the RSS list page. ''' if not session.get('logged_in'): form = LoginForm(request.form) if request.method == 'POST': username = request.form['username'].lower() password = hash_password(request.form['password']) email = request.form['email'] if form.validate(): if not is_user_key_take(username): add_user(username, password, email) session['logged_in'] = True session['name'] = username return json.dumps({'status': 'Signup successful'}) return json.dumps({'status': 'Username taken'}) return json.dumps({'status': 'User/Pass required'}) return render_template('index.html', form=form) return redirect(url_for('login'))
def test_password_hashes_are_randon(client): user1 = add_user( username="******", email="*****@*****.**", password="******" ) user2 = add_user( username="******", email="*****@*****.**", password="******" ) assert user1.password_hash != user2.password_hash
def register(): if request.method == 'GET': return render_template('register.html') else: username = request.form['username'] password = request.form['password'] hashed_password = generate_password_hash(password, method='pbkdf2:sha256', salt_length=8) add_user(Username=username, Hash=hashed_password) return f'<h1>Added user {username}<h1>'
def test_just_add_one(client): user = add_user(username="******", email="*****@*****.**") assert user.id is not None assert user.username == "Test" assert user.email == "*****@*****.**" assert user.active is True assert user.password_hash is not None
def signup(): if not session.get('logged_in'): form = LoginForm(request.form) if request.method == 'POST': username = request.form['username'].lower() password = helpers.hash_password(request.form['password']) email = request.form['email'] if form.validate(): if not helpers.username_taken(username): helpers.add_user(username, password, email) session['logged_in'] = True session['username'] = username return json.dumps({'status': 'Signup successful'}) return json.dumps({'status': 'Username taken'}) return json.dumps({'status': 'User/Pass required'}) return render_template('login.html', form=form) return redirect(url_for('login'))
def register(): if not session.get('logged_in'): form = LoginForm(request.form) if request.method == 'POST': username = request.form['username'].lower() password = helpers.hash_password(request.form['password']) email = request.form['email'] c1 = "#360033" c2 = "#0b8793" if form.validate(): if not helpers.username_taken(username): helpers.add_user(username, password, email, c1, c2) session['logged_in'] = True session['username'] = username return json.dumps({'status': 'Register successful'}) return json.dumps({'status': 'Username taken'}) return json.dumps({'status': 'Both fields required'}) return render_template('login.html', form=form) return redirect(url_for('login'))
def projects_add_user(): token_response = helpers.validate_jwt(request) if not token_response["success"]: return jsonify(token_response), 401 """ Add another user to a project """ project_id = request.json.get("project_id") new_id = helpers.user_by_username( request.json.get("username"))['user']['ref'].id() if helpers.add_user(new_id, project_id): return jsonify({"msg": "Successsfully added user to this project"}), 201 return jsonify({"msg": "Could not add user to this project"}), 500
def test_decode_auth_token(client): user = add_user( username="******", email="*****@*****.**", password="******" ) auth_token = user.encode_auth_token() assert User.decode_auth_token(auth_token) == user.id
def test_encode_auth_token(client): user = add_user( username="******", email="*****@*****.**", password="******" ) auth_token = user.encode_auth_token() assert isinstance(auth_token, bytes)
def test_no_duplicate_email(client): with pytest.raises(IntegrityError): add_user(username="******", email="*****@*****.**") add_user(username="******", email="*****@*****.**")
def test_to_json(client): user = add_user(username="******", email="*****@*****.**") assert isinstance(user.to_json(), dict)