Advertisement
Guest User

Untitled

a guest
Dec 27th, 2016
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.19 KB | None | 0 0
  1. <?php
  2. /**
  3.  * Template Name: reset page
  4.  */
  5. if( is_user_logged_in()){
  6.     wp_redirect(home_url());
  7. }
  8. get_header(); ?>
  9. <main id="main" class="site-main<?php if ($template == 'full') { echo ' full-width'; } ?>" role="main">
  10.     <div class="inner-wrap">
  11.         <div class="wrapper">
  12.             <h1>Przywracanie hasła</h1>
  13.  
  14.                 <?php
  15.  
  16.                 $error = '';
  17.                 $success = '';
  18.  
  19.                 if( isset( $_POST['action'] ) && 'reset' == $_POST['action'] )
  20.                 {
  21.                 $email = trim($_POST['user_login']);
  22.  
  23.                 if( empty( $email ) ) {
  24.                 $error = 'Wprawdź nazwę użytkownika lub adres e-mail.';
  25.                 } else if( ! is_email( $email )) {
  26.                 $error = 'Błędna nazwa użtykownika lub e-mail.';
  27.                 } else if( ! email_exists( $email ) ) {
  28.                 $error = 'Brak zarejestrowanego użytkownika z tym adresem e-mail.';
  29.                 } else {
  30.  
  31.                 $random_password = wp_generate_password( 12, false );
  32.                 $user = get_user_by( 'email', $email );
  33.  
  34.                 $update_user = wp_update_user( array (
  35.                 'ID' => $user->ID,
  36.                 'user_pass' => $random_password
  37.                 )
  38.                 );
  39.  
  40.                 if( $update_user ) {
  41.                 $to = $email;
  42.                 $subject = 'Twoje nowe hasło';
  43.                 $sender = get_option('name');
  44.  
  45.                 $message = 'Twoje nowe hasło to: '.$random_password;
  46.  
  47.                 $headers[] = 'MIME-Version: 1.0' . "\r\n";
  48.                 $headers[] = 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
  49.                 $headers[] = "X-Mailer: PHP \r\n";
  50.                 $headers[] = 'From: '.$sender.' < '.$email.'>' . "\r\n";
  51.  
  52.                 $mail = wp_mail( $to, $subject, $message, $headers );
  53.                 if( $mail )
  54.                 $success = 'Twoje nowe hasło zostało wysłane na twój adres e-mail.';
  55.  
  56.                 } else {
  57.                 $error = 'Oops, coś poszło nie tak...';
  58.                 }
  59.  
  60.                 }
  61.  
  62.                 if( ! empty( $error ) )
  63.                 echo '<div class="message"><div class="wpz-sc-box  alert   ">'. $error .'</div></div>';
  64.  
  65.                 if( ! empty( $success ) )
  66.                 echo '<div class="succes-message"><div class="wpz-sc-box  tick   ">'. $success .'</div></div>';
  67.                 }
  68.                 ?>
  69.  
  70.         <form method="post">
  71.            <fieldset>
  72.                <p>Proszę wprowadzić swoją nazwę użytkownika lub adres email. Twoje nowe hasło zostanie wysłane emailem.</p>
  73.                <p><label for="user_login">Nazwa użytkownika lub E-mail:</label>
  74.                   <?php $user_login = isset( $_POST['user_login'] ) ? $_POST['user_login'] : ''; ?>
  75.                   <input type="text" name="user_login" id="user_login" value="<?php echo $user_login;?>" /></p>
  76.                 <p>
  77.                   <input type="hidden" name="action" value="reset" />
  78.                   <input type="submit" value="Zresetuj hasło" class="button" id="submit" />
  79.                 </p>
  80.             </fieldset>
  81.         </form>
  82.     </div>
  83.     </div>
  84. </main>
  85. <?php get_footer(); ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement