用户连接 id变成用户名

This commit is contained in:
huang 2016-05-10 09:00:59 +08:00
parent fc36e4c01e
commit 6474444cc7
4 changed files with 27 additions and 1 deletions

View File

@ -2708,7 +2708,7 @@ class UsersController < ApplicationController
# 资源库 分为全部 课程资源 项目资源 附件 # 资源库 分为全部 课程资源 项目资源 附件
def user_resource def user_resource
# 别人的资源库是没有权限去看的 # 别人的资源库是没有权限去看的
if User.current.id.to_i != params[:id].to_i if User.current.id.to_i != @user.id.to_i
render_403 render_403
return return
end end

View File

@ -33,6 +33,19 @@ module ApplicationHelper
extend Forwardable extend Forwardable
def_delegators :wiki_helper, :wikitoolbar_for, :heads_for_wiki_formatter def_delegators :wiki_helper, :wikitoolbar_for, :heads_for_wiki_formatter
def user_path(resource, parameters = {})
if Fixnum === resource
resource = User.find(resource)
end
super
end
# def user_blogs_path(resource,parameters={})
# super
# end
def update_visiti_count container def update_visiti_count container
container.update_column(:visits, container.visits + 1) container.update_column(:visits, container.visits + 1)
end end

View File

@ -1072,16 +1072,25 @@ class User < Principal
anonymous_user anonymous_user
end end
def self.is_id?(id)
Fixnum===id || id.to_i.to_s == id
end
# refactor User model find function, # refactor User model find function,
# return anonymous user when can not find user id = user_id # return anonymous user when can not find user id = user_id
def self.find (*args, &block) def self.find (*args, &block)
begin begin
return find_by_login(args.first) if args.size==1 && !is_id?(args.first)
super super
rescue rescue
self.anonymous self.anonymous
end end
# super # super
end end
def to_param
login
end
# Salts all existing unsalted passwords # Salts all existing unsalted passwords
# It changes password storage scheme from SHA1(password) to SHA1(salt + SHA1(password)) # It changes password storage scheme from SHA1(password) to SHA1(salt + SHA1(password))
# This method is used in the SaltPasswords migration and is to be kept as is # This method is used in the SaltPasswords migration and is to be kept as is

View File

@ -522,6 +522,10 @@ RedmineApp::Application.routes.draw do
match 'courses/:course_id/news/index', :to => 'news#index', :via => [:get, :post], :as => 'new_course_news' match 'courses/:course_id/news/index', :to => 'news#index', :via => [:get, :post], :as => 'new_course_news'
match 'courses/:course_id/news/new', :to => 'news#new', :via => [:get, :post] match 'courses/:course_id/news/new', :to => 'news#new', :via => [:get, :post]
scope ":username" do
resources :posts
end
#added by young #added by young
resources :users do resources :users do
collection do collection do