Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * Template Name: reset page
- */
- if( is_user_logged_in()){
- wp_redirect(home_url());
- }
- get_header(); ?>
- <main id="main" class="site-main<?php if ($template == 'full') { echo ' full-width'; } ?>" role="main">
- <div class="inner-wrap">
- <div class="wrapper">
- <h1>Przywracanie hasła</h1>
- <?php
- $error = '';
- $success = '';
- if( isset( $_POST['action'] ) && 'reset' == $_POST['action'] )
- {
- $email = trim($_POST['user_login']);
- if( empty( $email ) ) {
- $error = 'Wprawdź nazwę użytkownika lub adres e-mail.';
- } else if( ! is_email( $email )) {
- $error = 'Błędna nazwa użtykownika lub e-mail.';
- } else if( ! email_exists( $email ) ) {
- $error = 'Brak zarejestrowanego użytkownika z tym adresem e-mail.';
- } else {
- $random_password = wp_generate_password( 12, false );
- $user = get_user_by( 'email', $email );
- $update_user = wp_update_user( array (
- 'ID' => $user->ID,
- 'user_pass' => $random_password
- )
- );
- if( $update_user ) {
- $to = $email;
- $subject = 'Twoje nowe hasło';
- $sender = get_option('name');
- $message = 'Twoje nowe hasło to: '.$random_password;
- $headers[] = 'MIME-Version: 1.0' . "\r\n";
- $headers[] = 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
- $headers[] = "X-Mailer: PHP \r\n";
- $headers[] = 'From: '.$sender.' < '.$email.'>' . "\r\n";
- $mail = wp_mail( $to, $subject, $message, $headers );
- if( $mail )
- $success = 'Twoje nowe hasło zostało wysłane na twój adres e-mail.';
- } else {
- $error = 'Oops, coś poszło nie tak...';
- }
- }
- if( ! empty( $error ) )
- echo '<div class="message"><div class="wpz-sc-box alert ">'. $error .'</div></div>';
- if( ! empty( $success ) )
- echo '<div class="succes-message"><div class="wpz-sc-box tick ">'. $success .'</div></div>';
- }
- ?>
- <form method="post">
- <fieldset>
- <p>Proszę wprowadzić swoją nazwę użytkownika lub adres email. Twoje nowe hasło zostanie wysłane emailem.</p>
- <p><label for="user_login">Nazwa użytkownika lub E-mail:</label>
- <?php $user_login = isset( $_POST['user_login'] ) ? $_POST['user_login'] : ''; ?>
- <input type="text" name="user_login" id="user_login" value="<?php echo $user_login;?>" /></p>
- <p>
- <input type="hidden" name="action" value="reset" />
- <input type="submit" value="Zresetuj hasło" class="button" id="submit" />
- </p>
- </fieldset>
- </form>
- </div>
- </div>
- </main>
- <?php get_footer(); ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement