用户连接 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
# 别人的资源库是没有权限去看的
if User.current.id.to_i != params[:id].to_i
if User.current.id.to_i != @user.id.to_i
render_403
return
end

View File

@ -33,6 +33,19 @@ module ApplicationHelper
extend Forwardable
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
container.update_column(:visits, container.visits + 1)
end

View File

@ -1072,16 +1072,25 @@ class User < Principal
anonymous_user
end
def self.is_id?(id)
Fixnum===id || id.to_i.to_s == id
end
# refactor User model find function,
# return anonymous user when can not find user id = user_id
def self.find (*args, &block)
begin
return find_by_login(args.first) if args.size==1 && !is_id?(args.first)
super
rescue
self.anonymous
end
# super
end
def to_param
login
end
# Salts all existing unsalted passwords
# 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

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/new', :to => 'news#new', :via => [:get, :post]
scope ":username" do
resources :posts
end
#added by young
resources :users do
collection do