Skip to content
This repository was archived by the owner on Dec 8, 2022. It is now read-only.

Commit 5807b90

Browse files
authored
Merge pull request #43 from codewizardshq/username-api
API for checking if a username is already taken
2 parents 74a4d14 + 185b526 commit 5807b90

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

CodeChallenge/api/users.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,3 +209,11 @@ def reset_password():
209209
return json_error("password reset failed")
210210

211211
return jsonify(status="success", reason="password reset successfully")
212+
213+
214+
@bp.route("/<string:username>/exists", methods=["GET"])
215+
def username_exists(username):
216+
exists = Users.query.filter_by(username=username).first() is not None
217+
return jsonify(status="success",
218+
exists=exists,
219+
username=username)

tests/test_auth.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,3 +97,16 @@ def test_forgot_password(client, app):
9797
))
9898

9999
assert retval.status_code == 200
100+
101+
102+
def test_user_exists(client):
103+
104+
rv = client.get("/api/v1/users/cwhqsam/exists")
105+
assert rv.status_code == 200
106+
assert rv.json["exists"] is True
107+
assert rv.json["username"] == "cwhqsam"
108+
109+
rv2 = client.get("/api/v1/users/foobar/exists")
110+
assert rv2.status_code == 200
111+
assert rv2.json["username"] == "foobar"
112+
assert rv2.json["exists"] is False

0 commit comments

Comments
 (0)