forked from appsecco/dvcsharp-api
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
ad
committed
May 14, 2018
1 parent
e5cf40f
commit 8cb97d2
Showing
4 changed files
with
64 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using Microsoft.AspNetCore.Mvc; | ||
using System.Security.Cryptography; | ||
using dvcsharp_core_api.Models; | ||
using dvcsharp_core_api.Data; | ||
|
||
namespace dvcsharp_core_api | ||
{ | ||
[Route("api/[controller]")] | ||
public class PasswordResetsController : Controller | ||
{ | ||
private readonly GenericDataContext _context; | ||
|
||
public PasswordResetsController(GenericDataContext context) | ||
{ | ||
_context = context; | ||
} | ||
|
||
[HttpPost] | ||
public IActionResult Post([FromBody] PasswordResetRequest passwordResetRequest) | ||
{ | ||
if(!ModelState.IsValid) | ||
{ | ||
return BadRequest(ModelState); | ||
} | ||
|
||
var exitingUser = _context.Users. | ||
Where(b => b.email == passwordResetRequest.email). | ||
FirstOrDefault(); | ||
|
||
if(exitingUser != null) { | ||
ModelState.AddModelError("email", "Email address does not exist"); | ||
return BadRequest(ModelState); | ||
} | ||
|
||
var md5 = MD5.Create(); | ||
var hash = md5.ComputeHash(System.Text.Encoding.ASCII.GetBytes(passwordResetRequest.email)); | ||
|
||
passwordResetRequest.key = BitConverter.ToString(hash).Replace("-", "").ToLowerInvariant(); | ||
_context.PasswordResetRequests.Add(passwordResetRequest); | ||
_context.SaveChanges(); | ||
|
||
return Ok(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
using System; | ||
using System.ComponentModel.DataAnnotations; | ||
|
||
namespace dvcsharp_core_api.Models | ||
{ | ||
public class PasswordResetRequest | ||
{ | ||
public string key { get; set; } | ||
public string email { get; set; } | ||
public string password { get; set; } | ||
public string passwordConfirmation { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters