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.

users_controller.rb 24 kB

13 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
13 years ago
​
13 years ago
13 years ago
​
13 years ago
​
13 years ago
​
13 years ago
13 years ago
​
​
​
​
13 years ago
​
​
​
​
​
​
​
​
​
​
12 years ago
​
​
​
13 years ago
13 years ago
13 years ago
​
​
​
​
13 years ago
​
​
​
​
13 years ago
13 years ago
​
​
13 years ago
13 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
13 years ago
​
​
​
​
​
​
13 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
12 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
12 years ago
​
​
12 years ago
12 years ago
​
12 years ago
​
12 years ago
​
12 years ago
​
​
​
​
13 years ago
​
​
​
​
​
13 years ago
​
13 years ago
13 years ago
13 years ago
​
13 years ago
​
​
​
​
13 years ago
13 years ago
13 years ago
​
​
​
​
​
​
13 years ago
​
​
​
​
​
​
​
​
13 years ago
13 years ago
13 years ago
​
​
13 years ago
​
13 years ago
​
13 years ago
13 years ago
​
​
​
​
13 years ago
​
​
​
​
​
​
​
​
​
​
​
​
13 years ago
​
​
​
​
13 years ago
​
​
13 years ago
​
​
​
​
​
​
​
​
​
​
​
13 years ago
13 years ago
​
​
13 years ago
13 years ago
​
​
​
​
13 years ago
13 years ago
​
​
​
​
​
​
​
​
​
​
​
13 years ago
​
​
​
​
​
​
​
13 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
13 years ago
13 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
13 years ago
13 years ago
​
​
​
​
​
13 years ago
​
​
​
​
​
​
​
​
13 years ago
13 years ago
​
​
13 years ago
​
13 years ago
13 years ago
​
​
13 years ago
13 years ago
13 years ago
​
​
​
​
​
​
​
​
​
​
13 years ago
​
13 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
13 years ago
13 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
13 years ago
​
​
13 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
13 years ago
​
​
​
​
​
​
13 years ago
​
​
​
​
​
13 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
13 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
13 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
13 years ago
​
​
13 years ago
​
​
13 years ago
​
​
​
​
​
​
​
​
​
13 years ago
13 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
13 years ago
​
​
​
​
​
​
​
​
​
​
13 years ago
​
​
13 years ago
​
​
​
13 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799
  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 UsersController < ApplicationController
  18. layout :setting_layout
  19. #Added by young
  20. menu_item :activity
  21. menu_item :user_information, :only => :info
  22. menu_item :user_course, :only => :user_courses
  23. menu_item :user_homework, :only => :user_homeworks
  24. menu_item :user_project, :only => [:user_projects, :watch_projects]
  25. menu_item :requirement_focus, :only => :watch_bids
  26. menu_item :requirement_focus, :only => :watch_contests
  27. menu_item :user_newfeedback, :only => :user_newfeedback
  28. #Ended by young
  29. before_filter :require_admin, :except => [:show, :index, :search, :tag_save, :tag_saveEx,:user_projects, :user_newfeedback, :user_comments, :watch_bids, :watch_contests, :info,
  30. :user_watchlist, :user_fanslist,:update, :user_courses, :user_homeworks, :watch_projects, :show_score, :topic_score_index, :project_score_index,
  31. :activity_score_index, :influence_score_index, :score_index]
  32. #edit has been deleted by huang, 2013-9-23
  33. before_filter :find_user, :only => [:user_fanslist, :user_watchlist, :show, :edit, :update, :destroy, :edit_membership, :user_courses,
  34. :user_homeworks, :destroy_membership, :user_activities, :user_projects, :user_newfeedback, :user_comments,
  35. :watch_bids, :watch_contests, :info, :watch_projects, :show_score, :topic_score_index, :project_score_index,
  36. :activity_score_index, :influence_score_index, :score_index]
  37. before_filter :auth_user_extension, only: :show
  38. accept_api_auth :index, :show, :create, :update, :destroy,:tag_save , :tag_saveEx
  39. #william
  40. before_filter :require_login, :only => [:tag_save,:tag_saveEx]
  41. helper :sort
  42. include SortHelper
  43. helper :custom_fields
  44. include CustomFieldsHelper
  45. include AvatarHelper
  46. # added by liuping 关注
  47. helper :watchers
  48. helper :activities
  49. ### added by william
  50. include ActsAsTaggableOn::TagsHelper
  51. # fq
  52. helper :words
  53. #added by young
  54. def user_projects
  55. if User.current.admin?
  56. @memberships = @user.memberships.all(conditions: "projects.project_type = #{Project::ProjectType_project}")
  57. else
  58. cond = Project.visible_condition(User.current) + " AND projects.project_type <> 1"
  59. @memberships = @user.memberships.all(:conditions => cond)
  60. end
  61. #events = Redmine::Activity::Fetcher.new(User.current, :author => @user).events(nil, nil, :limit => 20)
  62. #@events_by_day = events.group_by(&:event_date)
  63. @state = 0
  64. #add by huang
  65. unless User.current.admin?
  66. if !@user.active? #|| (@user != User.current && @memberships.empty? && events.empty?)
  67. render_404
  68. return
  69. end
  70. end
  71. #end
  72. respond_to do |format|
  73. format.html
  74. format.api
  75. end
  76. end
  77. # added by bai
  78. def show_score
  79. end
  80. # end
  81. ##added by fq
  82. def watch_bids
  83. cond = 'bids.reward_type <> 1'
  84. @bids = Bid.watched_by(@user).where('reward_type = ?', 1) # added by huang
  85. @offset, @limit = api_offset_and_limit({:limit => 10})
  86. @bid_count = @bids.count
  87. @bid_pages = Paginator.new @bid_count, @limit, params['page']
  88. @offset ||= @bid_pages.reverse_offset
  89. unless @offset == 0
  90. @bid = @bids.offset(@offset).limit(@limit).all.reverse
  91. else
  92. limit = @bid_count % @limit
  93. @bid = @bids.offset(@offset).limit(limit).all.reverse
  94. end
  95. respond_to do |format|
  96. format.html {
  97. render :layout => 'base_users'
  98. }
  99. format.api
  100. end
  101. end
  102. #new add by linchun
  103. def watch_contests
  104. @bids = Contest.watched_by(@user)
  105. @offset, @limit = api_offset_and_limit({:limit => 10})
  106. @contest_count = @contests.count
  107. @contest_pages = Paginator.new @contest_count, @limit, params['page']
  108. @offset ||= @contest_pages.reverse_offset
  109. unless @offset == 0
  110. @contest = @contests.offset(@offset).limit(@limit).all.reverse
  111. else
  112. limit = @bid_count % @limit
  113. @contest = @contests.offset(@offset).limit(limit).all.reverse
  114. end
  115. respond_to do |format|
  116. format.html {
  117. render :layout => 'base_users'
  118. }
  119. format.api
  120. end
  121. end
  122. # added by fq
  123. def user_activities
  124. @watcher = User.watched_by_id(@user)
  125. events = []
  126. for user in @watcher
  127. events << Redmine::Activity::Fetcher.new(User.current, :author => @user).events(nil, nil, :limit => 30)
  128. end
  129. @events_by_day = events.group_by(&:event_date)
  130. unless User.current.admin?
  131. if !@user.active? || (@user != User.current && @memberships.empty? && events.empty?)
  132. render_404
  133. return
  134. end
  135. end
  136. respond_to do |format|
  137. format.html
  138. format.api
  139. end
  140. end
  141. # end
  142. # added by huang
  143. def user_homeworks
  144. @membership = @user.memberships.all(:conditions => Project.visible_condition(User.current))
  145. @memberships = []
  146. @membership.each do |membership|
  147. if membership.project.project_type == 1
  148. @memberships << membership
  149. end
  150. end
  151. @bid = []
  152. @memberships.each do |membership|
  153. @bid += membership.project.homeworks
  154. end
  155. @bid = @bid.group_by {|bid| bid.courses.first.id}
  156. unless User.current.admin?
  157. if !@user.active?
  158. render_404
  159. return
  160. end
  161. end
  162. end
  163. include CoursesHelper
  164. def user_courses
  165. unless User.current.admin?
  166. if !@user.active? #|| (@user != User.current && @memberships.empty? && events.empty?)
  167. render_404
  168. return
  169. end
  170. end
  171. membership = @user.coursememberships.all#@user.coursememberships.all(:conditions => Course.visible_condition(User.current))
  172. membership.sort! {|older, newer| newer.created_on <=> older.created_on }
  173. @memberships = []
  174. membership.collect { |e|
  175. @memberships.push(e)
  176. }
  177. ## 判断课程是否过期 [需封装]
  178. @memberships_doing = []
  179. @memberships_done = []
  180. now_time = Time.now.year
  181. @memberships.map { |e|
  182. end_time = e.course.get_time.year
  183. isDone = course_endTime_timeout?(e.course)
  184. if isDone
  185. @memberships_done.push e
  186. else
  187. @memberships_doing.push e
  188. end
  189. }
  190. # respond_to do |format|
  191. # format.html
  192. # format.api
  193. # end
  194. end
  195. # modified by fq
  196. def user_newfeedback
  197. @jours = @user.journals_for_messages.where('m_parent_id IS NULL').order('created_on DESC')
  198. @jours.update_all(:is_readed => true, :status => false)
  199. @limit = 10
  200. @feedback_count = @jours.count
  201. @feedback_pages = Paginator.new @feedback_count, @limit, params['page']
  202. @offset ||= @feedback_pages.offset
  203. @jour = @jours[@offset, @limit]
  204. @state = false
  205. end
  206. # end
  207. def user_comments
  208. end
  209. #end
  210. def index
  211. @project_type = params[:project_type]
  212. role = params[:role]
  213. sort_init 'login', 'asc'
  214. sort_update %w(login firstname lastname mail admin created_on last_login_on)
  215. case params[:format]
  216. when 'xml', 'json'
  217. @offset, @limit = api_offset_and_limit({:limit => 15})
  218. else
  219. @limit = 15#per_page_option
  220. end
  221. @status = params[:status] || 1
  222. has = {
  223. "show_changesets" => true
  224. }
  225. # @count = Redmine::Activity::Fetcher.new(User.current, :author => @user).scope_select {|t| !has["show_#{t}"].nil?}.events(nil, nil).count
  226. scope = UserStatus.visible
  227. case role
  228. when 'teacher'
  229. scope = UserStatus.teacher
  230. when 'student'
  231. scope = UserStatus.student
  232. else
  233. end
  234. scope = scope.in_group(params[:group_id]) if params[:group_id].present?
  235. # scope.each do |user|
  236. # UserStatus.create(:changesets_count => user.changesets.count, :watchers_count => user.watcher_users.count, :user_id => user.id)
  237. # end
  238. @user_count = scope.count
  239. @user_pages = Paginator.new @user_count, @limit, params['page']
  240. #@offset ||= @user_pages.offset
  241. #@users = scope.order(sort_clause).limit(@limit).offset(@offset).all
  242. @user_base_tag = params[:id] ? 'base_users':'base'
  243. if params[:user_sort_type].present?
  244. case params[:user_sort_type]
  245. when '0'
  246. @offset ||= @user_pages.reverse_offset
  247. unless @offset == 0
  248. @users_statuses = scope.offset(@offset).limit(@limit).all.reverse
  249. else
  250. limit = @user_count % @limit
  251. if limit == 0
  252. limit = @limit
  253. end
  254. @users_statuses = scope.offset(@offset).limit(limit).all.reverse
  255. end
  256. @s_type = 0
  257. # @projects = @projects.sort {|x,y| y.created_on <=> x.created_on }
  258. # @projects = @projects[@offset, @limit]
  259. when '1'
  260. @offset ||= @user_pages.reverse_offset
  261. unless @offset == 0
  262. @users_statuses = scope.reorder('grade').offset(@offset).limit(@limit).all.reverse
  263. else
  264. limit = @user_count % @limit
  265. if limit == 0
  266. limit = @limit
  267. end
  268. @users_statuses = scope.reorder('grade').offset(@offset).limit(limit).all.reverse
  269. end
  270. @s_type = 1
  271. #sort {|x,y| y.user_status.changesets_count <=> x.user_status.changesets_count}
  272. #@users = @users[@offset, @limit]
  273. when '2'
  274. @offset ||= @user_pages.reverse_offset
  275. unless @offset == 0
  276. @users_statuses = scope.reorder('watchers_count').offset(@offset).limit(@limit).all.reverse
  277. else
  278. limit = @user_count % @limit
  279. if limit == 0
  280. limit = @limit
  281. end
  282. @users_statuses = scope.reorder('watchers_count').offset(@offset).limit(limit).all.reverse
  283. end
  284. @s_type = 2
  285. #@users = @users[@offset, @limit]
  286. end
  287. else
  288. @offset ||= @user_pages.reverse_offset
  289. unless @offset == 0
  290. @users_statuses = scope.reorder('grade').offset(@offset).limit(@limit).all.reverse
  291. else
  292. limit = @user_count % @limit
  293. if limit == 0
  294. limit = @limit
  295. end
  296. @users_statuses = scope.reorder('grade').offset(@offset).limit(limit).all.reverse
  297. end
  298. @s_type = 1
  299. # @projects = @projects.sort {|x,y| y.created_on <=> x.created_on }
  300. # @projects = @projects[@offset, @limit]
  301. end
  302. @users = []
  303. @users_statuses.each do |obj|
  304. @users << User.find_by_id("#{obj.user_id}")
  305. end
  306. respond_to do |format|
  307. format.html {
  308. @groups = Group.all.sort
  309. render :layout => @user_base_tag
  310. }
  311. format.api
  312. end
  313. end
  314. def search
  315. sort_init 'login', 'asc'
  316. sort_update %w(login firstname lastname mail admin created_on last_login_on)
  317. case params[:format]
  318. when 'xml', 'json'
  319. @offset, @limit = api_offset_and_limit({:limit => 15})
  320. else
  321. @limit = 15#per_page_option
  322. end
  323. @status = params[:status] || 1
  324. has = {
  325. "show_changesets" => true
  326. }
  327. scope = User.logged.status(@status)
  328. scope = scope.like(params[:name]) if params[:name].present?
  329. @user_count = scope.count
  330. @user_pages = Paginator.new @user_count, @limit, params['page']
  331. @user_base_tag = params[:id] ? 'base_users':'base'
  332. @offset ||= @user_pages.reverse_offset
  333. unless @offset == 0
  334. @users = scope.offset(@offset).limit(@limit).all.reverse
  335. else
  336. limit = @user_count % @limit
  337. if limit == 0
  338. limit = @limit
  339. end
  340. @users = scope.offset(@offset).limit(limit).all.reverse
  341. end
  342. respond_to do |format|
  343. format.html {
  344. @groups = Group.all.sort
  345. render :layout => @user_base_tag
  346. }
  347. format.api
  348. end
  349. end
  350. def show
  351. pre_count = 10 #limit
  352. case params[:type]
  353. when "1"
  354. if @user == User.current
  355. activity = Activity.where('user_id = ?', User.current.id).order('id desc')
  356. @activity_count = activity.count
  357. @activity_pages = Paginator.new @activity_count, pre_count, params['page']
  358. @activity = activity.offset(@activity_pages.offset).limit(@activity_pages.per_page).all
  359. @state = 1
  360. end
  361. when "2"
  362. message = []
  363. if @user == User.current
  364. message = JournalsForMessage.reference_message(@user.id)
  365. message += Journal.reference_message(@user.id)
  366. end
  367. @activity_count = message.size
  368. @info_pages = Paginator.new @activity_count, pre_count, params['page']
  369. messages = message.sort {|x,y| y.created_on <=> x.created_on }
  370. @message = messages[@info_pages.offset, @info_pages.per_page]
  371. @state = 2
  372. else
  373. where_condition = nil;
  374. # where_condition = "act_type <> 'JournalsForMessage'"
  375. if @user == User.current
  376. watcher = User.watched_by(@user)
  377. watcher.push(User.current)
  378. activity = Activity.where(where_condition).where('user_id in (?)', watcher).order('id desc')
  379. else
  380. activity = Activity.where(where_condition).where('user_id = ?', @user.id).order('id desc')
  381. end
  382. @activity_count = activity.count
  383. @activity_pages = Paginator.new @activity_count, pre_count, params['page']
  384. @activity = activity.offset(@activity_pages.offset).limit(@activity_pages.per_page).all
  385. @state = 0
  386. end
  387. if params[:user].present?
  388. user_temp = User.find_by_sql("select id from users where concat(lastname,firstname) like '%#{params[:user]}%' or lastname like '%#{params[:user]}%'")
  389. if user_temp.size > 1
  390. activity = Activity.where('user_id in (?)', user_temp).where('user_id in (?)', watcher).order('id desc')
  391. elsif user_temp.size == 1
  392. activity = Activity.where('user_id = ?', user_temp).where('user_id in (?)', watcher).order('id desc')
  393. else
  394. activity = Activity.where("1 = 0")
  395. end
  396. @offset, @limit = api_offset_and_limit({:limit => 10})
  397. @activity_count = activity.count
  398. @activity_pages = Paginator.new @activity_count, @limit, params['page']
  399. @offset ||= @activity_pages.offset
  400. @activity = activity.offset(@offset).limit(@limit)
  401. @state = 0
  402. end
  403. #Modified by nie
  404. unless User.current.admin?
  405. if !@user.active? #|| (@user != User.current && @memberships.empty? && events.empty?)
  406. # redirect_to home_path
  407. render_404
  408. return
  409. end
  410. end
  411. respond_to do |format|
  412. format.html
  413. format.api
  414. end
  415. end
  416. ##end fq
  417. #### added by fq
  418. def info
  419. message = []
  420. if @user == User.current
  421. message = JournalsForMessage.reference_message(@user.id)
  422. message += Journal.reference_message(@user.id)
  423. end
  424. @offset, @limit = api_offset_and_limit({:limit => 10})
  425. @info_count = message.size
  426. @info_pages = Paginator.new @info_count, @limit, params['page']
  427. @offset ||= @info_pages.offset
  428. messages = message.sort {|x,y| y.created_on <=> x.created_on }
  429. @message = messages[@offset, @limit]
  430. unless User.current.admin?
  431. if !@user.active?
  432. render_404
  433. return
  434. end
  435. end
  436. respond_to do |format|
  437. format.html
  438. format.api
  439. end
  440. end
  441. #### end
  442. def new
  443. @user = User.new(:language => Setting.default_language, :mail_notification => Setting.default_notification_option)
  444. @auth_sources = AuthSource.all
  445. render :layout => "base"
  446. end
  447. def create
  448. @user = User.new(:language => Setting.default_language, :mail_notification => Setting.default_notification_option)
  449. @user.safe_attributes = params[:user]
  450. @user.admin = params[:user][:admin] || false
  451. @user.login = params[:user][:login]
  452. @user.password, @user.password_confirmation = params[:user][:password], params[:user][:password_confirmation] unless @user.auth_source_id
  453. if @user.save
  454. @user.pref.attributes = params[:pref]
  455. @user.pref[:no_self_notified] = (params[:no_self_notified] == '1')
  456. @user.pref.save
  457. @user.notified_project_ids = (@user.mail_notification == 'selected' ? params[:notified_project_ids] : [])
  458. Mailer.account_information(@user, params[:user][:password]).deliver if params[:send_information]
  459. respond_to do |format|
  460. format.html {
  461. flash[:notice] = l(:notice_user_successful_create, :id => view_context.link_to(@user.login, user_path(@user)))
  462. if params[:continue]
  463. redirect_to new_user_path
  464. else
  465. redirect_to edit_user_path(@user)
  466. end
  467. }
  468. format.api { render :action => 'show', :status => :created, :location => user_url(@user) }
  469. end
  470. else
  471. @auth_sources = AuthSource.all
  472. # Clear password input
  473. @user.password = @user.password_confirmation = nil
  474. respond_to do |format|
  475. format.html { render :action => 'new' }
  476. format.api { render_validation_errors(@user) }
  477. end
  478. end
  479. unless @user.id.nil?
  480. #后台注册的用户默认权限为男性开发员
  481. ue = UserExtensions.create(:identity => 3,
  482. :gender => 0,
  483. :user_id => @user.id)
  484. ue.save
  485. end
  486. end
  487. def edit
  488. @auth_sources = AuthSource.all
  489. @membership ||= Member.new
  490. end
  491. def watch_projects
  492. @watch_projects = Project.joins(:watchers).where("project_type <>? and watchable_type = ? and `watchers`.user_id = ?", '1','Project', @user.id)
  493. @state = 1
  494. respond_to do |format|
  495. format.html {
  496. render :layout => 'base_users'
  497. }
  498. format.api
  499. end
  500. end
  501. def update
  502. @user.admin = params[:user][:admin] if params[:user][:admin]
  503. @user.login = params[:user][:login] if params[:user][:login]
  504. if params[:user][:password].present? && (@user.auth_source_id.nil? || params[:user][:auth_source_id].blank?)
  505. @user.password, @user.password_confirmation = params[:user][:password], params[:user][:password_confirmation]
  506. end
  507. @user.safe_attributes = params[:user]
  508. # Was the account actived ? (do it before User#save clears the change)
  509. was_activated = (@user.status_change == [User::STATUS_REGISTERED, User::STATUS_ACTIVE])
  510. # TODO: Similar to My#account
  511. @user.pref.attributes = params[:pref]
  512. @user.pref[:no_self_notified] = (params[:no_self_notified] == '1')
  513. if @user.save
  514. @user.pref.save
  515. @user.notified_project_ids = (@user.mail_notification == 'selected' ? params[:notified_project_ids] : [])
  516. if was_activated
  517. Mailer.account_activated(@user).deliver
  518. elsif @user.active? && params[:send_information] && !params[:user][:password].blank? && @user.auth_source_id.nil?
  519. Mailer.account_information(@user, params[:user][:password]).deliver
  520. end
  521. respond_to do |format|
  522. format.html {
  523. flash[:notice] = l(:notice_successful_update)
  524. redirect_to_referer_or edit_user_path(@user)
  525. }
  526. format.api { render_api_ok }
  527. end
  528. else
  529. @auth_sources = AuthSource.all
  530. @membership ||= Member.new
  531. # Clear password input
  532. @user.password = @user.password_confirmation = nil
  533. respond_to do |format|
  534. format.html { render :action => :edit }
  535. format.api { render_validation_errors(@user) }
  536. end
  537. end
  538. end
  539. def destroy
  540. @user.destroy
  541. respond_to do |format|
  542. format.html { redirect_back_or_default(users_path) }
  543. format.api { render_api_ok }
  544. end
  545. end
  546. def edit_membership
  547. @membership = Member.edit_membership(params[:membership_id], params[:membership], @user)
  548. @membership.save
  549. respond_to do |format|
  550. format.html { redirect_to edit_user_path(@user, :tab => 'memberships') }
  551. format.js
  552. end
  553. end
  554. def destroy_membership
  555. @membership = Member.find(params[:membership_id])
  556. if @membership.deletable?
  557. @membership.destroy
  558. end
  559. respond_to do |format|
  560. format.html { redirect_to edit_user_path(@user, :tab => 'memberships') }
  561. format.js
  562. end
  563. end
  564. ################# added by william
  565. def tag_save
  566. @tags = params[:tag_for_save][:name]
  567. @obj_id = params[:tag_for_save][:object_id]
  568. @obj_flag = params[:tag_for_save][:object_flag]
  569. case @obj_flag
  570. when '1' then
  571. @obj = User.find_by_id(@obj_id)
  572. when '2' then
  573. @obj = Project.find_by_id(@obj_id)
  574. when '3' then
  575. @obj = Issue.find_by_id(@obj_id)
  576. when '4' then
  577. @obj = Bid.find_by_id(@obj_id)
  578. when '5' then
  579. @obj = Forum.find_by_id(@obj_id)
  580. when '6'
  581. @obj = Attachment.find_by_id(@obj_id)
  582. when '7' then
  583. @obj = Contest.find_by_id(@obj_id)
  584. when '8'
  585. @obj = OpenSourceProject.find_by_id(@obj_id)
  586. when '9'
  587. @obj = Course.find_by_id(@obj_id)
  588. else
  589. @obj = nil
  590. end
  591. unless @obj.nil?
  592. @obj.tag_list.add(@tags.split(","))
  593. else
  594. return
  595. end
  596. if @obj.save
  597. ## 执行成功的操作。
  598. else
  599. #捕获异常
  600. end
  601. respond_to do |format|
  602. format.js
  603. format.html
  604. end
  605. end
  606. def tag_saveEx
  607. @tags = params[:tag_name]
  608. @obj_id = params[:obj_id]
  609. @obj_flag = params[:obj_flag]
  610. case @obj_flag
  611. when '1' then
  612. @obj = User.find_by_id(@obj_id)
  613. when '2' then
  614. @obj = Project.find_by_id(@obj_id)
  615. when '3' then
  616. @obj = Issue.find_by_id(@obj_id)
  617. when '4' then
  618. @obj = Bid.find_by_id(@obj_id)
  619. when '5' then
  620. @obj = Forum.find_by_id(@obj_id)
  621. when '6'
  622. @obj = Attachment.find_by_id(@obj_id)
  623. when '7' then
  624. @obj = Contest.find_by_id(@obj_id)
  625. when '8'
  626. @obj = OpenSourceProject.find_by_id(@obj_id)
  627. when '9'
  628. @obj = Course.find_by_id(@obj_id)
  629. else
  630. @obj = nil
  631. end
  632. unless @obj.nil?
  633. @obj.tag_list.add(@tags.split(","))
  634. else
  635. return
  636. end
  637. if @obj.save
  638. ## 执行成功的操作。
  639. else
  640. #捕获异常
  641. end
  642. respond_to do |format|
  643. format.js
  644. format.html
  645. end
  646. end
  647. ###add by huang
  648. def user_watchlist
  649. end
  650. ###add by huang
  651. def user_fanslist
  652. end
  653. #william
  654. def update_extensions(user_extensions)
  655. user_extensions = params[:user_extensions]
  656. unless user_extensions.nil?
  657. user_extensions = UserExtensions.find_by_id(user_extensions.user_id)
  658. # user_extensions.
  659. end
  660. end
  661. # added by bai
  662. def topic_score_index
  663. end
  664. def project_score_index
  665. end
  666. def activity_score_index
  667. end
  668. def influence_score_index
  669. end
  670. def score_index
  671. end
  672. # end
  673. private
  674. def find_user
  675. if params[:id] == 'current'
  676. require_login || return
  677. @user = User.current
  678. else
  679. @user = User.find(params[:id])
  680. end
  681. rescue ActiveRecord::RecordNotFound
  682. render_404
  683. end
  684. def setting_layout(default_base='base_users')
  685. User.current.admin? ? default_base : default_base
  686. end
  687. # 必填自己的工作单位,其实就是学校
  688. def auth_user_extension
  689. if @user == User.current && @user.user_extensions.school.nil?
  690. flash[:error] = l(:error_complete_occupation)
  691. redirect_to my_account_path
  692. end
  693. end
  694. end

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