-
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.
Added email otp validation at time of register.
- Loading branch information
1 parent
5511e3a
commit 614e14f
Showing
5 changed files
with
84 additions
and
5 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
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 |
---|---|---|
|
@@ -5,6 +5,8 @@ | |
using Microsoft.Extensions.Configuration; | ||
using Microsoft.IdentityModel.Tokens; | ||
using System.IdentityModel.Tokens.Jwt; | ||
using System.Net.Mail; | ||
using System.Net; | ||
using System.Security.Claims; | ||
using System.Text; | ||
|
||
|
@@ -18,6 +20,7 @@ public interface IRegisterService | |
Register GetUserWithId(int id); | ||
dynamic Login(string email, string password, int roleId); | ||
TokenModel RefreshGeneratedToken(TokenModel model, int Id); | ||
int SendEmail(string emailToAddress); | ||
} | ||
public class RegisterService : IRegisterService | ||
{ | ||
|
@@ -88,6 +91,46 @@ private string GenerateString() | |
return random.ToString(); | ||
} | ||
|
||
public int SendEmail(string emailToAddress) | ||
{ string smtpAddress = "smtp.gmail.com"; | ||
int portNumber = 587; | ||
int otp = Convert.ToInt32(GenerateString()); | ||
bool enableSSL = true; | ||
string emailFromAddress = "[email protected]"; //Sender Email Address | ||
string password = "xcka afny abfe mkwn"; //Sender Password | ||
|
||
string subject = "Verify OTP"; | ||
string body = "<div style='font-family: Helvetica,Arial,sans-serif;min-width:1000px;overflow:auto;line-height:2'>" | ||
+ "<div style='margin:50px auto;width:70%;padding:20px 0'>" + | ||
"<div style='border-bottom:1px solid #eee'>" + | ||
"<a href='' style='font-size:1.4em;color: #00466a;text-decoration:none;font-weight:600'>Holy Mary Institute of Technology and Science</a>" + | ||
"</div>" + | ||
"<p style='font-size:1.1em'>Hi,</p>" + | ||
"<p>Thank you for choosing HITS. Use the following OTP to complete your Sign Up procedures. OTP is valid for 5 minutes</p>" + | ||
"<h2 style='background: #00466a;margin: 0 auto;width: max-content;padding: 0 10px;color: #fff;border-radius: 4px;'>" + otp + "</h2>" + | ||
"<p style='font-size:0.9em;'>Regards,<br />HITS</p>" + | ||
"<hr style='border:none;border-top:1px solid #eee' />" + | ||
"<div style='float:right;padding:8px 0;color:#aaa;font-size:0.8em;line-height:1;font-weight:300'>" + | ||
" <p>HITS Inc</p> <p>Keesara, ghatkesar</p> <p>Hyderabad</p> </div></div></div>"; | ||
using (MailMessage mail = new MailMessage()) | ||
{ | ||
mail.From = new MailAddress(emailFromAddress, "Holy Mary"); | ||
mail.To.Add(emailToAddress); | ||
mail.Subject = subject; | ||
mail.Body = body; | ||
mail.IsBodyHtml = true; | ||
//mail.Attachments.Add(new Attachment("D:\\TestFile.txt"));//--Uncomment this to send any attachment | ||
using (SmtpClient smtp = new SmtpClient(smtpAddress, portNumber)) | ||
{ | ||
smtp.Credentials = new NetworkCredential(emailFromAddress, password); | ||
smtp.EnableSsl = enableSSL; | ||
smtp.Send(mail); | ||
} | ||
} | ||
|
||
return otp; | ||
} | ||
|
||
public string GenerateAccesstoken(Register user) | ||
{ | ||
var claims = new[] { new Claim("Id", user.Id.ToString()) }; | ||
|
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
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