Module: Ums::ApplicationHelper

Defined in:
app/helpers/ums/application_helper.rb

Instance Method Summary collapse

Instance Method Details

#authorizeObject



4
5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'app/helpers/ums/application_helper.rb', line 4

def authorize
   #unless Account.find_by_id(session[:account_id])
   if session[:user_id].nil?
     session[:original_uri] = request.url
     #flash[:notice] = "Please log in"
     redirect_to  ums. 
     return    
   end

   path = params[:controller] + "/" + params[:action]
   unless validate_permission(path)
      render status: :forbidden, text: "对不起,您没有访问该地址的权限"
   end    
end

#log_error(log_type, log_content, log_ip) ⇒ Object



28
29
30
31
32
33
34
35
# File 'app/helpers/ums/application_helper.rb', line 28

def log_error(log_type,log_content,log_ip)
log = Ums::Log.new
log.level="error"
log.log_type=log_type
log.data=log_content
log.ip=log_ip
log.save
end

#log_info(log_type, log_content, log_ip) ⇒ Object



19
20
21
22
23
24
25
26
# File 'app/helpers/ums/application_helper.rb', line 19

def log_info(log_type,log_content,log_ip)
log = Ums::Log.new
log.level="info"
log.log_type=log_type
log.data=log_content
log.ip=log_ip
log.save
end

#validate_permission(path) ⇒ Object



37
38
39
40
41
42
43
44
# File 'app/helpers/ums/application_helper.rb', line 37

def validate_permission(path)
  permission = session[:user_permission]

  logger.debug("user_permission:" + permission) unless permission.nil?
  logger.debug("user_path:" + path) unless path.nil?
  return false if permission.nil? || path.nil?
  return path.match(permission)
end