/// <summary>
        ///     Virtual method used to attempt a user login. If the user could not be logged in, null will be returned. If the user is logged in, the object will be added to the session with the key "UserInfo". Requires "DatabaseReporting" connection string to be defined in web.config unless it's overridden.
        /// </summary>
        /// <param name="usernameOrEmail">The username or email to check. Which one to pass depends on the useEmailForLogin parameter.</param>
        /// <param name="password">The password to try.</param>
        /// <param name="useEmailForLogin">If true, the usernameOrEmail value will be assumed to be an email.</param>
        /// <param name="clientID">The client ID of the login attempt.</param>
        /// <param name="outputValue">
        ///     <para>The value output from the query. Use this to generate response messages. Values are:</para>
        ///     <para>-1 - Unknown error. Something went wrong with the query.</para>
        ///     <para>0 - Success</para>
        ///     <para>1 - User is locked out.</para>
        ///     <para>2 - Login failed.</para>
        ///     <para>3 - No user or email was specified.</para>
        ///     <para>4 - User doesn't exist.</para>
        /// </param>
        /// <returns>Null if the user could not be logged in or the UserInformation object </returns>
        public static T LogUserIn <T>(string usernameOrEmail, string password, bool useEmailForLogin, int clientID,
                                      out int outputValue) where T : UserInformation, new()
        {
            T ui = new T();

            ui.Load(usernameOrEmail, password, useEmailForLogin, clientID, out outputValue);
            if (ui.UserID != -1)
            {
                SessionWrapper.Add <UserInformation>("UserInfo", ui);
                return(ui);
            }
            return(null);
        }
 public virtual void ProcessRequest(HttpContext context)
 {
     User = SessionWrapper.Get <T>("UserInfo", null);
     if (User == null)
     {
         string url = context.Server.UrlEncode(context.Request.Url.PathAndQuery);
         if (String.IsNullOrEmpty(url))
         {
             context.Response.Redirect(GetConfigString("LoginPage", RedirectPage), true);
         }
         else
         {
             context.Response.Redirect(GetConfigString("LoginPageWithRedirect", String.Concat(RedirectPage, "?", RedirectVariable, "=", url)), true);
         }
     }
 }
Example #3
0
 protected override void OnPreInit(EventArgs e)
 {
     base.OnPreInit(e);
     User = SessionWrapper.Get <T>("UserInfo", null);
     if (User == null)
     {
         string url = Server.UrlEncode(Request.Url.PathAndQuery);
         if (String.IsNullOrEmpty(url))
         {
             Response.Redirect(GetConfigString("LoginPage", RedirectPage));
         }
         else
         {
             Response.Redirect(GetConfigString("LoginPageWithRedirect", String.Concat(RedirectPage, "?", RedirectVariable, "=", url)));
         }
     }
 }