tazbug diff web/plugins/users/users.cgi @ rev 111
Backport users plugins from TinyCM
author | Christophe Lincoln <pankso@slitaz.org> |
---|---|
date | Fri Feb 10 23:43:16 2017 +0100 (2017-02-10) |
parents | 1a43d9e16913 |
children | c9939a4ea74c |
line diff
1.1 --- a/web/plugins/users/users.cgi Fri Feb 10 19:24:09 2017 +0100 1.2 +++ b/web/plugins/users/users.cgi Fri Feb 10 23:43:16 2017 +0100 1.3 @@ -3,6 +3,40 @@ 1.4 # TinyCM/TazBug Plugin - Users profile and admin 1.5 # 1.6 1.7 +# Display user public profile. 1.8 +public_people() { 1.9 + echo "</pre>" 1.10 + # Display personal user profile 1.11 + if [ -f "$PEOPLE/$USER/profile.txt" ]; then 1.12 + cat $PEOPLE/$USER/profile.txt | wiki_parser 1.13 + fi 1.14 +} 1.15 + 1.16 +# Display authenticated user profile. TODO: change password 1.17 +auth_people() { 1.18 + cat << EOT 1.19 +Email : $MAIL 1.20 +</pre> 1.21 +EOT 1.22 + # Each user can have personal profile page 1.23 + if [ -f "$PEOPLE/$USER/profile.txt" ]; then 1.24 + cat $PEOPLE/$USER/profile.txt | wiki_parser 1.25 + cat << EOT 1.26 +<div id="tools"> 1.27 + <a href="$script?modprofile">$(gettext "Modify profile")</a> 1.28 + <a href="$script?dashboard">Dashboard</a> 1.29 +</div> 1.30 +EOT 1.31 + else 1.32 + cat << EOT 1.33 +<div id="tools"> 1.34 + <a href="$script?modprofile">$(gettext "Create a profile page")</a> 1.35 + <a href="$script?dashboard">Dashboard</a> 1.36 +</div> 1.37 +EOT 1.38 + fi 1.39 +} 1.40 + 1.41 case " $(GET) " in 1.42 *\ users\ *) 1.43 d="Users" 1.44 @@ -66,4 +100,72 @@ 1.45 done 1.46 echo "</pre>" 1.47 html_footer && exit 0 ;; 1.48 + 1.49 + *\ user\ *) 1.50 + # User profile page 1.51 + d="$(GET user)" 1.52 + last="$(cat $PEOPLE/"$(GET user)"/last)" 1.53 + header 1.54 + html_header 1.55 + user_box 1.56 + . $PEOPLE/"$(GET user)"/account.conf 1.57 +cat << EOT 1.58 +<h2>$(get_gravatar $MAIL) $NAME</h2> 1.59 + 1.60 +<pre> 1.61 +$(gettext "User name :") $USER 1.62 +$(gettext "Last login :") $last 1.63 +EOT 1.64 + if check_auth && [ "$(GET user)" == "$user" ]; then 1.65 + auth_people 1.66 + else 1.67 + # check_auth will set VARS to current logged user: re-source 1.68 + . $PEOPLE/"$(GET user)"/account.conf 1.69 + public_people 1.70 + fi 1.71 + html_footer && exit 0 ;; 1.72 + 1.73 + *\ modprofile\ *) 1.74 + # Let user edit there profile 1.75 + if ! check_auth; then 1.76 + echo "ERROR" && exit 0 1.77 + fi 1.78 + d="$user profile" 1.79 + path=${PEOPLE}/${user} 1.80 + header 1.81 + html_header 1.82 + user_box 1.83 + cat << EOT 1.84 +<h2>$(gettext "User:") $user</h2> 1.85 +<p>$(gettext "Modify your profile settings") 1.86 +<div id="edit"> 1.87 + 1.88 +<form method="get" action="$script" name="editor"> 1.89 + <input type="hidden" name="saveprofile" /> 1.90 + <h3>Name</h3> 1.91 + <input type="text" name="name" value="$NAME" /> 1.92 + <h3>Email</h3> 1.93 + <input type="text" name="mail" value="$MAIL" /> 1.94 + <h3>About you</h3> 1.95 + <textarea name="profile">$(cat "$path/profile.txt")</textarea> 1.96 + <input type="submit" value="$(gettext "Save profile")" /> 1.97 +</form> 1.98 + 1.99 +</div> 1.100 +EOT 1.101 + html_footer && exit 0 ;; 1.102 + 1.103 + *\ saveprofile\ *) 1.104 + # Save a user profile 1.105 + if check_auth; then 1.106 + path="$PEOPLE/$user" 1.107 + sed -i s"/^NAME=.*/NAME=\"$(GET name)\"/" ${path}/account.conf 1.108 + sed -i s"/^MAIL=.*/MAIL=\"$(GET mail)\"/" ${path}/account.conf 1.109 + cp -f ${path}/profile.txt ${path}/profile.bak 1.110 + sed "s/$(echo -en '\r') /\n/g" > ${path}/profile.txt << EOT 1.111 +$(GET profile) 1.112 +EOT 1.113 + header "Location: $script?user=$user" 1.114 + fi && exit 0 ;; 1.115 + 1.116 esac