예제 #1
0
        public bool AuthenticateUser()
        {
            var v = Controller.GetCurrentContext();
            AuthenticationModule am = (AuthenticationModule)Controller.GetCurrentContext().ApplicationInstance.Modules["AuthenticationModule"];

            // AuthenticationModule am = new AuthenticationModule();
            if (View.GetUserName.Trim().Length > 0 && View.GetPassword.Trim().Length > 0)
            {
                try
                {
                    if (am.AuthenticateUser(View.GetUserName, View.GetPassword, View.PersistLogin))
                    {
                        return(true);
                    }
                    else
                    {
                        return(false);
                    }
                }
                catch (Exception ex)
                {
                    throw new Exception(ex.Message);
                }
            }
            else
            {
                throw new Exception("USERNAMEPASSWORDMISSING");
            }
        }
예제 #2
0
 protected void BtnCommand_Click(object sender, EventArgs e)
 {
     string retUrl = "";
     try
     {
         AuthenticationModule am = new AuthenticationModule();
         if (am != null)
         {
             int result = am.AuthenticateUser(txtUsername.Text, txtPassword.Text, chkrememberme.Checked);
             if (result > 0)
             {
                 if (Request.Params["ru"] != null)
                 {
                     retUrl = Request.QueryString["ru"];
                     Response.Redirect(Util.BaseSiteUrl + "a.aspx?p=" + retUrl, true);
                 }
                 else
                 {
                     Response.Redirect(Util.BaseSiteUrl + "a.aspx?p=admin-home", true);
                 }
             }
             else if (result < 0)
             {
                 this.lblError.Text = "You have not activated you account,  Kindly check your email and click on the activate this account link.";
                 this.lblError.Visible = true;
                 ViewState["Tries"] = System.Convert.ToInt32(ViewState["Tries"]) + 1;
                 if (System.Convert.ToInt32(ViewState["Tries"]) > 3)
                 {
                     Response.Redirect("~/Denied.aspx?times=" + ViewState["Tries"].ToString(), true);
                 }
             }
             else
             {
                 this.lblError.Text = "Invalid user name or password.";
                 this.lblError.Visible = true;
                 // Otherwise, increment number of tries.
                 ViewState["Tries"] = System.Convert.ToInt32(ViewState["Tries"]) + 1;
                 if (System.Convert.ToInt32(ViewState["Tries"]) > 3)
                 {
                     Response.Redirect("Denied.aspx?times=" + ViewState["Tries"].ToString(), true);
                 }
             }
         }
         else
         {
             throw new Exception("Modules Not Supported on the Server");
         }
     }
     catch (Exception ex)
     {
         this.lblError.Text = ex.Message;
     }
 }
예제 #3
0
        private void btnLogin_Click(object sender, System.EventArgs e)
        {
            AuthenticationModule am = (AuthenticationModule)this.Context.ApplicationInstance.Modules["AuthenticationModule"];

            if (am.AuthenticateUser(txtUsername.Text, txtPassword.Text, false))
            {
                Context.Response.Redirect(FormsAuthentication.GetRedirectUrl(this.User.Identity.Name, false));
            }
            else
            {
                this.lblError.Text    = "Invalid username or password.";
                this.lblError.Visible = true;
            }
        }
예제 #4
0
        public ActionResult Login(LoginViewModel model, string returnUrl)
        {
            string errorMsg = "";

            if (ModelState.IsValid)
            {
                bool isLoginSc = AuthenticationModule.AuthenticateUser(model.LoginName, model.Password, ref errorMsg);
                if (isLoginSc)
                {
                    return(RedirectToAction("Index", "Aplication"));
                }
                ViewBag.errorMsg = errorMsg;
            }
            return(View(model));
        }
예제 #5
0
        protected void btnLogin_Click(object sender, System.EventArgs e)
        {
            AuthenticationModule am = (AuthenticationModule)Context.ApplicationInstance.Modules["AuthenticationModule"];

            if (this.txtUsername.Text.Trim().Length > 0 && this.txtPassword.Text.Trim().Length > 0)
            {
                try
                {
                    if (am.AuthenticateUser(this.txtUsername.Text, this.txtPassword.Text, this.chkPersistLogin.Checked))
                    {
                        this.lblLoggedInUser.Text = this.txtUsername.Text;
                        this.pnlUserInfo.Visible  = true;
                        this.pnlLogin.Visible     = false;
                    }
                    else
                    {
                        this.lblLoginError.Text = base.GetText("USERNAMEPASSWORDERROR");
                    }
                }
                catch (Exception ex)
                {
                    this.lblLoginError.Text = base.GetText("LOGINERROR") + " " + ex.Message;
                }
            }
            else
            {
                this.lblLoginError.Text = base.GetText("USERNAMEPASSWORDMISSING");
            }

            if (this.lblLoginError.Text.Length > 0)
            {
                this.lblLoginError.Visible = true;
            }
            else
            {
                // Redirect to self to refresh rendering of the page because this event happens after
                // everything is already constructed.
                Context.Response.Redirect(Context.Request.RawUrl);
            }
        }