Browse Source

First version of showing uploaded logo. Need to be improved.

Martin Edenhofer 10 years ago
parent
commit
0415a8a298

+ 1 - 1
app/assets/javascripts/app/views/login.jst.eco

@@ -2,7 +2,7 @@
   <p><%- @T( 'Login with %s', @C( 'fqdn' ) ) %></p>
 
   <div class="hero-unit">
-    <img class="logo" src="<%= @C('image_path') + '/' + 'company-logo.png' %>" alt="<%= @C( 'product_name' ) %>">
+    <img class="logo" src="<%= @C('api_path') + '/sessions/logo' %>" alt="<%= @C( 'product_name' ) %>">
     <form id="login">
       <div class="form-group">
         <label for="username"><%- @Ti( 'Username / email' ) %></label>

+ 42 - 0
app/controllers/sessions_controller.rb

@@ -278,4 +278,46 @@ class SessionsController < ApplicationController
     SessionHelper::destroy( params[:id] )
     render :json => {}
   end
+
+=begin
+
+Resource:
+GET /api/v1/sessions/logo
+
+Response:
+<IMAGE>
+
+Test:
+curl http://localhost/api/v1/sessions/logo
+
+=end
+
+  def logo
+
+    # cache image
+    #response.headers['Expires'] = 1.year.from_now.httpdate
+    #response.headers["Cache-Control"] = "cache, store, max-age=31536000, must-revalidate"
+    #response.headers["Pragma"] = "cache"
+
+    # find logo
+    list = Store.list( :object => 'System::Logo', :o_id => 2 )
+    if list && list[0]
+      file = Store.find( list[0] )
+      send_data(
+        file.content,
+        :filename    => file.filename,
+        :type        => file.preferences['Content-Type'],
+        :disposition => 'inline'
+      )
+      return
+    end
+
+    # serve default image
+    send_data(
+      '',
+      :filename    => '',
+      :type        => 'image/gif',
+      :disposition => 'inline'
+    )
+  end
 end

+ 1 - 0
config/routes/auth.rb

@@ -15,6 +15,7 @@ Zammad::Application.routes.draw do
   match api_path + '/sessions/switch/:id',  :to => 'sessions#switch_to_user',       :via => :get
   match api_path + '/sessions/switch_back', :to => 'sessions#switch_back_to_user',  :via => :get
   match api_path + '/sessions',             :to => 'sessions#list',                 :via => :get
+  match api_path + '/sessions/logo',        :to => 'sessions#logo',                 :via => :get
   match api_path + '/sessions/:id',         :to => 'sessions#delete',               :via => :delete
 
 end