// asp code Generated by Basic Processor
// Original Page Name: C:\gmTestBed\FMStocks\src\FMSWeb\ASP\default.asp

namespace FMSWeb
{
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using VBNET=Microsoft.VisualBasic;
using gmRTL.Core;

public partial class _default : System.Web.UI.Page
{
   public FMSWeb._t_head _t_head1 = null;

   protected void Page_Load(object sender, EventArgs e)
   {
      _t_head1 = new FMSWeb._t_head();
   }
   public string msg = "";
   public string email = "";
   public string password = "";
   public void ProcessLogin()
   {
      //  By default, show the page with the default login test account "ta" and password "ta1"
      //  Otherwise, show what the user most recently typed in.
      email = HttpContext.Current.Request["login"].TrimB();
      password = HttpContext.Current.Request["password"].TrimB();
      if (String.IsNullOrEmpty(email))
      {
         gmRTL.Core.MathHelper.Randomize();
         email = "ta" + ((gmRTL.Core.MathHelper.Rnd() * 1000).ToInt() + 1).ToStr();
      }
      if (String.IsNullOrEmpty(password))
      {
         password = "ta";
      }
      //  Are we trying to log in?
      if (!String.IsNullOrEmpty(HttpContext.Current.Request["LoginButton"]))
      {
         //  We're on this page because the Login button was pressed.
         //  Attempt to login
         gmRTL.Core.ErrorHandling.ResumeNext(() =>
         {
            FMStocks_Bus.Account objAccount = null;
            int AccountID = 0;
            string FullName = "";
            bool bIsValid = false;
            objAccount = new FMStocks_Bus.Account();
            //  Common deployment error: this error handling block catches the common
            //  case where the FMStocks_Bus component isn't registered on the app server.
            if (gmRTL.Core.GlobalException.Instance.Number != 0)
            {
               _t_head1.BuildErrorMessage();
               msg = "<div class=error>" + FMSWeb._strings.CREATE_OBJECT_FAILED + "</div>";
               return;
            }
            bIsValid = objAccount.VerifyLogin(email,password,ref FullName,ref AccountID);
            objAccount = null;
            //  Common database error: if the DSN is incorrect, or the database is down or
            //  not reachable, this is the first place
            if (gmRTL.Core.GlobalException.Instance.Number != 0)
            {
               _t_head1.BuildErrorMessage();
               msg = "<div class=error>" + FMSWeb._strings.DATABASE_ERROR + "<p>" + _t_head1.g_strError + "</div>";
               return;
            }
            if (bIsValid)
            {
               //  Login was successful. Pass back the AccountID in a cookie for later.
               HttpContext.Current.Response.Cookies["Account"].Value = AccountID.ToStr();
               HttpContext.Current.Response.Redirect("home.aspx");
            }
            else
            {
               msg = "<span class=error>" + FMSWeb._strings.LOGIN_PASSWORD_FAILED + "</span><br>";
            }
         });
      }
      //  Setup the default message if we're here because a new account was just created
      if (HttpContext.Current.Request["NewAccount"].ToInt() == 1)
      {
         msg = "<span class=info>" + FMSWeb._strings.LOGIN_NEWACCOUNT_CREATED + "</span><br>";
         password = "";
      }
   }
}
}
