Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make Username and Email Case-Insensitive #586

Merged
merged 13 commits into from
Aug 21, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion Backend/Controllers/UserController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public UserController(IUserService userService, IPermissionService permissionSer
[HttpPost("forgot")]
public async Task<IActionResult> ResetPasswordRequest([FromBody] PasswordResetData data)
{
var email = data.Email;
var email = data.Email.ToLower();
// create password reset
var resetRequest = await _passwordResetService.CreatePasswordReset(email);

Expand Down Expand Up @@ -116,6 +116,7 @@ public async Task<IActionResult> Authenticate([FromBody] Credentials cred)
{
try
{
cred.Username = cred.Username.ToLower();
var user = await _userService.Authenticate(cred.Username, cred.Password);
if (user == null)
{
Expand Down Expand Up @@ -156,6 +157,8 @@ public async Task<IActionResult> Get(string userId)
[HttpPost]
public async Task<IActionResult> Post([FromBody] User user)
{
user.Username = user.Username.ToLower();
user.Email = user.Email.ToLower();
var returnUser = await _userService.Create(user);
if (returnUser == null)
{
Expand All @@ -172,6 +175,7 @@ public async Task<IActionResult> Post([FromBody] User user)
[HttpPost("checkusername/{username}")]
public async Task<IActionResult> CheckUsername(string username)
{
username = username.ToLower();
var usernameTaken = (await _userService.GetAllUsers()).Find(x => x.Username == username) != null;
if (usernameTaken)
{
Expand All @@ -188,6 +192,7 @@ public async Task<IActionResult> CheckUsername(string username)
[HttpPost("checkemail/{email}")]
public async Task<IActionResult> CheckEmail(string email)
{
email = email.ToLower();
var emailTaken = (await _userService.GetAllUsers()).Find(x => x.Email == email) != null;
if (emailTaken)
{
Expand Down
4 changes: 2 additions & 2 deletions docs/api/users/user.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

**name** :

**email** : Valid email address
**email** : Valid email address - Should always be stored in lowercase

**phone** : Valid phone number

Expand All @@ -16,7 +16,7 @@

**password** :

**username** :
**username** : Should always be stored in lowercase

**uiLang** :

Expand Down