Particulate recovery form



  • There is a form of authorization and registration. A mechanism for re-establishing the password is needed. The uniform is ready. Requests from OBD should be made through AJAX(js,jQuery). Type requests to find an E-mail record, etc.

    $user=mysqli:findOne('users','email=?',array($data['email'])); R::store($user);

    These are requests from RedBeanPHP. Something similar is desirable, but through AJAX(js,jQuery)



  • <form>
    <label for="Email">Enter your email for password reset: <input type="text" id="email" value=""></label>
    </form>
    
    $.ajax({
    

    url: '/password/forgot',
    type: 'POST',
    data: 'email='+$('#email').val()
    error: function(req, text, error) {
    alert(error);
    },
    success: function ( data ) {
    if ( data ) {
    if ( typeof data.success !== typeof undefined ) {
    alert('Password has been reset. Check your mailbox for further instructions ');
    } else if ( typeof data.error !== typeof undefined ) {
    alert('Error: '+data.message);
    }
    } else { alert('Unknown server response!'); }
    },
    });

    /* PasswordController.php /
    public function Forgot() {
    $data = new \stdClass();
    $data->error = true;
    $data->message = 'No email specicifed!';
    if ( is_array( $_POST ) && isset($_POST['email']) && trim($_POST['email']) != '' ) {
    /
    FILTER_FLAG_EMAIL_UNICODE - нужен чтобы поддерживать кириллические домены /
    $data->message = 'Email have incorrect format!';
    if ( filter_var( $_POST['email'], FILTER_VALIDATE_EMAIL, FILTER_FLAG_EMAIL_UNICODE) ) {
    R::setup( 'mysqli:host=localhost;dbname= ...','root', '', false);
    $data->message = 'Unable to connect to database!';
    if ( R::testConnection() ) {
    $user = R::findOne('users', 'email = ?', array( trim($_POST['email'] ) ));
    $data->message = 'User with email='.trim($_POST['email'] ).' not found!';
    if ( $user ) {
    $user->password = md5( time() );
    R::store($user);
    /

    * Sending mail with instructions at this place...
    */
    unset($data->error);
    $data->success = true;
    $data->message = 'OK';
    }
    }
    }
    }
    echo json_ecode($data);
    }



Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2