using System;
using SteamWare;

public partial class login : System.Web.UI.Page
{
  protected string nextPage
  {
    get
    {
      string pagina = memLayer.ML.StringSessionObj("nextPage");
      if (string.IsNullOrEmpty(pagina))
      {
        // cerco se ho prev / prec page
        if (user_std.pagPrecedente != "")
        {
          pagina = user_std.pagPrecedente;
        }
        else
        {
          pagina = "menu.aspx";
        }
      }
      return pagina;
    }
  }
  public string jumpPage { get; set; }

  protected void Page_Load(object sender, EventArgs e)
  {
    jumpPage = nextPage;
    logger.lg.scriviLog(string.Format("Login iniziato: jumpPage {0}", jumpPage), tipoLog.INFO);
    Mod_login1.modoLogin = SteamWare.loginMode.normale;
    // pulisco dir temp dai file dei cartellini stampati
    reportPrinter.obj.pulisciDir();
  }

  protected override void OnInit(EventArgs e)
  {
    base.OnInit(e);
    Mod_login1.Login_ok += new EventHandler(Mod_login1_Login_ok);
    Mod_login1.Login_Error += new EventHandler(Mod_login1_Login_Error);
  }

  void Mod_login1_Login_Error(object sender, EventArgs e)
  {
    Response.Redirect("./unauthorized.aspx", false);
  }

  void Mod_login1_Login_ok(object sender, EventArgs e)
  {
    logger.lg.scriviLog(string.Format("Login OK: redirect a pag {0}", jumpPage), tipoLog.INFO);
    Response.Redirect(jumpPage, false);
  }
  protected override void OnUnload(EventArgs e)
  {
    base.OnUnload(e);
    Mod_login1.Login_ok -= new EventHandler(Mod_login1_Login_ok);
    Mod_login1.Login_Error -= new EventHandler(Mod_login1_Login_Error);
  }
}
