/** * Performs ajax signup. * @since 1.0 */ public function ajax() { header('Content-Type: application/json'); if (get_option('addon_login_crossdomain', false)) { header('Access-Control-Allow-Origin: *'); } try { // Method validation if ('POST' != $_SERVER['REQUEST_METHOD']) { throw new Exception('Invalid request method.'); } // Token validation if (Request::input('_token') != LoginPage::get_token()) { throw new Exception('Invalid security token.'); } $userdata = $this->generate_userdata(); // Run validations $errors = $this->validate($userdata); do_action('register_post', $userdata['user_login'], $userdata['user_email'], $errors); $errors = apply_filters('registration_errors', $errors, $userdata['user_login'], $userdata['user_email']); if (!empty($errors->errors)) { $raw = []; foreach ($errors->get_error_messages() as $message) { $raw[] = $message; } echo json_encode(['errors' => $raw, 300]); wp_die(); } // Insert other $userdata['ID'] = wp_insert_user($userdata); do_action('user_register', $userdata['ID']); $message = 'Your account has been created!' . '<div><a href="' . LoginPage::get_redirect_to() . '">> back to page I was reading</a></div>' . '<a href="' . home_url('/wp-login.php') . '?redirect_to=' . LoginPage::get_redirect_to() . '">> login now</a>'; echo json_encode(['message' => apply_filters('addon_loginpage_signup_message', $message), 200]); } catch (Exception $e) { echo json_encode(['errors' => [$e->getMessage()], 300]); } wp_die(); }
/** * Performs ajax login. * @since 1.0 */ public function ajax() { $input = ['token' => Request::input('_token'), 'user_login' => Request::input('user_login'), 'user_password' => Request::input('user_password'), 'remember' => Request::input('remember', false)]; header('Content-Type: application/json'); if (get_option('addon_login_crossdomain', false)) { header('Access-Control-Allow-Origin: *'); } try { // Method validation if ('POST' != $_SERVER['REQUEST_METHOD']) { throw new Exception('Invalid request method.'); } // Token validation if ($input['token'] != LoginPage::get_token()) { throw new Exception('Invalid security token.'); } $this->authenticate($input['user_login'], $input['user_password'], $input['remember']); echo json_encode(['redirect_to' => LoginPage::get_redirect_to(), 200]); } catch (Exception $e) { echo json_encode(['errors' => [$e->getMessage()], 300]); } wp_die(); }
/** * Performs ajax login. * @since 1.0 */ public function ajax_reset() { $input = ['token' => Request::input('_token'), 'ID' => Request::input('ID'), 'user_pass' => Request::input('user_pass'), 'repeat_pass' => Request::input('repeat_pass')]; header('Content-Type: application/json'); if (get_option('addon_login_crossdomain', false)) { header('Access-Control-Allow-Origin: *'); } try { // Method validation if ('POST' != $_SERVER['REQUEST_METHOD']) { throw new Exception('Invalid request method.'); } // Token validation if ($input['token'] != LoginPage::get_token()) { throw new Exception('Invalid security token.'); } $user = get_user_by('id', $input['ID']); $errors = new WP_Error(); if (empty($user)) { $errors->add('invalid_user', 'The <strong>User</strong> is invalid.'); } if (empty($input['user_pass'])) { $errors->add('empty_password', 'Field <strong>Password</strong> cannot be empty.'); } if (empty($input['repeat_pass'])) { $errors->add('empty_repeat_password', 'Field <strong>Password (repeat)</strong> can not be empty.'); } if ($input['user_pass'] !== $input['repeat_pass']) { $errors->add('unmatch_passwords', 'Fields <strong>Password</strong> and <strong>Password (repeat)</strong> must match.'); } if (!empty($errors->errors)) { $raw = []; foreach ($errors->get_error_messages() as $message) { $raw[] = $message; } echo json_encode(['errors' => $raw, 300]); wp_die(); } // Change password wp_set_password($input['user_pass'], $user->ID); do_action('password_reset', $user, $input['user_pass']); wp_cache_delete($user->user_login, 'userlogins'); $message = 'Password changed successfully. <a href="' . home_url('/wp-login.php') . '">Would you like to try to login?</a>'; echo json_encode(['message' => apply_filters('addon_loginpage_resetpassword_message', $message), 200]); } catch (Exception $e) { echo json_encode(['errors' => [$e->getMessage()], 300]); } wp_die(); }