Imports RGBC_Forecast.SystemFunctions
Imports RGBC_Forecast.ProjectFunctions
Imports RGBC_Forecast.db


Partial Public Class Index
  Inherits System.Web.UI.Page


  Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    FormsAuthentication.SignOut()
    Session.Clear()

    If Not Page.IsPostBack Then
      If Request.QueryString("M") = "1" Then
        lblMessage.Text = "Your Session has expired and you have been logged out."
      End If
    End If

  End Sub

  Protected Sub btnLogin_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnLogin.Click
    Dim s As String

      s = db.CleanString(Request.LogonUserIdentity.Name.ToUpper())
      lblMessage.Text = s & "<br>"

      'Try
      '   dr = RGBC_Forecast.db.getRow(sql_get_Users(s, "Forecast"))

      '   If dr Is Nothing Then
      '      lblMessage.Text &= "fuck! its nothing again ..... WHYYYYY????"
      '   End If
      'Catch ex As Exception
      '   lblMessage.Text &= "<i>An error has occured, please contact the system administrator.</i><BR>" & ex.Message & ex.StackTrace
      'End Try

      Try
         If LogginUser(Request, Session) Then
            Response.Redirect("Home.aspx", False)
         Else
            lblMessage.Text &= "<i>Insufficient Access.</i><BR>Login is controlled through the Active Directory.<BR>Please contact the system administrator if you require access."
            FormsAuthentication.SignOut()
            Session.Item("USER") = Nothing
         End If
      Catch ex As Exception
         lblMessage.Text &= "<i>An error has occurred, please contact the system administrator.</i><BR>" & System.Web.HttpUtility.HtmlEncode(ex.Message)

         FormsAuthentication.SignOut()
         Session.Item("USER") = Nothing
      Finally

      End Try

   End Sub

End Class
