tinycm rev 76

Move user profile stuff to plugin and improve user functions
author Christophe Lincoln <pankso@slitaz.org>
date Fri Feb 10 22:53:14 2017 +0100 (2017-02-10)
parents 33e6a5c881ec
children 4e8dfb19f2a7
files index.cgi plugins/users/users.cgi
line diff
     1.1 --- a/index.cgi	Fri Feb 10 20:32:34 2017 +0100
     1.2 +++ b/index.cgi	Fri Feb 10 22:53:14 2017 +0100
     1.3 @@ -2,7 +2,7 @@
     1.4  #
     1.5  # TinyCM - Small, fast and elegant CGI/SHell Content Manager
     1.6  #
     1.7 -# Copyright (C) 2012-2014 SliTaz GNU/Linux - BSD License
     1.8 +# Copyright (C) 2012-2017 SliTaz GNU/Linux - BSD License
     1.9  #
    1.10  . /usr/lib/slitaz/httphelper
    1.11  
    1.12 @@ -267,41 +267,6 @@
    1.13  	fi
    1.14  }
    1.15  
    1.16 -# Display user public profile.
    1.17 -public_people() {
    1.18 -	echo "</pre>"
    1.19 -	# Display personal user profile
    1.20 -	if [ -f "$PEOPLE/$USER/profile.txt" ]; then
    1.21 -		cat $PEOPLE/$USER/profile.txt | wiki_parser
    1.22 -	fi
    1.23 -}
    1.24 -
    1.25 -# Display authenticated user profile. TODO: change password
    1.26 -auth_people() {
    1.27 -	cat << EOT
    1.28 -Email      : $MAIL
    1.29 -Secure key : $KEY
    1.30 -</pre>
    1.31 -EOT
    1.32 -	# Each user can have personal profile page
    1.33 -	if [ -f "$PEOPLE/$USER/profile.txt" ]; then
    1.34 -		cat $PEOPLE/$USER/profile.txt | wiki_parser
    1.35 -		cat << EOT
    1.36 -<div id="tools">
    1.37 -	<a href="$script?edit=profile">$(gettext "Edit profile")</a>
    1.38 -	<a href="$script?dashboard">Dashboard</a>
    1.39 -</div>
    1.40 -EOT
    1.41 -	else
    1.42 -		cat << EOT
    1.43 -<div id="tools">
    1.44 -	<a href="$script?edit=profile">$(gettext "Create a profile page")</a>
    1.45 -	<a href="$script?dashboard">Dashboard</a>
    1.46 -</div>
    1.47 -EOT
    1.48 -	fi
    1.49 -}
    1.50 -
    1.51  # The CM style parser. Just a title, simple text formatting and internal
    1.52  # links, as well as images and use HTML for other stuff. Keep it fast!
    1.53  # To make TinyCM as easy as possible we have a small HTML editor/helper
    1.54 @@ -358,15 +323,6 @@
    1.55  	fi
    1.56  }
    1.57  
    1.58 -# Save a user profile.
    1.59 -save_profile() {
    1.60 -	path="$PEOPLE/$user"
    1.61 -	cp -f ${path}/${d}.txt ${path}/${d}.bak
    1.62 -	sed "s/$(echo -en '\r') /\n/g" > ${path}/${d}.txt << EOT
    1.63 -$(GET content)
    1.64 -EOT
    1.65 -}
    1.66 -
    1.67  # CM tools (edit, diff, etc) for auth users
    1.68  wiki_tools() {
    1.69  	if check_auth; then
    1.70 @@ -483,9 +439,6 @@
    1.71  		get_lang
    1.72  		wiki_tools
    1.73  		if check_auth; then
    1.74 -			if [ "$doc" == "profile" ]; then
    1.75 -				wiki="$PEOPLE/$user"
    1.76 -			fi
    1.77  			cat << EOT
    1.78  <h2>$(gettext "Edit $doc [ $i18n ]")</h2>
    1.79  
    1.80 @@ -509,13 +462,7 @@
    1.81  	*\ save\ *)
    1.82  		d="$(GET save)"
    1.83  		if check_auth; then
    1.84 -			# User profile
    1.85 -			if [ "$d" == "profile" ]; then
    1.86 -				save_profile
    1.87 -				header "Location: $script?user=$user"
    1.88 -			else
    1.89 -				save_document
    1.90 -			fi
    1.91 +			save_document
    1.92  		fi 
    1.93  		header "Location: $script?d=$d" ;;
    1.94  		
    1.95 @@ -647,7 +594,7 @@
    1.96  		fi ;;
    1.97  		
    1.98  	*\ user\ *)
    1.99 -		# User profile
   1.100 +		# Basic user profile. Use the users plugin for more functions
   1.101  		d="$(GET user)"
   1.102  		last="$(cat $PEOPLE/"$(GET user)"/last)"
   1.103  		header
   1.104 @@ -660,14 +607,8 @@
   1.105  <pre>
   1.106  $(gettext "User name  :") $USER
   1.107  $(gettext "Last login :") $last
   1.108 +</pre>
   1.109  EOT
   1.110 -		if check_auth && [ "$(GET user)" == "$user" ]; then
   1.111 -			auth_people
   1.112 -		else
   1.113 -			# check_auth will set VARS to current logged user: re-source
   1.114 -			. $PEOPLE/"$(GET user)"/account.conf
   1.115 -			public_people
   1.116 -		fi
   1.117  		html_footer ;;
   1.118  		
   1.119  	*\ hg\ *)
     2.1 --- a/plugins/users/users.cgi	Fri Feb 10 20:32:34 2017 +0100
     2.2 +++ b/plugins/users/users.cgi	Fri Feb 10 22:53:14 2017 +0100
     2.3 @@ -3,6 +3,40 @@
     2.4  # TinyCM/TazBug Plugin - Users profile and admin
     2.5  #
     2.6  
     2.7 +# Display user public profile.
     2.8 +public_people() {
     2.9 +	echo "</pre>"
    2.10 +	# Display personal user profile
    2.11 +	if [ -f "$PEOPLE/$USER/profile.txt" ]; then
    2.12 +		cat $PEOPLE/$USER/profile.txt | wiki_parser
    2.13 +	fi
    2.14 +}
    2.15 +
    2.16 +# Display authenticated user profile. TODO: change password
    2.17 +auth_people() {
    2.18 +	cat << EOT
    2.19 +Email      : $MAIL
    2.20 +</pre>
    2.21 +EOT
    2.22 +	# Each user can have personal profile page
    2.23 +	if [ -f "$PEOPLE/$USER/profile.txt" ]; then
    2.24 +		cat $PEOPLE/$USER/profile.txt | wiki_parser
    2.25 +		cat << EOT
    2.26 +<div id="tools">
    2.27 +	<a href="$script?edit-profile">$(gettext "Edit profile")</a>
    2.28 +	<a href="$script?dashboard">Dashboard</a>
    2.29 +</div>
    2.30 +EOT
    2.31 +	else
    2.32 +		cat << EOT
    2.33 +<div id="tools">
    2.34 +	<a href="$script?edit-profile">$(gettext "Create a profile page")</a>
    2.35 +	<a href="$script?dashboard">Dashboard</a>
    2.36 +</div>
    2.37 +EOT
    2.38 +	fi
    2.39 +}
    2.40 +
    2.41  case " $(GET) " in
    2.42  	*\ users\ *)
    2.43  		d="Users"
    2.44 @@ -66,4 +100,72 @@
    2.45  		done
    2.46  		echo "</pre>"
    2.47  		html_footer && exit 0 ;;
    2.48 +		
    2.49 +	*\ user\ *)
    2.50 +		# User profile page
    2.51 +		d="$(GET user)"
    2.52 +		last="$(cat $PEOPLE/"$(GET user)"/last)"
    2.53 +		header
    2.54 +		html_header
    2.55 +		user_box
    2.56 +		. $PEOPLE/"$(GET user)"/account.conf
    2.57 +cat << EOT
    2.58 +<h2>$(get_gravatar $MAIL) $NAME</h2>
    2.59 +
    2.60 +<pre>
    2.61 +$(gettext "User name  :") $USER
    2.62 +$(gettext "Last login :") $last
    2.63 +EOT
    2.64 +		if check_auth && [ "$(GET user)" == "$user" ]; then
    2.65 +			auth_people
    2.66 +		else
    2.67 +			# check_auth will set VARS to current logged user: re-source
    2.68 +			. $PEOPLE/"$(GET user)"/account.conf
    2.69 +			public_people
    2.70 +		fi
    2.71 +		html_footer && exit 0 ;;
    2.72 +		
    2.73 +	*\ edit-profile\ *)
    2.74 +		# Let user edit there profile
    2.75 +		if ! check_auth; then
    2.76 +			echo "ERROR" && exit 0
    2.77 +		fi
    2.78 +		d="$user profile"
    2.79 +		path=${PEOPLE}/${user}
    2.80 +		header
    2.81 +		html_header
    2.82 +		user_box
    2.83 +		cat << EOT
    2.84 +<h2>$(gettext "Edit profile [ $user ]")</h2>
    2.85 +<p>$(gettext "Edit your profile settings")
    2.86 +<div id="edit">
    2.87 +
    2.88 +<form method="get" action="$script" name="editor">
    2.89 +	<input type="hidden" name="save-profile" />
    2.90 +	<h3>Name</h3>
    2.91 +	<input type="text" name="name" value="$NAME" />
    2.92 +	<h3>Email</h3>
    2.93 +	<input type="text" name="mail" value="$MAIL" />
    2.94 +	<h3>About you</h3>
    2.95 +	<textarea name="profile">$(cat "$path/profile.txt")</textarea>
    2.96 +	<input type="submit" value="$(gettext "Save profile")" />
    2.97 +</form>
    2.98 +
    2.99 +</div>
   2.100 +EOT
   2.101 +		html_footer && exit 0 ;;
   2.102 +	
   2.103 +	*\ save-profile\ *)
   2.104 +		# Save a user profile
   2.105 +		if check_auth; then
   2.106 +			path="$PEOPLE/$user"
   2.107 +			sed -i s"/^NAME=.*/NAME=\"$(GET name)\"/" ${path}/account.conf
   2.108 +			sed -i s"/^MAIL=.*/MAIL=\"$(GET mail)\"/" ${path}/account.conf
   2.109 +			cp -f ${path}/profile.txt ${path}/profile.bak
   2.110 +			sed "s/$(echo -en '\r') /\n/g" > ${path}/profile.txt << EOT
   2.111 +$(GET profile)
   2.112 +EOT
   2.113 +			header "Location: $script?user=$user"
   2.114 +		fi && exit 0 ;;
   2.115 +	
   2.116  esac