diff options
| author | 2022-10-02 17:34:27 +0200 | |
|---|---|---|
| committer | 2022-10-02 17:34:27 +0200 | |
| commit | bab25259f9316a765c3de8a1f5d7111accfdb004 (patch) | |
| tree | 8ee48b9ee4bd2559845ce3875fd0520756dc85a1 | |
| parent | Minor tweak. (diff) | |
| download | penes-snac2-bab25259f9316a765c3de8a1f5d7111accfdb004.tar.gz penes-snac2-bab25259f9316a765c3de8a1f5d7111accfdb004.tar.xz penes-snac2-bab25259f9316a765c3de8a1f5d7111accfdb004.zip | |
User data can be modified from the web interface.
| -rw-r--r-- | html.c | 35 |
1 files changed, 35 insertions, 0 deletions
| @@ -956,6 +956,41 @@ int html_post_handler(d_char *req, char *q_path, d_char *payload, int p_size, | |||
| 956 | else | 956 | else |
| 957 | if (p_path && strcmp(p_path, "admin/user-setup") == 0) { | 957 | if (p_path && strcmp(p_path, "admin/user-setup") == 0) { |
| 958 | /* change of user data */ | 958 | /* change of user data */ |
| 959 | char *v; | ||
| 960 | char *p1, *p2; | ||
| 961 | |||
| 962 | if ((v = xs_dict_get(p_vars, "name")) != NULL) | ||
| 963 | snac.config = xs_dict_set(snac.config, "name", v); | ||
| 964 | if ((v = xs_dict_get(p_vars, "avatar")) != NULL) | ||
| 965 | snac.config = xs_dict_set(snac.config, "avatar", v); | ||
| 966 | if ((v = xs_dict_get(p_vars, "bio")) != NULL) | ||
| 967 | snac.config = xs_dict_set(snac.config, "bio", v); | ||
| 968 | |||
| 969 | /* password change? */ | ||
| 970 | if ((p1 = xs_dict_get(p_vars, "passwd1")) != NULL && | ||
| 971 | (p2 = xs_dict_get(p_vars, "passwd2")) != NULL && | ||
| 972 | *p1 && strcmp(p1, p2) == 0) { | ||
| 973 | xs *pw = hash_password(snac.uid, p1, NULL); | ||
| 974 | snac.config = xs_dict_set(snac.config, "passwd", pw); | ||
| 975 | } | ||
| 976 | |||
| 977 | xs *fn = xs_fmt("%s/user.json", snac.basedir); | ||
| 978 | xs *bfn = xs_fmt("%s.bak", fn); | ||
| 979 | FILE *f; | ||
| 980 | |||
| 981 | rename(fn, bfn); | ||
| 982 | |||
| 983 | if ((f = fopen(fn, "w")) != NULL) { | ||
| 984 | xs *j = xs_json_dumps_pp(snac.config, 4); | ||
| 985 | fwrite(j, strlen(j), 1, f); | ||
| 986 | fclose(f); | ||
| 987 | } | ||
| 988 | else | ||
| 989 | rename(bfn, fn); | ||
| 990 | |||
| 991 | history_del(&snac, "_timeline.html"); | ||
| 992 | |||
| 993 | status = 303; | ||
| 959 | } | 994 | } |
| 960 | 995 | ||
| 961 | if (status == 303) { | 996 | if (status == 303) { |