Skip to content

Commit

Permalink
#43 added signin and signup
Browse files Browse the repository at this point in the history
  • Loading branch information
YahyaTec committed Dec 19, 2022
1 parent 8f3a14c commit 5f5be65
Show file tree
Hide file tree
Showing 3 changed files with 1,838 additions and 4 deletions.
64 changes: 64 additions & 0 deletions modules/forms/assets/js/forgot-password.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/**
* landkit.js
*
* Handles behaviour of the theme
*/
( function( $, window ) {
'use strict';

$( '.mas-login-form .login-register-tab-switcher' ).not('.first-bar').on( 'click', function (e) {
e.preventDefault();
$( '#customer_login > .woocommerce-notices-wrapper' ).hide();
$("form.mas-login-form").parent().removeClass("active");
$("form.register").parent().addClass("active");
});

$( '.mas-login-form .elementor-lost-password.login-register-tab-switcher' ).on( 'click', function (e) {
e.preventDefault();
$( '#customer_login > .woocommerce-notices-wrapper' ).hide();
$("form.mas-login-form").parent().removeClass("active");
$("form.mas-register").parent().removeClass("active");
$("form.mas-forget-password").parent().addClass("active");
});
$( '.mas-forget-password .login-register-tab-switcher' ).on( 'click', function (e) {
e.preventDefault();
$( '#customer_login > .woocommerce-notices-wrapper' ).hide();
$("form.mas-forget-password").parent().removeClass("active");
$("form.mas-login-form").parent().addClass("active");
});

$( '.mas-register .login-register-tab-switcher' ).on( 'click', function (e) {
e.preventDefault();
$( '#customer_login > .woocommerce-notices-wrapper' ).hide();
$("form.register").parent().removeClass("active");
$("form.mas-login-form").parent().addClass("active");
});

var hash_value = window.location.hash;

switch( hash_value ) {
case '#customer-login-form':
case '#forget-password-form':
$( 'a.login-register-tab-switcher[href="' + hash_value + '"]' ).trigger( 'click' );
break;
}

//grabs the hash tag from the url
var hash = window.location.hash;
//checks whether or not the hash tag is set
if (hash != "") {
//removes all active classes from tabs
$('.mas-tab-content div').each(function() {
$(this).removeClass('active');
});
//this will add the active class on the hashtagged value
var link = "";
$('.mas-tab-content div').each(function() {
link = $(this).attr('id');
if ('#'+link == hash) {
$(this).addClass('active');
}
});
}

} )( jQuery, window );
83 changes: 79 additions & 4 deletions modules/forms/module.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
namespace MASElementor\Modules\Forms;

use MASElementor\Base\Module_Base;
use WP_Error;

if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly.
Expand All @@ -29,7 +30,8 @@ public function get_name() {
*/
public function get_widgets() {
return array(
'Login',
// 'Login',
'Signin',
);
}

Expand All @@ -38,8 +40,10 @@ public function get_widgets() {
*/
public function __construct() {
parent::__construct();
// add_action( 'wp_loaded', array( $this, 'mas_add_new_member' ) );.
// add_action( 'wp_loaded', array( $this, 'mas_login_member' ) );.
add_action( 'elementor/frontend/before_register_scripts', array( $this, 'register_frontend_scripts' ) );
add_action( 'wp_loaded', array( $this, 'mas_add_new_member' ) );
add_action( 'wp_loaded', array( $this, 'mas_login_member' ) );
add_action( 'wp_loaded', array( $this, 'mas_lost_password' ) );
}

/**
Expand Down Expand Up @@ -67,6 +71,19 @@ public function mas_form_errors() {

}

/**
* Landkit Form Success.
*
* @return WP_Error
*/
public function mas_form_success() {
static $wp_error; // Will hold global variable safely.
if ( ! isset( $wp_error ) ) {
$wp_error = new WP_Error( null, null, null );
}
return $wp_error;
}

/**
* Add new user.
*/
Expand Down Expand Up @@ -163,7 +180,7 @@ public function mas_add_new_member() {
$creds['user_password'] = $password;
$creds['remember'] = true;
if ( $password_generated ) {
mas_form_success()->add( 'verify_user', esc_html__( 'Account created successfully. Please check your email to create your account password', 'mas-elementor' ) );
$this->mas_form_success()->add( 'verify_user', esc_html__( 'Account created successfully. Please check your email to create your account password', 'mas-elementor' ) );
} else {
$user = wp_signon( $creds, false );
// send the newly created user to the home page after logging them in.
Expand Down Expand Up @@ -280,4 +297,62 @@ public function mas_login_member() {
}
}

/**
* Landkit Lost Password function.
*/
public function mas_lost_password() {
$nonce_value = $this->mas_get_var( $_REQUEST['mas_lost_password_nonce'], $this->mas_get_var( $_REQUEST['_wpnonce'], '' ) ); //phpcs:ignore
if ( isset( $_POST['mas_lost_password_check'] ) && wp_verify_nonce( $nonce_value, 'mas-lost-password-nonce' ) ) {
$login = isset( $_POST['user_login'] ) ? sanitize_user( wp_unslash( $_POST['user_login'] ) ) : '';
$user_data = get_user_by( 'login', $login );

if ( empty( $login ) ) {
$this->mas_form_errors()->add( 'empty_user_login', esc_html__( 'Enter a username or email address', 'mas-elementor' ) );

} else {
// Check on username first, as customers can use emails as usernames.
$user_data = get_user_by( 'login', $login );
}
// If no user found, check if it login is email and lookup user based on email.
if ( ! $user_data && is_email( $login ) ) {
$user_data = get_user_by( 'email', $login );
}

do_action( 'lostpassword_post' );

if ( ! $user_data ) {
// if the user name doesn't exist.
$this->mas_form_errors()->add( 'empty_user_login', esc_html__( 'There is no account with that username or email address.', 'mas-elementor' ) );
}

if ( is_multisite() && ! is_user_member_of_blog( $user_data->ID, get_current_blog_id() ) ) {
$this->mas_form_errors()->add( 'empty_user_login', esc_html__( 'Invalid username or email address.', 'mas-elementor' ) );

return false;
}

$errors = $this->mas_form_errors()->get_error_messages();

// only create the user in if there are no errors.
if ( empty( $errors ) ) {
$this->mas_form_success()->add( 'verify_user', esc_html__( 'Passord has been sent to your email', 'mas-elementor' ) );

}
}

}

/**
* Register frontend script.
*/
public function register_frontend_scripts() {
wp_register_script(
'forgot-password',
MAS_ELEMENTOR_MODULES_URL . 'forms/assets/js/forgot-password.js',
array( 'elementor-frontend-modules', 'jquery' ),
MAS_ELEMENTOR_VERSION,
true
);
}

}
Loading

0 comments on commit 5f5be65

Please sign in to comment.