Jump to content

Exception: Please wait at least 5 seconds before attempting another login. processwire


ankh2054
 Share

Recommended Posts

Hi All,

My login form below. When a user tries to login more than twice in a very short time the following errors is displayed.

Exception: Please wait at least 5 seconds before attempting another login. processwire

I have read a post which states you can capture that error message display it to the user using, but I'm not sure exactly how to use this. Would someone be so kind and offer assistance. 

try {
// Login
} catch (WireException $e) {
// Print out message of exception
echo $e->getMessage();
}
<?php
$login_errors = "";
$out = "";
$form = "<form class='omb_loginForm' action='./' accept-charset='UTF-8' autocomplete='off' method='POST'>
                        
            <div class='input-group'>
                <span class='input-group-addon'><i class='fa fa-user'></i></span>
                <input type='text' class='form-control' name='user' placeholder='Username'>
            </div>
            <span class='help-block'></span>

            <div class='input-group'>
                <span class='input-group-addon'><i class='fa fa-lock'></i></span>
                <input  type='password' class='form-control' name='pass' placeholder='Password'>
            </div>
            <span class='help-block'></span>

            <button class='btn btn-lg btn-primary btn-block' type='submit' name='login_submit' value='Login'>Login</button>
        </form>"
;

//Check if user is already logged in - redirect to 
if($user->isLoggedin()) {
    // user is already logged in, so they don't need to be here
    $session->redirect("/"); 
}




//check for login before outputting markup
if($input->post->user && $input->post->pass) { 



    $user = $sanitizer->username($input->post->user);
    $pass = $input->post->pass; 
    $u = $users->get($user); 



    //Check if the password provided in $pass equals tmp_pass
    if($u->id && $u->tmp_pass && $u->tmp_pass === $pass) {
    // user logging in with tmp_pass, so change it to be their real pass
    $u->of(false);
    $u->pass = $u->tmp_pass;
    $u->save();
    $u->of(true);
    
      $u = $session->login($user, $pass); 
      if($u) {
        // user is logged in, get rid of tmp_pass
        $u->of(false);
        $u->tmp_pass = '';
        $u->save();
        // now redirect to the profile edit page
        $session->redirect('/reset-pass-change/'); 
      }
   }

   //if user not logging if with TMP password carry on as normal.
    try {
        if($session->login($user, $pass)) {
          $session->redirect("/");
       } 

        else {
          $login_errors = "Username or Password is incorrect";
          $out .= $form;
       }

        } 
       catch (Exception $e) {
       $login_errors = $e->getMessage();
    }
   



   /*If user not logging if with TMP password carry on as normal.
    elseif($session->login($user, $pass)) {
        // login successful
        $session->redirect("/"); 
        
        }

    else {
        $login_errors .= "Username or Password is incorrect";
        $out .= $form;

    }*/

}

else {
    $out .= $form;
}



?>



<?php include("./head.inc"); ?>
<?php include("./navbar_login.inc"); ?>

<div class="container">

<div class="omb_login">
            <h3 class="omb_authTitle">Login or <a href="/register/">Sign up</a></h3>
            <div class="row omb_row-sm-offset-3 omb_socialButtons">
                <div class="col-xs-4 col-sm-2">
                    <a href="#" class="btn btn-lg btn-block omb_btn-facebook">
                        <i class="fa fa-facebook visible-xs"></i>
                        <span class="hidden-xs">Facebook</span>
                    </a>
                </div>
                <div class="col-xs-4 col-sm-2">
                    <a href="#" class="btn btn-lg btn-block omb_btn-twitter">
                        <i class="fa fa-twitter visible-xs"></i>
                        <span class="hidden-xs">Twitter</span>
                    </a>
                </div>  
                <div class="col-xs-4 col-sm-2">
                    <a href="#" class="btn btn-lg btn-block omb_btn-google">
                        <i class="fa fa-google-plus visible-xs"></i>
                        <span class="hidden-xs">Google+</span>
                    </a>
                </div>  
            </div>

            <div class="row omb_row-sm-offset-3 omb_loginOr">
                <div class="col-xs-12 col-sm-6">
                    <hr class="omb_hrOr">
                    <span class="omb_spanOr">or</span>
                </div>
            </div>

            <div class="row omb_row-sm-offset-3">
                <div class="col-xs-12 col-sm-6">

                <div class="alert alert-error fade-in alert-dismissable">
                <!-- error outputs -->
                <?php echo $login_errors; ?>
                </div>

               <!-- Form outputs -->
                <?php echo $out; ?>
            </div>
            </div>
            <div class="row omb_row-sm-offset-3">
                <div class="col-xs-12 col-sm-3">
                    <label class="checkbox">
                        <input type="checkbox" name="rememberme" value="1" checked="checked">Remember Me
                    </label>
                </div>
                <div class="col-xs-12 col-sm-3">
                    <p class="omb_forgotPwd">
                        <a href="/reset-pass/">Forgot password?</a>
                    </p>
                </div>
            </div>  

</div>

   

<?php include ("./foot.inc"); ?>
<?php include ("./java.inc"); ?>
Link to comment
Share on other sites

Hi ankh2054!

You can use it like this:

try {
   if($session->login($user, $pass)) {
      $session->redirect("/");
   } else {
      $login_errors = "Username or Password is incorrect";
   }
} catch (Exception $e) {
   $login_errors = $e->getMessage();
}
  • Like 3
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...