[php] fge

Viewer

  1. <?
  2. require_once '../site.php';
  3. $db->connect();
  4. $token = STAccounts::createCSRFToken();
  5.  
  6. if ($_SERVER['REQUEST_METHOD'] === 'POST') {
  7.  
  8. // Filter username - June 13, 2021
  9. $username = filter_input(INPUT_POST, 'username', FILTER_SANITIZE_SPECIAL_CHARS);
  10.  
  11.         $login = $account->login($username, $_POST['password']);
  12.  
  13.         // Handle our own exceptions until STAccountsException caught
  14.         if (!$login) {
  15.             $log_attempt = $db->query_params('SELECT user_id, email, login_attempts, avatar_thumb AS avatar FROM users WHERE username = :username LIMIT 1', array(
  16.                 'username' => $username
  17.                 ));
  18.                
  19.                 if ($check = $log_attempt->fetch()) {
  20.        
  21.         // Save login attempt
  22.         if (is_null($check['login_attempts'])) {
  23.         $db->query_params('UPDATE users SET login_attempts = 1 WHERE user_id = :user_id', array(
  24.             'user_id' => $check['user_id']
  25.                 ));
  26.     }
  27.  
  28. // dispatch email notice - 3 login failures
  29. if ($check['login_attempts'] <= 3) {
  30.         $errors[] = 'Password <b>incorrect.</b>';
  31.     $db->query_params('UPDATE users SET login_attempts = login_attempts + 1 WHERE user_id = :user_id', array(
  32.         'user_id' => $check['user_id']
  33.     ));
  34. } else if ($check['login_attempts'] >= 3) {
  35.     send_email($check['email'], '3 Failed Login Attempts', '3 Failed Login Attempts', 'Switch-Torrents detected <b>3 failed login attempts</b> to this registered account.', 'Options', 'Reset password', false);
  36.     $db->query_params('UPDATE users SET login_attempts = 0 WHERE user_id = :user_id', array(
  37.         'user_id' => $check['user_id']
  38.     ));
  39.     $errors[] = 'Please try again.';
  40. }
  41.  
  42.         $avatar = '<img src="/' . $check['avatar'] . '" style="width:30px;height:30px;border-radius:100px;vertical-align:middle" />';
  43. } else {
  44.     $errors[] = 'Username <b>not found.</b>';
  45. }
  46.     } else {
  47.         header(sprintf('Location: %s/', $CONFIG['base_url']));
  48.     }
  49. }
  50. site_header();
  51. // Collect errors if any
  52. if (!empty($errors)) {
  53.     foreach ($errors as $error) {
  54.         $message = sprintf('<span class="material-icons" style="color:orange;vertical-align:middle;padding-left:20px">warning</span> %s', $error);
  55.     }
  56. }
  57. printf('<h1 itemprop="name"><span class="card-title">Sign In to %s</span></h1>', html_escape($CONFIG['site_title']));
  58. printf('<article itemprop="itemListElement" itemscope="" itemtype="http://schema.org/Article" class="card" style="height:350px">');
  59. printf('<div style="float:left"><img src="/images/v2_login_banner.png" style="width:180px;height:350px;overflow:auto"></div>');
  60. printf('<div style="float:left;padding-left:30px;margin-top:-30px">');
  61. printf('<form class="cd-form floating-labels" method="POST" action="%s/signin/">', $CONFIG['base_url']);
  62. printf('<fieldset>
  63.             <div class="icon">
  64.                <label class="cd-label" for="cd-name">Username</label>
  65.                <input class="user" type="text" name="username" id="cd-name" placeholder="Username" value="%s" required>
  66.             </div>
  67.             <div class="icon" style="margin-top:-15px">
  68.                <label class="cd-label" for="cd-company">Password</label>
  69.                <input class="company" type="password" name="password" id="cd-company" required>
  70.             </div>
  71.             <div>
  72.                <button class="btn" onclick="this.form.submit()">%s Sign In</button> <span>%s</span>
  73.                <div style="margin-top:15px">Not registered? Sign up <a href="/signup/">here</a></div> 
  74.             </div>
  75.             
  76.          </fieldset>', $_POST['username'], $avatar, $message);
  77. printf('<input type="hidden" name="csrf" value="%s">', $token);
  78. printf('</form>');
  79. printf('</div>');
  80. printf('<div style="clear:both"></div>');
  81. printf('<div class="card-action ng-scope">
  82.          <!-- interactionCount -->
  83.          <span itemprop="interactionCount" class="comments"><a href="/signup/" target="_self" class="ng-binding">Register</a></span>
  84.          <span style="padding-left:10px;padding-right:10px;color:#C0C0C0">-</span>
  85.          <span class="timestamp"><a href="/recover/" target="_self" class="ng-binding">Recover</a></span>
  86.       </div>
  87.    </article>
  88. </div>');
  89. site_footer();

Editor

You can edit this paste and save as new:


File Description
  • fge
  • Paste Code
  • 13 Jun-2021
  • 4.04 Kb
You can Share it: