Plugin Directory

Changeset 2909511


Ignore:
Timestamp:
05/08/2023 12:27:39 PM (3 years ago)
Author:
stacks
Message:

signup with phone

Location:
stacks-mobile-app-builder/trunk
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • stacks-mobile-app-builder/trunk/api/mobile/woocommerce/api/models/login-providers/login-provider.php

    r2739350 r2909511  
    4242
    4343    /**
     44     * Get all users by email
     45     *
     46     * @param string $email
     47     *
     48     * @return array|false
     49     */
     50    public function get_users_by_username($username) {
     51        return get_user_by('login', $username);
     52    }
     53
     54    /**
    4455     * return valid user response
    4556     *
  • stacks-mobile-app-builder/trunk/api/mobile/woocommerce/api/models/login-providers/manual-login-provider.php

    r2739350 r2909511  
    2626    public function login() {
    2727        $user = $this->get_users_by_email($this->get_email());
    28 
     28        if( empty($user) ) {
     29            $user = $this->get_users_by_username($this->get_email());
     30        }
    2931        if ($user && !empty($user)) {
    3032
  • stacks-mobile-app-builder/trunk/api/mobile/woocommerce/api/services/service-stacks-wc-checkout.php

    r2739350 r2909511  
    134134
    135135        $this->validate_checkout($this->posted_data, $errors);
    136 
    137         if (!empty($errors->get_error_messages())) {
     136        if (!empty($errors->get_error_messages()) && $errors->get_error_data()['id'] !== "billing_email") {
    138137            foreach ($errors->get_error_messages() as $message) {
    139138                $notices_log[] = $message;
  • stacks-mobile-app-builder/trunk/api/mobile/woocommerce/api/v1/authentication/registration-controller.php

    r2766500 r2909511  
    6161            'schema' => array($this, 'get_public_item_schema'),
    6262        ));
     63
     64        register_rest_route($this->get_api_endpoint(), 'register_phone', array( // V3
     65            array(
     66                'methods'             => WP_REST_Server::READABLE,
     67                'callback'            => array($this, 'register_phone_number'),
     68                // 'permission_callback' => array($this, 'get_items_permissions_check'),
     69                'args'                => $this->get_collection_params(),
     70            ),
     71            'schema' => array($this, 'get_public_item_schema'),
     72        ));
    6373    }
    6474
     
    152162
    153163        // set current user to inform all other filters and plugins that there is a user working
     164        $user = new WP_User($user_id);
     165        wp_set_current_user($user->ID, $user->user_login);
     166
     167        // let other plugins hook and edit returned array
     168        $returned_data = apply_filters('_stacks_api_before_sending_register_success', [], $user->ID);
     169
     170        $this->update_success_return_message($this->get_message('registeration_successfull'));
     171
     172        // every thing okay
     173        return $this->return_success_response($returned_data);
     174    }
     175
     176    public function register_phone_number( $request ) {
     177        $this->map_request_params($request->get_params());
     178
     179        $password = sanitize_text_field( $request->get_param( 'password' ) );
     180        $phone = sanitize_text_field( $request->get_param( 'phone' ) );
     181   
     182        if ( empty( $password ) || empty( $phone ) ) {
     183            return $this->return_error_response('registration_failed',  __( 'Please fill all required fields.' ),array( 'status' => 400 ));
     184        }
     185
     186        /** 1- type exists and we validate it exists **/
     187        $this->validate_type();
     188        $this->validate_required_parameters_exists('phone');
     189
     190        if ($this->has_errors()) {
     191            return $this->return_invalid_parameter_response();
     192        }
     193
     194        $this->validate_device_settings();
     195
     196        if ($this->has_errors()) {
     197            return $this->return_invalid_device_type_response();
     198        }
     199
     200        // contact model and set parameters and get array to persist
     201        $result = $this->get_model_instance()->set_params($this->data)->collect_parameters();
     202
     203        // errors appeared from thrid party or wordpress
     204        if (!$result['success']) {
     205            return $this->return_fetch_parameters_error_response($result['errors']);
     206        }
     207
     208        // Check if the phone number is already registered
     209        $user_by_phone = get_users( array(
     210            'meta_key' => 'shipping_phone',
     211            'meta_value' => $phone,
     212            'fields' => 'ID',
     213        ) );
     214        if ( ! empty( $user_by_phone ) ) {
     215            return $this->return_error_response('registration_failed',  __( 'This phone number is already registered.' ),array( 'status' => 400 ));
     216        }
     217        $result['params']['user_login'] = $phone;
     218        $user_registered = $this->model->persist($result['params']);
     219
     220        // error happened while registering user
     221        if (!$user_registered['success']) {
     222            return $this->return_error_response(Stacks_WC_Api_Response_Service::UNEXPECTED_ERROR_CODE, $this->unexpected_error_message(), $user_registered['errors'], 500);
     223        }
     224        $user_id = $user_registered['user_id'];
     225        update_user_meta( $user_id, 'shipping_phone', $phone );
     226       
     227        // save user meta
     228        update_user_meta($user_id, 'billing_phone', $phone);
     229       
     230   
    154231        $user = new WP_User($user_id);
    155232        wp_set_current_user($user->ID, $user->user_login);
  • stacks-mobile-app-builder/trunk/api/mobile/woocommerce/api/v1/authentication/registration-login-abstract-controller.php

    r2751673 r2909511  
    1919    protected $facebook_required_parameters = array('access_token', 'device_type', 'device_id');
    2020    protected $manual_required_parameters   = array('email', 'first_name', 'last_name', 'password', 'device_type', 'device_id');
     21    protected $manual_required_parameters_phone   = array('phone', 'first_name', 'last_name', 'password', 'device_type', 'device_id');
    2122    protected $allowed_device_types        = array('android', 'ios');
    2223
     
    7374     * @return $this
    7475     */
    75     protected function validate_required_parameters_exists() {
     76    protected function validate_required_parameters_exists($registeration_type = 'email') {
    7677        switch ($this->active_method) {
    7778            case 'facebook':
     
    7980                break;
    8081            case 'manual':
    81                 $this->validate_parameters($this->manual_required_parameters);
     82                if($registeration_type == 'phone') {
     83                    $this->validate_parameters($this->manual_required_parameters_phone);
     84                } else {
     85                    $this->validate_parameters($this->manual_required_parameters);
     86                }
     87               
    8288                break;
    8389        }
  • stacks-mobile-app-builder/trunk/helper_functions.php

    r2905445 r2909511  
    129129 *                                Definitions                                  *
    130130 * =========================================================================== */
    131 define('stacks_version', '5.0.7');
     131define('stacks_version', '5.0.8');
    132132define('STACKS_BRAIN', 'http://tunnel.stacksmarket.co:8083');
    133133define('STACKS_WC_API', plugin_dir_path(__FILE__) . 'api/mobile/woocommerce/api');
  • stacks-mobile-app-builder/trunk/index.php

    r2905445 r2909511  
    66 * Author URI: stacksmarket.co
    77 * Description: Enjoy the fast and easy experience of building your Ecommerce mobile application
    8  * Version: 5.0.7
     8 * Version: 5.0.8
    99 */
    1010class stacks_app_builder {
  • stacks-mobile-app-builder/trunk/readme.txt

    r2905445 r2909511  
    66Requires PHP: 7.4
    77WC tested up to: 7.4.0
    8 Stable tag: 5.0.7
     8Stable tag: 5.0.8
    99License: GPLv2 or later
    1010License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    121121
    122122== Changelog ==
     123
     124= 5.0.8 (08 May, 2023) =
     125* App: Allow users to signup, login and checkout with their phone number instead of email
     126* Builder: possibility to choose between required phone or email on signup
    123127
    124128= 5.0.7 (28 April, 2023) =
Note: See TracChangeset for help on using the changeset viewer.