using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Configuration;
using System.IO;
using System.Web.Mail;

namespace VoServices.Footprint.Web
{
	/// <summary>
	/// Summary description for _default.
	/// </summary>
	public partial class forgotpass : BasePageTemplated
	{
	
		protected void Page_Load(object sender, System.EventArgs e)
		{
			TitleLabel.Text = "Password reminder";
		}

		#region Web Form Designer generated code
		override protected void OnInit(EventArgs e)
		{
			//
			// CODEGEN: This call is required by the ASP.NET Web Form Designer.
			//
			InitializeComponent();
			base.OnInit(e);
		}
		
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{    

		}
		#endregion

		protected void Ok_Click(object sender, System.EventArgs e)
		{

			User usr = new User(DatabaseConnection);
			usr.Load(UserId.Text);
			
			if (usr.Guid != "")
			{
				// sending mail

				string body = "";
				StreamReader tmpfile = new StreamReader(Server.MapPath("../templates/passwd.txt"));
				body = tmpfile.ReadToEnd();
				tmpfile.Close();

				body = body.Replace("[$Passwd]", usr.Password);
				body = body.Replace("[$Date]", DateTime.Now.ToString());

				SmtpMail.SmtpServer = ConfigurationSettings.AppSettings["ErrorReportSmtp"];

				SmtpMail.Send("webmaster@voservices.net",
					usr.Email,
					"Your Spectrum Service Password",
					body);

				ResultLabel.Text = "The password has been sent to your e-mail address.";
				ResultLabel.Visible = true;
			}
			else
			{
				ResultLabel.Text = "Username not found.";
				ResultLabel.Visible = true;
			}

		}
	}
}
