You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

my_controller.rb 6.8 kB

13 years ago
13 years ago
​
​
​
​
​
​
​
​
​
​
13 years ago
13 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
12 years ago
12 years ago
​
​
​
​
​
​
​
​
​
​
13 years ago
​
​
​
13 years ago
12 years ago
​
13 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
13 years ago
13 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. # Redmine - project management software
  2. # Copyright (C) 2006-2013 Jean-Philippe Lang
  3. #
  4. # This program is free software; you can redistribute it and/or
  5. # modify it under the terms of the GNU General Public License
  6. # as published by the Free Software Foundation; either version 2
  7. # of the License, or (at your option) any later version.
  8. #
  9. # This program is distributed in the hope that it will be useful,
  10. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. # GNU General Public License for more details.
  13. #+
  14. # You should have received a copy of the GNU General Public License
  15. # along with this program; if not, write to the Free Software
  16. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  17. class MyController < ApplicationController
  18. before_filter :require_login
  19. helper :issues
  20. helper :users
  21. helper :custom_fields
  22. BLOCKS = { 'issuesassignedtome' => :label_assigned_to_me_issues,
  23. 'issuesreportedbyme' => :label_reported_issues,
  24. 'issueswatched' => :label_watched_issues,
  25. 'news' => :label_news_latest,
  26. 'calendar' => :label_calendar,
  27. 'documents' => :label_document_plural,
  28. 'timelog' => :label_spent_time
  29. }.merge(Redmine::Views::MyPage::Block.additional_blocks).freeze
  30. DEFAULT_LAYOUT = { 'left' => ['issuesassignedtome'],
  31. 'right' => ['issuesreportedbyme']
  32. }.freeze
  33. def index
  34. page
  35. render :action => 'page'
  36. end
  37. # Show user's page
  38. def page
  39. @user = User.current
  40. @blocks = @user.pref[:my_page_layout] || DEFAULT_LAYOUT
  41. end
  42. # Edit user's account
  43. def account
  44. @user = User.current
  45. @pref = @user.pref
  46. if request.post?
  47. @user.safe_attributes = params[:user]
  48. @user.pref.attributes = params[:pref]
  49. @user.pref[:no_self_notified] = (params[:no_self_notified] == '1')
  50. @user.login = params[:login]
  51. unless @user.user_extensions.nil?
  52. if @user.user_extensions.identity == 2
  53. @user.firstname = params[:enterprise_name]
  54. end
  55. end
  56. @se = @user.user_extensions ||= UserExtensions.new
  57. @se.school_id = params[:occupation] if params[:occupation]
  58. @se.gender = params[:gender]
  59. @se.location = params[:province] if params[:province]
  60. @se.location_city = params[:city] if params[:city]
  61. @se.identity = params[:identity].to_i if params[:identity]
  62. @se.technical_title = params[:technical_title] if params[:technical_title]
  63. @se.student_id = params[:no] if params[:no]
  64. if @user.save && @se.save
  65. @user.pref.save
  66. @user.notified_project_ids = (@user.mail_notification == 'selected' ? params[:notified_project_ids] : [])
  67. set_language_if_valid @user.language
  68. flash[:notice] = l(:notice_account_updated)
  69. redirect_to user_path(@user)
  70. return
  71. else
  72. @user
  73. end
  74. end
  75. end
  76. # Destroys user's account
  77. def destroy
  78. @user = User.current
  79. unless @user.own_account_deletable?
  80. redirect_to my_account_path
  81. return
  82. end
  83. if request.post? && params[:confirm]
  84. @user.destroy
  85. if @user.destroyed?
  86. logout_user
  87. flash[:notice] = l(:notice_account_deleted)
  88. end
  89. redirect_to home_path
  90. end
  91. end
  92. # Manage user's password
  93. def password
  94. @user = User.current
  95. unless @user.change_password_allowed?
  96. flash[:error] = l(:notice_can_t_change_password)
  97. redirect_to my_account_path
  98. return
  99. end
  100. if request.post?
  101. if @user.check_password?(params[:password])
  102. @user.password, @user.password_confirmation = params[:new_password], params[:new_password_confirmation]
  103. if @user.save
  104. flash[:notice] = l(:notice_account_password_updated)
  105. redirect_to my_account_path
  106. end
  107. else
  108. flash[:error] = l(:notice_account_wrong_password)
  109. end
  110. end
  111. end
  112. # Create a new feeds key
  113. def reset_rss_key
  114. if request.post?
  115. if User.current.rss_token
  116. User.current.rss_token.destroy
  117. User.current.reload
  118. end
  119. User.current.rss_key
  120. flash[:notice] = l(:notice_feeds_access_key_reseted)
  121. end
  122. redirect_to my_account_path
  123. end
  124. # Create a new API key
  125. def reset_api_key
  126. if request.post?
  127. if User.current.api_token
  128. User.current.api_token.destroy
  129. User.current.reload
  130. end
  131. User.current.api_key
  132. flash[:notice] = l(:notice_api_access_key_reseted)
  133. end
  134. redirect_to my_account_path
  135. end
  136. # User's page layout configuration
  137. def page_layout
  138. @user = User.current
  139. @blocks = @user.pref[:my_page_layout] || DEFAULT_LAYOUT.dup
  140. @block_options = []
  141. BLOCKS.each do |k, v|
  142. unless %w(top left right).detect {|f| (@blocks[f] ||= []).include?(k)}
  143. @block_options << [l("my.blocks.#{v}", :default => [v, v.to_s.humanize]), k.dasherize]
  144. end
  145. end
  146. end
  147. # Add a block to user's page
  148. # The block is added on top of the page
  149. # params[:block] : id of the block to add
  150. def add_block
  151. block = params[:block].to_s.underscore
  152. if block.present? && BLOCKS.key?(block)
  153. @user = User.current
  154. layout = @user.pref[:my_page_layout] || {}
  155. # remove if already present in a group
  156. %w(top left right).each {|f| (layout[f] ||= []).delete block }
  157. # add it on top
  158. layout['top'].unshift block
  159. @user.pref[:my_page_layout] = layout
  160. @user.pref.save
  161. end
  162. redirect_to my_page_layout_path
  163. end
  164. # Remove a block to user's page
  165. # params[:block] : id of the block to remove
  166. def remove_block
  167. block = params[:block].to_s.underscore
  168. @user = User.current
  169. # remove block in all groups
  170. layout = @user.pref[:my_page_layout] || {}
  171. %w(top left right).each {|f| (layout[f] ||= []).delete block }
  172. @user.pref[:my_page_layout] = layout
  173. @user.pref.save
  174. redirect_to my_page_layout_path
  175. end
  176. # Change blocks order on user's page
  177. # params[:group] : group to order (top, left or right)
  178. # params[:list-(top|left|right)] : array of block ids of the group
  179. def order_blocks
  180. group = params[:group]
  181. @user = User.current
  182. if group.is_a?(String)
  183. group_items = (params["blocks"] || []).collect(&:underscore)
  184. group_items.each {|s| s.sub!(/^block_/, '')}
  185. if group_items and group_items.is_a? Array
  186. layout = @user.pref[:my_page_layout] || {}
  187. # remove group blocks if they are presents in other groups
  188. %w(top left right).each {|f|
  189. layout[f] = (layout[f] || []) - group_items
  190. }
  191. layout[group] = group_items
  192. @user.pref[:my_page_layout] = layout
  193. @user.pref.save
  194. end
  195. end
  196. render :nothing => true
  197. end
  198. end

软件技术创新是当今国家整体创新能力的重要基础和发展引擎。近年来,大众参与的软件创新与创业活动已经成为网络时代软件开发和应用的新形态,正在快速改变着全球软件创新模式和软件产业格局。 ...