Exemple #1
0
 public void EmailService(forgetclass link)
 {
     try
     {
         string HtmlBody;
         using (StreamReader streamReader = new StreamReader(config["IssuerEmailDetail:HtmlBodyFile"], Encoding.UTF8))
         {
             HtmlBody = streamReader.ReadToEnd();
         }
         HtmlBody = HtmlBody.Replace("JwtToken", link.JwtToken);
         MailMessage message = new MailMessage();
         SmtpClient  smtp    = new SmtpClient();
         message.From = new MailAddress(config["IssuerEmailDetail:Email"]);
         message.To.Add(new MailAddress(link.Email));
         message.Subject            = "Reset Password";
         message.IsBodyHtml         = true;
         message.Body               = HtmlBody;
         smtp.Port                  = 587;
         smtp.Host                  = "smtp.gmail.com";
         smtp.EnableSsl             = true;
         smtp.UseDefaultCredentials = false;
         smtp.Credentials           = new NetworkCredential(config["IssuerEmailDetail:Email"], config["IssuerEmailDetail:Password"]);
         smtp.DeliveryMethod        = SmtpDeliveryMethod.Network;
         smtp.Send(message);
     }
     catch (Exception e)
     {
         throw e;
     }
 }
Exemple #2
0
        public forgetclass ForgetPassword(ForgetPasswordModel forgetPasswordModel)
        {
            ForgetModel forget = new ForgetModel();
            UserAccount login  = new UserAccount();

            login.Email = forgetPasswordModel.Email;
            UserAccount validateEmail = userContext.Accounts
                                        .Where(e => e.Email.Equals(login.Email)).FirstOrDefault(e => e.Email == login.Email);
            var jwt = GenerateToken(validateEmail);

            forget.JwtToken = jwt;


            if (validateEmail != null)
            {
                var model1 = new ForgetPasswordModel {
                    Email = forgetPasswordModel.Email
                };
                var model2 = new ForgetModel {
                    JwtToken = forget.JwtToken
                };
                var model = new forgetclass {
                    Email = model1.Email, JwtToken = model2.JwtToken
                };
                return(model);
            }
            else
            {
                throw new UserAccountException(UserAccountException.ExceptionType.EMAIL_DONT_EXIST, "email address is not registered");
            }
        }
Exemple #3
0
        public ActionResult ForgetPassword(ForgetPasswordModel forgetPasswordModel)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    forgetclass result = userBL.ForgetPassword(forgetPasswordModel);                   //getting the data from BusinessLayer
                    var         msmq   = new MSMQ(Configuration);
                    msmq.MSMQSender(result);
                    if (result != null)
                    {
                        return(this.Ok(new { Success = true, Message = "Your password has been forget sucessfully now you can reset your password" }));   //(smd format)    //this.Ok returns the data in json format
                    }

                    else
                    {
                        return(this.Ok(new { Success = true, Message = "Other User is trying to login from your account" }));   //(smd format)    //this.Ok returns the data in json format
                    }
                }
                else
                {
                    return(null);
                }
            }
            catch (Exception ex)
            {
                return(BadRequest(new { Success = false, ex.Message }));
            }
        }
Exemple #4
0
        /// <summary>
        /// Handles the ReceiveCompleted event of the Queue control.
        /// sends email when message received from queue
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public void MSMQReceiver(object sender, ReceiveCompletedEventArgs e)
        {
            try
            {
                MessageQueue queue = (MessageQueue)sender;
                Message      msg   = queue.EndReceive(e.AsyncResult);
                forgetclass  model = JsonConvert.DeserializeObject <forgetclass>(msg.Body.ToString());

                email.EmailService(model);

                queue.BeginReceive(TimeSpan.FromSeconds(5));
            }
            catch (Exception ex)
            {
            }
        }
Exemple #5
0
 /// <summary>
 /// Sends the password reset link to MSMQ
 /// </summary>
 /// <param name="link"></param>
 public void MSMQSender(forgetclass link)
 {
     try
     {
         if (!MessageQueue.Exists(queue.Path))
         {
             MessageQueue.Create(queue.Path);
         }
         queue.Formatter = new XmlMessageFormatter(new Type[] { typeof(string) });
         Message msg = new Message
         {
             Label = "password reset link",
             Body  = JsonConvert.SerializeObject(link),
         };
         queue.Send(msg);
         queue.ReceiveCompleted += MSMQReceiver;
         queue.BeginReceive(TimeSpan.FromSeconds(5));
         queue.Close();
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }