using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using digioz;

public partial class controls_ForgotLogin : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    protected void btnRecover_Click(object sender, EventArgs e)
    {
        string lsEmail = Utility.ConvertHtmlToPlainText(txtEmail.Text);
        lsEmail = lsEmail.Replace("=", "");
        lsEmail = lsEmail.Replace("--", "");
        lsEmail = lsEmail.Replace("/", "");

        if (UserProfileManagement.DoesEmailExist(lsEmail))
        {
            try
            {
                UserProfile loUserProfile = UserProfileManagement.GetUserProfileByEmail(lsEmail);
                User loUser = UserManagement.GetUserByUsername(loUserProfile.Username);

                ContactInfo loContactInfo = new ContactInfo();
                digioz.Hashtable loConfigTable = new digioz.Hashtable();
                ConfigurationList loConfigurationList = ConfigurationManagement.GetConfigurationList();
                foreach (digioz.Configuration loConfig in loConfigurationList)
                {
                    loConfigTable.AddToTable(loConfig.KeyName, loConfig.KeyValue);
                }

                loContactInfo.SenderEMail = (string)(loConfigTable.GetValue("Contact Email"));
                loContactInfo.ContactEMail = lsEmail;
                loContactInfo.SenderSubject = "Your Login Information";
                loContactInfo.SenderMessage = "Hello,<br>" 
                                            + "Below is your login information you requested:<br><br>" 
                                            + "Username: " + loUserProfile.Username + "<br>"
                                            + "Password: " + loUser.Password +"<br><br>"
                                            + "Thanks" +"<br>"
                                            + "The Support Team";
                loContactInfo.SMTPServer = (string)(loConfigTable.GetValue("SMTP Server"));
                loContactInfo.SMTPUsername = (string)(loConfigTable.GetValue("SMTP Username"));
                loContactInfo.SMTPPassword = (string)(loConfigTable.GetValue("SMTP Password"));
                loContactInfo.Attachment = String.Empty;
               bool lbresponse =Utility.SendMail.SubmitMail(loContactInfo);
               lblMessage.Text = "<font color='green'>Login Information has been emailed to the email address on file.</font>";
            }
            catch
            {
                lblMessage.Text = "<font color='red'>Unable to Email your login information to you. Please contact the webmaster.</font>";
            }
        }
        else
        {
            lblMessage.Text = "<font color='red'>Invalid Email Specified</font>";
        }
    }
}
