Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php require('includes/config.php');
- //if logged in redirect to members page
- if( $user->is_logged_in() ){ header('Location: ../members.php'); }
- //if form has been submitted process it
- if(isset($_POST['submit'])){
- //email validation
- if(!filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)){
- $error[] = 'Please enter a valid email address';
- } else {
- $stmt = $db->prepare('SELECT email,username FROM users WHERE email = :email');
- $stmt->execute(array(':email' => $_POST['email']));
- $row = $stmt->fetch(PDO::FETCH_ASSOC);
- $username = $row['username'];
- if(empty($row['email'])){
- $error[] = 'There is no account associated with this email address. If you believe this is an error please contact support.';
- }
- }
- //if no errors have been created carry on
- if(!isset($error)){
- if (@array_key_exists('HTTP_X_FORWARDED_FOR', $_SERVER)) {
- $ip = @array_pop(explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']));
- }
- //create the activasion code
- $token = bin2hex(random_bytes(32));
- try {
- $stmt = $db->prepare("UPDATE users SET resetToken = :token, resetComplete='No', reset_IP = :ip WHERE email = :email");
- $stmt->execute(array(
- ':email' => $row['email'],
- ':token' => $token,
- ':ip' => $ip
- ));
- //send email
- $to = $row['email'];
- $subject = "Password Reset";
- $body = "<p>Someone requested that the password be reset for user $username.</p>
- <p>If this was a mistake, just ignore this email and nothing will happen.</p>
- <p>To reset your password, visit the following address: <a href='https://thedownliner.com/login/resetcomptest.php?key=$token'>https://thedownliner.com/login/resetPassword.php?key=$token</a></p>
- <p>Accounts</p>
- <p>The Downliner</p>";
- $mail = new Mail();
- $mail->setFrom(SITEEMAIL);
- $mail->addAddress($to);
- $mail->subject($subject);
- $mail->body($body);
- $mail->send();
- //redirect to index page
- header('Location: login.php?action=reset');
- exit;
- //else catch the exception and show the error.
- } catch(PDOException $e) {
- $error[] = $e->getMessage();
- }
- }
- }
- //define page title
- $title = 'Reset Account';
- //include header template
- require('layout/header.php');
- ?>
- <div class="container" style="width: 932px;">
- <br><br>
- <div class="panel panel-default" style="padding: 10px;">
- <div class="row">
- <div class="col-xs-12 col-sm-8 col-md-6 col-sm-offset-2 col-md-offset-3">
- <form role="form" method="post" action="" autocomplete="off">
- <h2>Reset Password</h2>
- <hr>
- <?php
- //check for any errors
- if(isset($error)){
- foreach($error as $error){
- echo '<div class="alert alert-danger" align="center">'.$error.'</div>';
- }
- }
- if(isset($_GET['action'])){
- //check the action
- switch ($_GET['action']) {
- case 'active':
- echo "<div class='alert alert-success' align='center'>Your account is now active you may now log in.</div>";
- break;
- case 'reset':
- echo "<div class='alert alert-success' align='center'>Please check your inbox for a reset link.</div>";
- break;
- }
- }
- ?>
- <div class="form-group">
- <input type="email" name="email" id="email" class="form-control input-lg" placeholder="Email" tabindex="1">
- </div>
- <hr>
- <div class="row">
- <div class="col-xs-6 col-md-6"><input type="submit" name="submit" value="Send Reset Link" class="btn btn-success btn-block btn-lg" tabindex="2"></div>
- <div class="col-xs-6 col-md-6"><a href='login.php' class="btn btn-primary btn-block btn-lg">Back to login page</a></div>
- </div>
- </form>
- <br><br>
- </div>
- </div>
- </div>
- </div>
- <?php
- //include header template
- require('layout/footer.php');
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement