PluginProbe
Templately – Elementor & Gutenberg Template Library: 6500+ Free & Pro Ready Templates And Cloud! / 2.2.7
Templately – Elementor & Gutenberg Template Library: 6500+ Free & Pro Ready Templates And Cloud! v2.2.7
3.7.5 3.7.4 3.7.3 3.7.2 1-final 3.7.1 3.7.0 3.6.8 3.6.7 3.6.6 3.6.5 3.6.4 3.6.3 3.6.2 3.6.1 3.0.3 3.0.4 3.0.5 3.0.6 3.0.7 3.0.8 3.0.9 3.1.0 3.1.1 3.1.10 All 111 releases
templately / includes / API / SignUp.php

SignUp.php in Templately – Elementor & Gutenberg Template Library: 6500+ Free & Pro Ready Templates And Cloud! 2.2.7, at includes/API/SignUp.php

89 lines 2.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Templately\API;
4
5 use Templately\Utils\Helper;
6 use Templately\Utils\Options;
7 use WP_REST_Request;
8
9 class SignUp extends API {
10 public function permission_check( WP_REST_Request $request ) {
11 $this->request = $request;
12 return true;
13 }
14
15 public function register_routes() {
16 $this->post('signup', [ $this, 'create_account' ] );
17 }
18
19 public function create_account() {
20 $errors = [];
21 $_ip = Helper::get_ip();
22 $_site_url = home_url( '/' );
23
24 $first_name = $this->get_param( 'first_name' );
25 $last_name = $this->get_param( 'last_name' );
26 $email = $this->get_param( 'email', '', 'sanitize_email' );
27 $password = $this->get_param( 'password' );
28 $confirm_password = $this->get_param( 'confirm_password' );
29
30 if ( empty( $first_name ) ) {
31 $errors['first_name'] = __( 'First name cannot be empty.', 'templately' );
32 }
33 if ( empty( $last_name ) ) {
34 $errors['last_name'] = __( 'Last name cannot be empty.', 'templately' );
35 }
36 if ( empty( $email ) ) {
37 $errors['email'] = __( 'Email cannot be empty.', 'templately' );
38 }
39 if ( $email && ! filter_var( $email, FILTER_VALIDATE_EMAIL ) ) {
40 $errors['email'] = __( 'Make sure you have given a valid email address.', 'templately' );
41 }
42 if ( empty( $password ) ) {
43 $errors['password'] = __( 'Password cannot be empty.', 'templately' );
44 }
45 if ( empty( $confirm_password ) ) {
46 $errors['confirm_password'] = __( 'Confirm password cannot be empty.', 'templately' );
47 }
48
49 if ( ! empty( $password ) && ! empty( $confirm_password ) && $password !== $confirm_password ) {
50 $errors['password_mismatched'] = __( 'Password and confirm password should be matched.', 'templately' );
51 }
52
53 if ( ! empty( $errors ) ) {
54 return $this->error( 'signup_errors', $errors, 'signup', '400' );
55 }
56
57 $query = 'status, message, user{ id, name, first_name, last_name, display_name, email, profile_photo, joined, is_verified, api_key, plan, plan_expire_at, my_cloud{ limit, usages, last_pushed }, show_notice }';
58
59 $response = $this->http()->mutation(
60 'createUser',
61 $query,
62 [
63 'first_name' => $first_name,
64 'last_name' => $last_name,
65 'email' => $email,
66 'password' => $password,
67 'site_url' => $_site_url,
68 'ip' => $_ip
69 ]
70 )->post();
71
72 if( is_wp_error( $response ) ) {
73 return $response;
74 }
75
76 if ( ! Login::is_globally_signed() ) {
77 Options::set_global_login();
78 }
79
80 if ( ! empty( $response['user']['api_key'] ) ) {
81 $this->utils('options')->set( 'api_key', $response['user']['api_key'] );
82 unset( $response['user']['api_key'] );
83 }
84
85 $this->utils('options')->set( 'user', $response['user'] );
86
87 return $response;
88 }
89 }