diff --git a/app/assets/javascripts/app/controllers/login.js.coffee b/app/assets/javascripts/app/controllers/login.js.coffee index 3628921a4..ec5f18584 100644 --- a/app/assets/javascripts/app/controllers/login.js.coffee +++ b/app/assets/javascripts/app/controllers/login.js.coffee @@ -48,22 +48,14 @@ class Index extends App.Controller login: (e) -> e.preventDefault() - e.stopPropagation(); - - @log 'submit', $(e.target) - @username = $(e.target).find('[name="username"]').val() - @password = $(e.target).find('[name="password"]').val() -# @log @username, @password + params = @formParam(e.target) # session create with login/password auth = new App.Auth auth.login( - data: { - username: @username, - password: @password, - }, + data: params, success: @success - error: @error, + error: @error, ) success: (data, status, xhr) => diff --git a/app/assets/javascripts/app/views/agent_ticket_create.jst.eco b/app/assets/javascripts/app/views/agent_ticket_create.jst.eco index f07b852c3..a4f088462 100644 --- a/app/assets/javascripts/app/views/agent_ticket_create.jst.eco +++ b/app/assets/javascripts/app/views/agent_ticket_create.jst.eco @@ -22,6 +22,6 @@
-   +  
diff --git a/app/assets/javascripts/app/views/getting_started.jst.eco b/app/assets/javascripts/app/views/getting_started.jst.eco index b62e5108a..061eba958 100644 --- a/app/assets/javascripts/app/views/getting_started.jst.eco +++ b/app/assets/javascripts/app/views/getting_started.jst.eco @@ -18,7 +18,7 @@

Master Agent

<%- @form_master %> - +
<% end %> @@ -26,7 +26,7 @@

Invite Agents

<%- @form_agent %> - +
diff --git a/app/assets/javascripts/app/views/login.jst.eco b/app/assets/javascripts/app/views/login.jst.eco index e4a345d1c..25aa7364f 100644 --- a/app/assets/javascripts/app/views/login.jst.eco +++ b/app/assets/javascripts/app/views/login.jst.eco @@ -6,11 +6,16 @@
- Sign in with +

Sign in with

@@ -25,7 +30,7 @@
- Sign in using +

Sign in using

    <% for auth_provider in @auth_providers: %>
  • <%= auth_provider.name %>
  • diff --git a/app/assets/javascripts/app/views/signup.jst.eco b/app/assets/javascripts/app/views/signup.jst.eco index 35ee8098c..ab343a331 100644 --- a/app/assets/javascripts/app/views/signup.jst.eco +++ b/app/assets/javascripts/app/views/signup.jst.eco @@ -2,12 +2,12 @@

    Join <%= Config.product_name %>

    - -
    - <%- @form %> - - + +

    + <%- @form %> +

    + Cancel +
    -
