diff options
author | ꦌꦫꦶꦏ꧀ꦦꦿꦧꦮꦑꦩꦭ꧀ <erik@darapsa.co.id> | 2021-06-16 22:32:10 +0800 |
---|---|---|
committer | ꦌꦫꦶꦏ꧀ꦦꦿꦧꦮꦑꦩꦭ꧀ <erik@darapsa.co.id> | 2021-06-16 22:32:10 +0800 |
commit | adbe76047fc207eb09a2e03d4231e0713360140f (patch) | |
tree | 2e745687268c0464741275f7f4918b7edc94cc7a | |
parent | 33dcd889f48b1daed6bdf4d41a4f7463e64df27a (diff) |
Create admin function
-rw-r--r-- | admin.c | 30 | ||||
-rw-r--r-- | icclient/admin.h | 15 | ||||
-rw-r--r-- | main.c | 31 |
3 files changed, 46 insertions, 30 deletions
@@ -17,9 +17,31 @@ icclient_admin *icclient_admin_login(const char *username, const char *password, return admin; } -void icclient_admin_newitem(const char *description, const char *comment, const char *price, const char *image_path) +void icclient_admin_new_admin(const char *username, const char *password, const char *name, bool super, + enum icclient_admin_group group, void (*handler)(icclient_fetch_t *)) { - request(NULL, NULL, &(struct body){ 15, { + request(handler, NULL, &(struct body){ 13, { + { "mv_todo", "set" }, + { "mv_data_table", "access" }, + { "mv_data_key", "username" }, + { "mv_update_empty", "1" }, + { "mv_data_fields", "username password name super groups" }, + { "mv_click", "process_filter" }, + { "user_id", "NEW" }, + { "name", name }, + { "mv_data_function", "insert" }, + { "username", username }, + { "password", password }, + { "super", super ? "1" : "0" }, + { "groups", group == ICCLIENT_ADMIN_GROUP_CONTENT ? ":CONTENT" + : group == ICCLIENT_ADMIN_GROUP_MERCH ? ":MERCH" : ":ORDERS" } + }}, "%s", "ui"); +} + +void icclient_admin_new_item(const char *description, const char *comment, const char *price, const char *image_path, + void (*handler)(icclient_fetch_t *)) +{ + request(handler, NULL, &(struct body){ 15, { { "mv_click", "process_filter" }, { "mv_data_fields", "sku description prod_group category comment inactive price wholesale image thumb image_large weight nontaxable gift_cert" }, { "mv_ui", "1" }, @@ -45,9 +67,9 @@ void icclient_admin_newitem(const char *description, const char *comment, const }}, "%s", "admin/item_edit"); } -void icclient_admin_logout(icclient_admin *admin) +void icclient_admin_logout(icclient_admin *admin, void (*handler)(icclient_fetch_t *)) { - request(NULL, NULL, NULL, "%s", "admin/login"); + request(handler, NULL, NULL, "%s", "admin/login"); if (admin->name) free(admin->name); if (admin->username) diff --git a/icclient/admin.h b/icclient/admin.h index cfc89da..dad603d 100644 --- a/icclient/admin.h +++ b/icclient/admin.h @@ -6,6 +6,11 @@ struct icclient_admin { char *password; char *name; bool super; + enum icclient_admin_group { + ICCLIENT_ADMIN_GROUP_CONTENT, + ICCLIENT_ADMIN_GROUP_MERCH, + ICCLIENT_ADMIN_GROUP_ORDERS + } group; }; #ifdef __cplusplus @@ -16,12 +21,14 @@ extern "C" { const char *password, const char *successpage, const char *nextpage, const char *failpage, void (*handler)(icclient_fetch_t *)); - void icclient_admin_newitem(const char *description, const char *comment, - const char *price, const char *image_path); - void icclient_admin_logout(struct icclient_admin *admin); + void icclient_admin_new_admin(const char *username, const char *password, const char *name, bool super, + enum icclient_admin_group group, void (*handler)(icclient_fetch_t *)); + void icclient_admin_new_item(const char *description, const char *comment, const char *price, const char *image_path, + void (*handler)(icclient_fetch_t *)); + void icclient_admin_logout(struct icclient_admin *admin, void (*handler)(icclient_fetch_t *)); #ifdef __cplusplus } #endif -#endif // ICCLIENT_ADMIN_H +#endif @@ -4,6 +4,7 @@ #include <stdbool.h> #include "icclient.h" #include "icclient/member.h" +#include "icclient/admin.h" static void print_catalog(struct icclient_catalog *catalog) { @@ -23,36 +24,22 @@ static void print_catalog(struct icclient_catalog *catalog) } icclient_free_catalog(catalog); } -/* -static void print_user(icclient_fetch_t *fetch) + +static void print(icclient_fetch_t *fetch) { printf("%s\n", fetch->data); } -*/ + int main(int argc, char *argv[]) { icclient_init("https://demo.interchangecommerce.org/i/demo", "/demo/images", NULL); - icclient_allproducts(print_catalog, NULL); /* - char *name_line = NULL; - printf("\nName: "); - ssize_t name_nread = getline(&name_line, &(size_t){0}, stdin); - char *name = malloc(--name_nread + 1); - strncpy(name, name_line, name_nread); - free(name_line); - - char *pass_line = NULL; - printf("Pass: "); - ssize_t pass_nread = getline(&pass_line, &(size_t){0}, stdin); - char *pass = malloc(--pass_nread + 1); - strncpy(pass, pass_line, pass_nread); - free(pass_line); - pass[pass_nread] = '\0'; - - struct icclient_member *member = icclient_member_login(name, pass, NULL, NULL, NULL, print_user); - free(name); - free(pass); + icclient_allproducts(print_catalog, NULL); + struct icclient_member *member = icclient_member_login("kirk@icdevgroup.net", "kirk", NULL, NULL, NULL, print); icclient_member_logout(member); */ + struct icclient_admin *admin = icclient_admin_login("interch", "pass", NULL, NULL, NULL, NULL); + icclient_admin_new_admin("Hardware", "pass", "Hardware stuff", 0, ICCLIENT_ADMIN_GROUP_MERCH, NULL); + icclient_admin_logout(admin, NULL); icclient_cleanup(); } |