Example #1
0
        public int ForgotPassword(ForgotPasswordRequest pForgotPasswordRequest)
        {
            IUserProfileRepository _IUserProfileRepository;
            _IUserProfileRepository = new UserProfileRepository(new WorkersInMotionDB());
            IGlobalUserRepository _IGlobalUserRepository;
            _IGlobalUserRepository = new GlobalUserRepository(new WorkersInMotionDB());
            string UserGUID = _IUserProfileRepository.GetUserIDFromEmail(pForgotPasswordRequest.Cred);
            GlobalUser globalUser = _IGlobalUserRepository.GetPasswordFromUserGUID(new Guid(UserGUID));
            if (globalUser != null)
            {
                EmailManager();
                //string url = AppDomain.CurrentDomain.BaseDirectory;
                //TextReader textreader = new StreamReader(url + "EmailTemplate.html");
                //string content = textreader.ReadToEnd();
                //content = content.Replace("$UserName$", globalUser.UserName);
                //content = content.Replace("$Password$", globalUser.Password);

                StringBuilder sbMailBody = new StringBuilder();
                sbMailBody.Append("<html>");
                sbMailBody.Append("<head></head>");
                sbMailBody.Append("<body>");
                sbMailBody.Append("<table cellspacing=\"2\" cellpadding=\"2\" border=\"0\" width=\"100%\">");
                sbMailBody.Append("<tr>");
                sbMailBody.Append("<td align=\"left\" width=\"300px\">");
                sbMailBody.Append("Dear " + globalUser.UserName + ",");
                sbMailBody.Append("</td>");
                sbMailBody.Append("</tr>");
                sbMailBody.Append("<tr>");
                sbMailBody.Append("<td align=\"left\" width=\"300px\">");
                sbMailBody.Append("</td>");
                sbMailBody.Append("</tr>");
                sbMailBody.Append("<tr>");
                sbMailBody.Append("<td align=\"left\" width=\"300px\">");
                sbMailBody.Append("<b>User Name :</b>" + globalUser.UserName + "");
                sbMailBody.Append("</td>");
                sbMailBody.Append("</tr>");

                sbMailBody.Append("<tr>");
                sbMailBody.Append("<td align=\"left\" width=\"300px\">");
                sbMailBody.Append("<b>Password :</b>" + globalUser.Password + "");
                sbMailBody.Append("</td>");
                sbMailBody.Append("</tr>");
                sbMailBody.Append("<tr>");
                sbMailBody.Append("<tr>");
                sbMailBody.Append("<td align=\"left\" width=\"300px\">");
                sbMailBody.Append("</td>");
                sbMailBody.Append("</tr>");
                sbMailBody.Append("<td align=\"left\" width=\"300px\">");
                sbMailBody.Append("on WorkersInMotion Website");
                sbMailBody.Append("</td>");
                sbMailBody.Append("</tr>");

                sbMailBody.Append("</table>");
                sbMailBody.Append("</body>");

                sbMailBody.Append("</html>");

                sftMail lMail = new sftMail(pForgotPasswordRequest.Cred, m_cSMTPUserName);
                lMail.FromDisplayName = string.Empty;
                lMail.FromAddress = m_cSMTPUserName;
                lMail.ToDisplayName = string.Empty;
                lMail.IsMailBodyHTML = true;
                lMail.MailSubject = "Password Recovery";
                lMail.MailBody = sbMailBody.ToString();
                lMail.SmtpHost = m_cSMTPHost;
                if (!string.IsNullOrEmpty(m_cPortNo))
                {
                    lMail.PortNo = Convert.ToInt32(m_cPortNo);
                }
                else
                {
                    lMail.PortNo = 25;
                }
                if (lMail.SendMail())
                {
                    return 1;
                }
                else
                {
                    return 0;
                }
            }
            else
            {
                return 401;
            }

        }