public async Task <IActionResult> EmailCheck(string email) { CustomCodes check = await _userService.EmailCheck(email); if (check.statusCode == 401) { return(new ObjectResult(check)); } CustomCodes result = await _tokenService.ForgotPassword(email); EmailTemplate newEmail = new EmailTemplate() { Email = email, Link = "https://localhost:5001/email/" + result.access_token, Switch = "forgotPassword" }; await _mailer.SendEmailAsync(newEmail); var response = new CustomCodes { statusCode = 200 }; return(new ObjectResult(response)); }
public async Task <IActionResult> PostBook([FromBody] Region book) { Console.WriteLine("\n\n\n CONTROLLER \n\n\n"); CustomCodes response = await _bookService.PostBook(book); return(new ObjectResult(response)); }
public async Task <dynamic> GenerateToken(string email) { // FIGURE OUT HOW TO USE THE QUERIED DOCUMENT'S ID IN CLAIMTYPES var filter = Builders <Users> .Filter.Eq("Email", email); Users user = await _users.Find(filter).FirstOrDefaultAsync(); var claims = new List <Claim> { new Claim(ClaimTypes.Name, email), new Claim(ClaimTypes.NameIdentifier, email), new Claim(JwtRegisteredClaimNames.Nbf, new DateTimeOffset(DateTime.Now).ToUnixTimeSeconds().ToString()), new Claim(JwtRegisteredClaimNames.Exp, new DateTimeOffset(DateTime.Now.AddDays(1)).ToUnixTimeSeconds().ToString()), }; var token = new JwtSecurityToken( new JwtHeader( new SigningCredentials( new SymmetricSecurityKey(Encoding.UTF8.GetBytes("MyKeyIsSuperSecretButIProbablyWillStillUploadThisToGithubBecauseImStupid")), SecurityAlgorithms.HmacSha256)), new JwtPayload(claims)); var output = new CustomCodes { access_token = new JwtSecurityTokenHandler().WriteToken(token), statusCode = 200, user = user }; return(output); }
public async Task <IActionResult> Validate([FromBody] CustomCodes code) { var result = await _tokenService.ValidateToken(code.access_token); if (result.statusCode == 200) { return(new ObjectResult(result)); } else { return(new ObjectResult(new CustomCodes { statusCode = 401 })); } }
public async Task <IActionResult> UpdateEmail([FromBody] Users user) { if (await _userService.UpdateEmail(user)) { CustomCodes result = await _tokenService.GenerateToken(user.Email); return(new ObjectResult(result)); } else { return(new ObjectResult(new CustomCodes { statusCode = 500 })); } }
public async Task <IActionResult> BookRequest([FromBody] EmailTemplate email) { CustomCodes result = await _userService.checkRequests(email.Email, email.Book.Id); if (result.statusCode != 200) { return(new ObjectResult(result)); } await _mailer.SendEmailAsync(email); CustomCodes response = new CustomCodes { statusCode = 200 }; return(new ObjectResult(response)); }
public async Task <IActionResult> ForgotPassword([FromBody] string email) { var result = await _tokenService.ForgotPassword(email); EmailTemplate newEmail = new EmailTemplate() { Email = email, Link = "https://localhost:5001/email/" + result.access_token, Switch = "forgotPassword" }; await _mailer.SendEmailAsync(newEmail); var response = new CustomCodes { statusCode = 200 }; return(new ObjectResult(response)); }
public async Task <IActionResult> Get(string id) { CustomCodes result = await _bookService.GetBooks(id); return(new ObjectResult(result)); }