PluginProbe
JSON API Auth / 1.6
JSON API Auth v1.6
3.1.2 3.1.1 2.0.0 2.1.0 2.2.0 2.3.0 2.4.0 2.5.0 2.6.0 2.7.0 2.7.1 2.8.0 2.9.0 2.9.1 3.0.0 3.1.0 trunk 0.1 1.0 1.1 1.2 1.3 1.4 1.5 1.5.1 All 33 releases
← All changes | controllers/Auth.php +150 -249 1.21.6 View file →
@@ -1,250 +1,151 @@
1 -<?php
2 -
3 -/*
4 -
5 -Controller Name: Auth
6 -
7 -Controller Description: Authentication add-on controller for the Wordpress JSON API plugin
8 -
9 -Controller Author: Matt Berg
10 -
11 -Controller Author Twitter: @mattberg
12 -
13 -*/
14 -
15 -
16 -
17 -class JSON_API_Auth_Controller {
18 -
19 -
20 -
21 - public function validate_auth_cookie() {
22 -
23 - global $json_api;
24 -
25 -
26 -
27 - if (!$json_api->query->cookie) {
28 -
29 - $json_api->error("You must include a 'cookie' authentication cookie. Use the `create_auth_cookie` Auth API method.");
30 -
31 - }
32 -
33 -
34 -
35 - $valid = wp_validate_auth_cookie($json_api->query->cookie, 'logged_in') ? true : false;
36 -
37 -
38 -
39 - return array(
40 -
41 - "valid" => $valid
42 -
43 - );
44 -
45 - }
46 -
47 -
48 -
49 - public function generate_auth_cookie() {
50 -
51 - global $json_api;
52 -
53 -
54 -
55 - $nonce_id = $json_api->get_nonce_id('auth', 'generate_auth_cookie');
56 -
57 - if (!wp_verify_nonce($json_api->query->nonce, $nonce_id)) {
58 -
59 - $json_api->error("Your 'nonce' value was incorrect. Use the 'get_nonce' API method.");
60 -
61 - }
62 -
63 -
64 -
65 - if (!$json_api->query->username) {
66 -
67 - $json_api->error("You must include a 'username' var in your request.");
68 -
69 - }
70 -
71 -
72 -
73 - if (!$json_api->query->password) {
74 -
75 - $json_api->error("You must include a 'password' var in your request.");
76 -
77 - }
78 -
79 -
80 -
81 - $user = wp_authenticate($json_api->query->username, $json_api->query->password);
82 -
83 - if (is_wp_error($user)) {
84 -
85 - $json_api->error("Invalid username and/or password.", 'error', '401');
86 -
87 - remove_action('wp_login_failed', $json_api->query->username);
88 -
89 - }
90 -
91 -
92 -
93 - $expiration = time() + apply_filters('auth_cookie_expiration', -1209600, $user->ID, true);
94 -
95 -
96 -
97 - $cookie = wp_generate_auth_cookie($user->ID, $expiration, 'logged_in');
98 -
99 -
100 -
101 -
102 -
103 - preg_match('|src="(.+?)"|', get_avatar( $user->ID, 32 ), $avatar);
104 -
105 -
106 -
107 -
108 -
109 -
110 -
111 - return array(
112 -
113 - "cookie" => $cookie,
114 -
115 - "user" => array(
116 -
117 - "id" => $user->ID,
118 -
119 - "username" => $user->user_login,
120 -
121 - "nicename" => $user->user_nicename,
122 -
123 - "email" => $user->user_email,
124 -
125 - "url" => $user->user_url,
126 -
127 - "registered" => $user->user_registered,
128 -
129 - "displayname" => $user->display_name,
130 -
131 - "firstname" => $user->user_firstname,
132 -
133 - "lastname" => $user->last_name,
134 -
135 - "nickname" => $user->nickname,
136 -
137 - "description" => $user->user_description,
138 -
139 - "capabilities" => $user->wp_capabilities,
140 -
141 - "avatar" => $avatar[1]
142 -
143 - ),
144 -
145 - );
146 -
147 - }
148 -
149 -
150 -public function clear_auth_cookie() {
151 -
152 - global $json_api;
153 -
154 - if (!$json_api->query->cookie) {
155 -
156 - $json_api->error("You must include a valid 'cookie' to clear it.");
157 -
158 - }
159 -
160 - $user_id = wp_validate_auth_cookie($json_api->query->cookie, 'logged_in');
161 -
162 - if (!$user_id) {
163 -
164 - $json_api->error("Invalid authentication cookie. Provide a valid cookie to clear.");
165 -
166 - }
167 -
168 - $expiration = time() + apply_filters('auth_cookie_expiration', -1209600, $user_id, true);
169 -
170 - $cookie = wp_generate_auth_cookie($user_id, $expiration, 'logged_in');
171 -
172 - $valid = wp_validate_auth_cookie($cookie, 'logged_in') ? true : false;
173 -
174 - return array(
175 -
176 - "valid" => $valid
177 -
178 - );
179 -
180 - }
181 -
182 - public function get_currentuserinfo() {
183 -
184 - global $json_api;
185 -
186 -
187 -
188 - if (!$json_api->query->cookie) {
189 -
190 - $json_api->error("You must include a 'cookie' var in your request. Use the `generate_auth_cookie` Auth API method.");
191 -
192 - }
193 -
194 -
195 -
196 - $user_id = wp_validate_auth_cookie($json_api->query->cookie, 'logged_in');
197 -
198 - if (!$user_id) {
199 -
200 - $json_api->error("Invalid authentication cookie. Use the `generate_auth_cookie` Auth API method.");
201 -
202 - }
203 -
204 -
205 -
206 - $user = get_userdata($user_id);
207 -
208 - preg_match('|src="(.+?)"|', get_avatar( $user->ID, 32 ), $avatar);
209 -
210 -
211 -
212 - return array(
213 -
214 - "user" => array(
215 -
216 - "id" => $user->ID,
217 -
218 - "username" => $user->user_login,
219 -
220 - "nicename" => $user->user_nicename,
221 -
222 - "email" => $user->user_email,
223 -
224 - "url" => $user->user_url,
225 -
226 - "registered" => $user->user_registered,
227 -
228 - "displayname" => $user->display_name,
229 -
230 - "firstname" => $user->user_firstname,
231 -
232 - "lastname" => $user->last_name,
233 -
234 - "nickname" => $user->nickname,
235 -
236 - "description" => $user->user_description,
237 -
238 - "capabilities" => $user->wp_capabilities,
239 -
240 - "avatar" => $avatar[1]
241 -
242 - )
243 -
244 - );
245 -
246 - }
247 -
248 -
249 -
1 +<?php
2 +
3 +/*
4 +Controller Name: Auth
5 +Controller Description: Authentication add-on controller for the Wordpress JSON API plugin
6 +Controller Author: Matt Berg, Ali Qureshi
7 +Controller Author Twitter: @parorrey
8 +*/
9 +
10 +
11 +
12 +
13 +
14 +
15 +
16 +class JSON_API_Auth_Controller {
17 +
18 +
19 + public function validate_auth_cookie() {
20 +
21 + global $json_api;
22 +
23 + if (!$json_api->query->cookie) {
24 +
25 + $json_api->error("You must include a 'cookie' authentication cookie. Use the `create_auth_cookie` Auth API method.");
26 +
27 + }
28 +
29 + $valid = wp_validate_auth_cookie($json_api->query->cookie, 'logged_in') ? true : false;
30 +
31 + return array(
32 +
33 + "valid" => $valid
34 +
35 + );
36 +
37 +
38 + }
39 +
40 + public function generate_auth_cookie() {
41 +
42 + global $json_api;
43 +
44 + /*
45 + $nonce_id = $json_api->get_nonce_id('auth', 'generate_auth_cookie');
46 +
47 + if (!wp_verify_nonce($json_api->query->nonce, $nonce_id)) {
48 +
49 + $json_api->error("Your 'nonce' value was incorrect. Use the 'get_nonce' API method.");
50 + }*/
51 +
52 +
53 + if (!$json_api->query->username) {
54 +
55 + $json_api->error("You must include a 'username' var in your request.");
56 +
57 + }
58 +
59 +
60 + if (!$json_api->query->password) {
61 +
62 + $json_api->error("You must include a 'password' var in your request.");
63 +
64 + }
65 +
66 + if ($json_api->query->seconds) $seconds = (int) $json_api->query->seconds;
67 +
68 + else $seconds = 1209600;//14 days
69 +
70 +
71 +
72 + $user = wp_authenticate($json_api->query->username, $json_api->query->password);
73 +
74 + if (is_wp_error($user)) {
75 +
76 + $json_api->error("Invalid username and/or password.", 'error', '401');
77 +
78 + remove_action('wp_login_failed', $json_api->query->username);
79 +
80 + }
81 +
82 +
83 + $expiration = time() + apply_filters('auth_cookie_expiration', $seconds, $user->ID, true);
84 +
85 + $cookie = wp_generate_auth_cookie($user->ID, $expiration, 'logged_in');
86 +
87 + preg_match('|src="(.+?)"|', get_avatar( $user->ID, 32 ), $avatar);
88 +
89 + return array(
90 + "cookie" => $cookie,
91 + "cookie_name" => LOGGED_IN_COOKIE,
92 + "user" => array(
93 + "id" => $user->ID,
94 + "username" => $user->user_login,
95 + "nicename" => $user->user_nicename,
96 + "email" => $user->user_email,
97 + "url" => $user->user_url,
98 + "registered" => $user->user_registered,
99 + "displayname" => $user->display_name,
100 + "firstname" => $user->user_firstname,
101 + "lastname" => $user->last_name,
102 + "nickname" => $user->nickname,
103 + "description" => $user->user_description,
104 + "capabilities" => $user->wp_capabilities,
105 + "avatar" => $avatar[1]
106 +
107 + ),
108 + );
109 + }
110 +
111 +
112 + public function get_currentuserinfo() {
113 + global $json_api;
114 +
115 + if (!$json_api->query->cookie) {
116 + $json_api->error("You must include a 'cookie' var in your request. Use the `generate_auth_cookie` Auth API method.");
117 +
118 + }
119 +
120 + $user_id = wp_validate_auth_cookie($json_api->query->cookie, 'logged_in');
121 +
122 + if (!$user_id) {
123 + $json_api->error("Invalid authentication cookie. Use the `generate_auth_cookie` Auth API method.");
124 + }
125 +
126 + $user = get_userdata($user_id);
127 + preg_match('|src="(.+?)"|', get_avatar( $user->ID, 32 ), $avatar);
128 +
129 + return array(
130 + "user" => array(
131 + "id" => $user->ID,
132 + "username" => $user->user_login,
133 + "nicename" => $user->user_nicename,
134 + "email" => $user->user_email,
135 + "url" => $user->user_url,
136 + "registered" => $user->user_registered,
137 + "displayname" => $user->display_name,
138 + "firstname" => $user->user_firstname,
139 + "lastname" => $user->last_name,
140 + "nickname" => $user->nickname,
141 + "description" => $user->user_description,
142 + "capabilities" => $user->wp_capabilities,
143 +
144 + "avatar" => $avatar[1]
145 +
146 + )
147 +
148 + );
149 +
150 + }
250 151 }