\ No newline at end of file diff --git a/app/assets/stylesheets/zzz.css b/app/assets/stylesheets/zzz.css index 39cd69db8..6181212bf 100644 --- a/app/assets/stylesheets/zzz.css +++ b/app/assets/stylesheets/zzz.css @@ -13,6 +13,15 @@ body { background-image: url("../assets/glyphicons-halflings.png"); } +/* + * + */ +.hero-unit .small { + font-size: 12px; + line-height: 20px; + color: #999999; +} + /* * removed margin of forms to not break the layout with submit buttons within
area e. g. for modal dialogs */ diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 1340239e6..a69cf48fd 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -92,6 +92,18 @@ class ApplicationController < ActionController::Base return false end + # check logon session + if params['logon_session'] + logon_session = ActiveRecord::SessionStore::Session.where( :session_id => params['logon_session'] ).first + if logon_session + userdata = User.find( user_id = logon_session.data[:user_id] ) + end + + # set logon session user to current user + current_user_set(userdata) + return true + end + # return auth not ok (no session exists) if !session[:user_id] message = 'no valid session, user_id' @@ -134,7 +146,7 @@ class ApplicationController < ActionController::Base :o_id => object.id, :history_type_id => history_type.id, :history_object_id => history_object.id, - :created_by_id => session[:user_id] + :created_by_id => current_user.id ) end diff --git a/app/controllers/sessions_controller.rb b/app/controllers/sessions_controller.rb index 9bf351888..c62b3e094 100644 --- a/app/controllers/sessions_controller.rb +++ b/app/controllers/sessions_controller.rb @@ -5,37 +5,70 @@ class SessionsController < ApplicationController # "Create" a login, aka "log the user in" def create - logger.debug 'session create' -# logger.debug params.inspect + user = User.authenticate( params[:username], params[:password] ) # auth failed if !user render :json => { :error => 'login failed' }, :status => :unprocessable_entity + return end + user = User.find_fulldata(user.id) + # do not show password user['password'] = '' - user['roles'] = user.roles.select('id, name').where(:active => true) - user['groups'] = user.groups.select('id, name').where(:active => true) - user['organization'] = user.organization - user['organizations'] = user.organizations.select('id, name').where(:active => true) - # auto population of default collections default_collection = default_collections() # set session user_id - session[:user_id] = user.id - + session[:user_id] = user['id'] + + # check logon session + logon_session_key = nil + if params['logon_session'] + logon_session_key = Digest::MD5.hexdigest( rand(999999).to_s + Time.new.to_s ) + session = ActiveRecord::SessionStore::Session.create( + :session_id => logon_session_key, + :data => { + :user_id => user['id'] + } + ) + end + + # remember me - set session cookie to expire later + if params[:remember_me] + request.env['rack.session.options'][:expire_after] = 1.year.from_now + end + # return new session data - render :json => { :session => user, :default_collections => default_collection }, :status => :created + render :json => { + :session => user, + :default_collections => default_collection, + :logon_session => logon_session_key, + }, + :status => :created end def show - + + user_id = nil + # no valid sessions - if !session[:user_id] + if session[:user_id] + user_id = session[:user_id] + end + + # check logon session + if params['logon_session'] + session = ActiveRecord::SessionStore::Session.where( :session_id => params['logon_session'] ).first + if session + user_id = session.data[:user_id] + end + end + + if !user_id render :json => { :error => 'no valid session', :config => config_frontend, @@ -45,7 +78,7 @@ class SessionsController < ApplicationController # Save the user ID in the session so it can be used in # subsequent requests - user = user_data_full( session[:user_id] ) + user = user_data_full( user_id ) # auto population of default collections default_collection = default_collections() @@ -60,10 +93,14 @@ class SessionsController < ApplicationController # "Delete" a login, aka "log the user out" def destroy - + # Remove the user id from the session @_current_user = session[:user_id] = nil + # reset session cookie (set :expire_after to '' in case remember_me is active) + request.env['rack.session.options'][:expire_after] = '' + request.env['rack.session.options'][:renew] = true + render :json => { } end diff --git a/app/controllers/ticket_overviews_controller.rb b/app/controllers/ticket_overviews_controller.rb index f3be59117..5ec7048c2 100644 --- a/app/controllers/ticket_overviews_controller.rb +++ b/app/controllers/ticket_overviews_controller.rb @@ -4,7 +4,7 @@ class TicketOverviewsController < ApplicationController # GET /tickets # GET /tickets.json def show - + # build up attributes hash overview_selected = nil overviews = Overview.all @@ -376,7 +376,7 @@ class TicketOverviewsController < ApplicationController # load article ids # if item.history_object == 'Ticket' - tickets.push Ticket.find(item.o_id) + tickets.push Ticket.find( item['o_id'] ) # end # if item.history_object 'Ticket::Article' # tickets.push Ticket::Article.find(item.o_id) @@ -386,8 +386,8 @@ class TicketOverviewsController < ApplicationController # end # load users - if !users[item.created_by_id] - users[item.created_by_id] = user_data_full(item.created_by_id) + if !users[ item['created_by_id'] ] + users[ item['created_by_id'] ] = user_data_full( item['created_by_id'] ) end } @@ -411,7 +411,7 @@ class TicketOverviewsController < ApplicationController # load article ids # if item.history_object == 'Ticket' - tickets.push Ticket.find(item.o_id) + tickets.push Ticket.find( item['o_id'] ) # end # if item.history_object 'Ticket::Article' # tickets.push Ticket::Article.find(item.o_id) @@ -421,8 +421,8 @@ class TicketOverviewsController < ApplicationController # end # load users - if !users[item.created_by_id] - users[item.created_by_id] = user_data_full(item.created_by_id) + if !users[ item['created_by_id'] ] + users[ item['created_by_id'] ] = user_data_full( item['created_by_id'] ) end } diff --git a/app/models/history.rb b/app/models/history.rb index 9c52347d8..d95532c8f 100644 --- a/app/models/history.rb +++ b/app/models/history.rb @@ -25,12 +25,15 @@ class History < ActiveRecord::Base where( :history_type_id => History::Type.where( :name => ['created', 'updated']) ). order('created_at DESC, id DESC'). limit(10) + datas = [] stream.each do |item| - item['history_object'] = item.history_object - item['history_type'] = item.history_type + data = item.attributes + data['history_object'] = item.history_object + data['history_type'] = item.history_type + datas.push data # item['history_attribute'] = item.history_attribute end - return stream + return datas end def self.recent_viewed(user) @@ -40,12 +43,15 @@ class History < ActiveRecord::Base where( :history_type_id => History::Type.where( :name => ['viewed']) ). order('created_at DESC, id DESC'). limit(10) + datas = [] stream.each do |item| - item['history_object'] = item.history_object - item['history_type'] = item.history_type + data = item.attributes + data['history_object'] = item.history_object + data['history_type'] = item.history_type + datas.push data # item['history_attribute'] = item.history_attribute end - return stream + return datas end private diff --git a/app/models/user.rb b/app/models/user.rb index 011622bc8..a827fee1c 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -13,31 +13,38 @@ class User < ApplicationModel store :preferences def self.authenticate( username, password ) + + # do not authenticate with nothing + return if !username + return if !password + + # try to find user based on login user = User.where( :login => username, :active => true ).first - return nil if user.nil? - logger.debug 'auth' - logger.debug username - logger.debug user.login - logger.debug password - logger.debug user.password - logger.debug user.inspect -# return user - return user if user.password == password - return + + # try second lookup with email + if !user + user = User.where( :email => username, :active => true ).first + end + + # no user found + if !user + return nil + end + + # auth ok + if user.password == password + return user + end + + # auth failed + return false end def self.create_from_hash!(hash) -# logger.debug(hash.inspect) -# raise hash.to_yaml -# exit url = '' if hash['info']['urls'] then url = hash['info']['urls']['Website'] || hash['info']['urls']['Twitter'] || '' end -# logger.debug(hash['info'].inspect) -# raise url.to_yaml -# exit -# logger.debug('aaaaaaaa') roles = Role.where( :name => 'Customer' ) create( :login => hash['info']['nickname'] || hash['uid'], @@ -61,7 +68,6 @@ class User < ApplicationModel user = User.find(user_id) data = user.attributes - # get linked accounts data['accounts'] = {} authorizations = user.authorizations() || []