# HG changeset patch # User Christophe Lincoln # Date 1486763594 -3600 # Node ID e3cba575c564f5c216e441afecb95995dd3d7189 # Parent 33e6a5c881ec0cf3d113281d1a49c64cc43af88d Move user profile stuff to plugin and improve user functions diff -r 33e6a5c881ec -r e3cba575c564 index.cgi --- a/index.cgi Fri Feb 10 20:32:34 2017 +0100 +++ b/index.cgi Fri Feb 10 22:53:14 2017 +0100 @@ -2,7 +2,7 @@ # # TinyCM - Small, fast and elegant CGI/SHell Content Manager # -# Copyright (C) 2012-2014 SliTaz GNU/Linux - BSD License +# Copyright (C) 2012-2017 SliTaz GNU/Linux - BSD License # . /usr/lib/slitaz/httphelper @@ -267,41 +267,6 @@ fi } -# Display user public profile. -public_people() { - echo "" - # Display personal user profile - if [ -f "$PEOPLE/$USER/profile.txt" ]; then - cat $PEOPLE/$USER/profile.txt | wiki_parser - fi -} - -# Display authenticated user profile. TODO: change password -auth_people() { - cat << EOT -Email : $MAIL -Secure key : $KEY - -EOT - # Each user can have personal profile page - if [ -f "$PEOPLE/$USER/profile.txt" ]; then - cat $PEOPLE/$USER/profile.txt | wiki_parser - cat << EOT -
- $(gettext "Edit profile") - Dashboard -
-EOT - else - cat << EOT -
- $(gettext "Create a profile page") - Dashboard -
-EOT - fi -} - # The CM style parser. Just a title, simple text formatting and internal # links, as well as images and use HTML for other stuff. Keep it fast! # To make TinyCM as easy as possible we have a small HTML editor/helper @@ -358,15 +323,6 @@ fi } -# Save a user profile. -save_profile() { - path="$PEOPLE/$user" - cp -f ${path}/${d}.txt ${path}/${d}.bak - sed "s/$(echo -en '\r') /\n/g" > ${path}/${d}.txt << EOT -$(GET content) -EOT -} - # CM tools (edit, diff, etc) for auth users wiki_tools() { if check_auth; then @@ -483,9 +439,6 @@ get_lang wiki_tools if check_auth; then - if [ "$doc" == "profile" ]; then - wiki="$PEOPLE/$user" - fi cat << EOT

$(gettext "Edit $doc [ $i18n ]")

@@ -509,13 +462,7 @@ *\ save\ *) d="$(GET save)" if check_auth; then - # User profile - if [ "$d" == "profile" ]; then - save_profile - header "Location: $script?user=$user" - else - save_document - fi + save_document fi header "Location: $script?d=$d" ;; @@ -647,7 +594,7 @@ fi ;; *\ user\ *) - # User profile + # Basic user profile. Use the users plugin for more functions d="$(GET user)" last="$(cat $PEOPLE/"$(GET user)"/last)" header @@ -660,14 +607,8 @@
 $(gettext "User name  :") $USER
 $(gettext "Last login :") $last
+
EOT - if check_auth && [ "$(GET user)" == "$user" ]; then - auth_people - else - # check_auth will set VARS to current logged user: re-source - . $PEOPLE/"$(GET user)"/account.conf - public_people - fi html_footer ;; *\ hg\ *) diff -r 33e6a5c881ec -r e3cba575c564 plugins/users/users.cgi --- a/plugins/users/users.cgi Fri Feb 10 20:32:34 2017 +0100 +++ b/plugins/users/users.cgi Fri Feb 10 22:53:14 2017 +0100 @@ -3,6 +3,40 @@ # TinyCM/TazBug Plugin - Users profile and admin # +# Display user public profile. +public_people() { + echo "" + # Display personal user profile + if [ -f "$PEOPLE/$USER/profile.txt" ]; then + cat $PEOPLE/$USER/profile.txt | wiki_parser + fi +} + +# Display authenticated user profile. TODO: change password +auth_people() { + cat << EOT +Email : $MAIL + +EOT + # Each user can have personal profile page + if [ -f "$PEOPLE/$USER/profile.txt" ]; then + cat $PEOPLE/$USER/profile.txt | wiki_parser + cat << EOT +
+ $(gettext "Edit profile") + Dashboard +
+EOT + else + cat << EOT +
+ $(gettext "Create a profile page") + Dashboard +
+EOT + fi +} + case " $(GET) " in *\ users\ *) d="Users" @@ -66,4 +100,72 @@ done echo "" html_footer && exit 0 ;; + + *\ user\ *) + # User profile page + d="$(GET user)" + last="$(cat $PEOPLE/"$(GET user)"/last)" + header + html_header + user_box + . $PEOPLE/"$(GET user)"/account.conf +cat << EOT +

$(get_gravatar $MAIL) $NAME

+ +
+$(gettext "User name  :") $USER
+$(gettext "Last login :") $last
+EOT
+		if check_auth && [ "$(GET user)" == "$user" ]; then
+			auth_people
+		else
+			# check_auth will set VARS to current logged user: re-source
+			. $PEOPLE/"$(GET user)"/account.conf
+			public_people
+		fi
+		html_footer && exit 0 ;;
+		
+	*\ edit-profile\ *)
+		# Let user edit there profile
+		if ! check_auth; then
+			echo "ERROR" && exit 0
+		fi
+		d="$user profile"
+		path=${PEOPLE}/${user}
+		header
+		html_header
+		user_box
+		cat << EOT
+

$(gettext "Edit profile [ $user ]")

+

$(gettext "Edit your profile settings") +

+ +
+ +

Name

+ +

Email

+ +

About you

+ + +
+ +
+EOT + html_footer && exit 0 ;; + + *\ save-profile\ *) + # Save a user profile + if check_auth; then + path="$PEOPLE/$user" + sed -i s"/^NAME=.*/NAME=\"$(GET name)\"/" ${path}/account.conf + sed -i s"/^MAIL=.*/MAIL=\"$(GET mail)\"/" ${path}/account.conf + cp -f ${path}/profile.txt ${path}/profile.bak + sed "s/$(echo -en '\r') /\n/g" > ${path}/profile.txt << EOT +$(GET profile) +EOT + header "Location: $script?user=$user" + fi && exit 0 ;; + esac