mirror of
https://github.com/Sea-Haven-Industries/shoc-backend.git
synced 2026-10-06 18:12:11 +00:00
Replace hardcoded SMTP credentials with SendGrid service
- Remove inline SMTP method with codevoir.com credentials - Inject existing SendMessage helper that uses SendGrid via config - Clean up unused using directives
This commit is contained in:
parent
0e3cb761c9
commit
486233076c
1 changed files with 5 additions and 37 deletions
|
|
@ -4,13 +4,11 @@ using Microsoft.AspNetCore.Identity;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using Microsoft.IdentityModel.Tokens;
|
using Microsoft.IdentityModel.Tokens;
|
||||||
using System.IdentityModel.Tokens.Jwt;
|
using System.IdentityModel.Tokens.Jwt;
|
||||||
using System.Net.Mail;
|
|
||||||
using System.Net;
|
|
||||||
using System.Security.Claims;
|
using System.Security.Claims;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using Api.SeaHavenIndustries.DTOs;
|
using Api.SeaHavenIndustries.DTOs;
|
||||||
|
using Api.SeaHavenIndustries.Helper;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using System.Diagnostics;
|
|
||||||
|
|
||||||
namespace Api.SeaHavenIndustries.Controllers
|
namespace Api.SeaHavenIndustries.Controllers
|
||||||
{
|
{
|
||||||
|
|
@ -21,12 +19,14 @@ namespace Api.SeaHavenIndustries.Controllers
|
||||||
private readonly UserManager<ApplicationUser> _userManager;
|
private readonly UserManager<ApplicationUser> _userManager;
|
||||||
private readonly IConfiguration _configuration;
|
private readonly IConfiguration _configuration;
|
||||||
private readonly ApplicationDbContext _db;
|
private readonly ApplicationDbContext _db;
|
||||||
|
private readonly SendMessage _sendMessage;
|
||||||
|
|
||||||
public AuthenticationController(UserManager<ApplicationUser> userManager, IConfiguration configuration, ApplicationDbContext db, IWebHostEnvironment webHostEnvironment, IHttpContextAccessor httpContext)
|
public AuthenticationController(UserManager<ApplicationUser> userManager, IConfiguration configuration, ApplicationDbContext db, SendMessage sendMessage)
|
||||||
{
|
{
|
||||||
_userManager = userManager;
|
_userManager = userManager;
|
||||||
_configuration = configuration;
|
_configuration = configuration;
|
||||||
_db = db;
|
_db = db;
|
||||||
|
_sendMessage = sendMessage;
|
||||||
}
|
}
|
||||||
|
|
||||||
[AllowAnonymous]
|
[AllowAnonymous]
|
||||||
|
|
@ -150,7 +150,7 @@ namespace Api.SeaHavenIndustries.Controllers
|
||||||
_db.ForgetPasswordCodes.Add(forgetPasswordCode);
|
_db.ForgetPasswordCodes.Add(forgetPasswordCode);
|
||||||
_db.SaveChanges();
|
_db.SaveChanges();
|
||||||
string body = $"Your Password Reset Code is: " + forgetPasswordCode.Code;
|
string body = $"Your Password Reset Code is: " + forgetPasswordCode.Code;
|
||||||
SendEMail(user.Email, "Forget Password Request.", body);
|
await _sendMessage.SendEMail(user.Email, "Forget Password Request.", body);
|
||||||
return Ok(new Response { Status = "Success ", Message = "Please check your email for code" });
|
return Ok(new Response { Status = "Success ", Message = "Please check your email for code" });
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
@ -211,38 +211,6 @@ namespace Api.SeaHavenIndustries.Controllers
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpGet()]
|
|
||||||
public bool SendEMail(string emailid, string subject, string body)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
MailMessage mail = new MailMessage();
|
|
||||||
mail.From = new MailAddress("infoesquall@codevoir.com"); //IMPORTANT: This must be same as your smtp authentication address.
|
|
||||||
mail.To.Add(emailid);
|
|
||||||
|
|
||||||
//set the content
|
|
||||||
|
|
||||||
mail.Subject = subject;
|
|
||||||
mail.Body = body;
|
|
||||||
mail.IsBodyHtml = true;
|
|
||||||
//send the message
|
|
||||||
SmtpClient smtp = new SmtpClient("mail.codevoir.com");
|
|
||||||
|
|
||||||
//IMPORANT: Your smtp login email MUST be same as your FROM address.
|
|
||||||
NetworkCredential Credentials = new NetworkCredential("infoesquall@codevoir.com", "Abc123!@#");
|
|
||||||
smtp.UseDefaultCredentials = false;
|
|
||||||
smtp.Credentials = Credentials;
|
|
||||||
smtp.Port = 8889; //25 alternative port number is 8889
|
|
||||||
smtp.EnableSsl = false;
|
|
||||||
|
|
||||||
smtp.Send(mail);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
private Random _random = new Random();
|
private Random _random = new Random();
|
||||||
private string GenerateRandomNo()
|
private string GenerateRandomNo()
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue