@@ -8,28 +8,123 @@ public function __construct() {
88 parent ::__construct ();
99 }
1010
11- public function get_users ()
11+ /**
12+ * demo method
13+ *
14+ * @link [api/user/demo]
15+ * @method POST
16+ * @return Response|void
17+ */
18+ public function demo ()
1219 {
1320 header ("Access-Control-Allow-Origin: * " );
1421
22+ // API Configuration
1523 $ this ->_apiConfig ([
1624 /**
17- * By Default Method `GET`
25+ * By Default Request Method `GET`
1826 */
19- 'methods ' => ['GET ' , 'POST ' , 'OPTIONS ' ],
27+ 'methods ' => ['POST ' ], // 'GET', 'OPTIONS'
28+
2029 /**
21- * number limit, type limit, time limit (last minute)
30+ * Number limit, type limit, time limit (last minute)
2231 */
23- // 'limit' => [5, 'ip', 'everyday'],
32+ 'limit ' => [5 , 'ip ' , 'everyday ' ],
2433
2534 /**
2635 * type :: ['header', 'get', 'post']
2736 * key :: ['table : Check Key in Database', 'key']
2837 */
29- // 'key' => ['GET' ], // type, {key}|table (by default)
38+ 'key ' => ['POST ' , $ this -> key () ], // type, {key}|table (by default)
3039 ]);
3140
32-
33- // echo "HELLO WORLD";
41+ // return data
42+ $ this ->api_return (
43+ [
44+ 'status ' => true ,
45+ "result " => "Return API Response " ,
46+ ],
47+ 200 );
48+ }
49+
50+ /**
51+ * Check API Key
52+ *
53+ * @return key|string
54+ */
55+ private function key ()
56+ {
57+ // use database query for get valid key
58+
59+ return 1452 ;
60+ }
61+
62+
63+ /**
64+ * login method
65+ *
66+ * @link [api/user/login]
67+ * @method POST
68+ * @return Response|void
69+ */
70+ public function login ()
71+ {
72+ header ("Access-Control-Allow-Origin: * " );
73+
74+ // API Configuration
75+ $ this ->_apiConfig ([
76+ 'methods ' => ['POST ' ],
77+ ]);
78+
79+ // you user authentication code will go here, you can compare the user with the database or whatever
80+ $ payload = [
81+ 'id ' => "Your User's ID " ,
82+ 'other ' => "Some other data "
83+ ];
84+
85+ // Load Authorization Library or Load in autoload config file
86+ $ this ->load ->library ('authorization_token ' );
87+
88+ // generte a token
89+ $ token = $ this ->authorization_token ->generateToken ($ payload );
90+
91+ // return data
92+ $ this ->api_return (
93+ [
94+ 'status ' => true ,
95+ "result " => [
96+ 'token ' => $ token ,
97+ ],
98+
99+ ],
100+ 200 );
101+ }
102+
103+ /**
104+ * view method
105+ *
106+ * @link [api/user/view]
107+ * @method POST
108+ * @return Response|void
109+ */
110+ public function view ()
111+ {
112+ header ("Access-Control-Allow-Origin: * " );
113+
114+ // API Configuration [Return Array: User Token Data]
115+ $ user_data = $ this ->_apiConfig ([
116+ 'methods ' => ['POST ' ],
117+ 'requireAuthorization ' => true ,
118+ ]);
119+
120+ // return data
121+ $ this ->api_return (
122+ [
123+ 'status ' => true ,
124+ "result " => [
125+ 'user_data ' => $ user_data ['token_data ' ]
126+ ],
127+ ],
128+ 200 );
34129 }
35130}
0 commit comments