Merge branch 'master' of github.com:martini/zammad
This commit is contained in:
commit
6a042642a6
11 changed files with 137 additions and 70 deletions
|
@ -48,22 +48,14 @@ class Index extends App.Controller
|
||||||
|
|
||||||
login: (e) ->
|
login: (e) ->
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
e.stopPropagation();
|
params = @formParam(e.target)
|
||||||
|
|
||||||
@log 'submit', $(e.target)
|
|
||||||
@username = $(e.target).find('[name="username"]').val()
|
|
||||||
@password = $(e.target).find('[name="password"]').val()
|
|
||||||
# @log @username, @password
|
|
||||||
|
|
||||||
# session create with login/password
|
# session create with login/password
|
||||||
auth = new App.Auth
|
auth = new App.Auth
|
||||||
auth.login(
|
auth.login(
|
||||||
data: {
|
data: params,
|
||||||
username: @username,
|
|
||||||
password: @password,
|
|
||||||
},
|
|
||||||
success: @success
|
success: @success
|
||||||
error: @error,
|
error: @error,
|
||||||
)
|
)
|
||||||
|
|
||||||
success: (data, status, xhr) =>
|
success: (data, status, xhr) =>
|
||||||
|
|
|
@ -22,6 +22,6 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="form-actions">
|
<div class="form-actions">
|
||||||
<button type="reset" class="btn">Cancel</button> <input type="submit" class="btn-primary" value="Create"/>
|
<button type="reset" class="btn">Cancel</button> <input type="submit" class="btn btn-primary" value="Create"/>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
|
|
|
@ -18,7 +18,7 @@
|
||||||
<h2>Master Agent</h2>
|
<h2>Master Agent</h2>
|
||||||
<form class="form-stacked">
|
<form class="form-stacked">
|
||||||
<%- @form_master %>
|
<%- @form_master %>
|
||||||
<button class="btn-primary submit">Next...</button>
|
<button class="btn btn-primary submit">Next...</button>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
@ -26,7 +26,7 @@
|
||||||
<h2>Invite Agents</h2>
|
<h2>Invite Agents</h2>
|
||||||
<form class="form-stacked">
|
<form class="form-stacked">
|
||||||
<%- @form_agent %>
|
<%- @form_agent %>
|
||||||
<button class="btn-primary submit">Send Invitation</button>
|
<button class="btn btn-primary submit">Send Invitation</button>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
<div class="span6">
|
<div class="span6">
|
||||||
|
|
|
@ -6,11 +6,16 @@
|
||||||
<div class="container">
|
<div class="container">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="span12">
|
<div class="span12">
|
||||||
Sign in with
|
<p>Sign in with</p>
|
||||||
<form id="login" class="form-search">
|
<form id="login" class="form-search">
|
||||||
<input name="username" type="text" class="input span3" placeholder="Username" value="<%= @item.username %>" autocapitalize="off"/>
|
<input name="username" type="text" class="input span3" placeholder="Username or email" value="<%= @item.username %>" autocapitalize="off"/>
|
||||||
<input name="password" type="password" class="input span3" placeholder="Password"/>
|
<input name="password" type="password" class="input span3" placeholder="Password"/>
|
||||||
<button class="btn-primary" type="submit">Sign in</button>
|
<button class="btn btn-primary" type="submit">Sign in</button>
|
||||||
|
<div>
|
||||||
|
<span class="small"><input name="remember_me" value="1" type="checkbox"/> Remember me</span>
|
||||||
|
<span class="small">·</span>
|
||||||
|
<a href="#resend_password" class="small">Forgot password?</a>
|
||||||
|
</div>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -25,7 +30,7 @@
|
||||||
|
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="span12">
|
<div class="span12">
|
||||||
Sign in using
|
<p>Sign in using</p>
|
||||||
<ul>
|
<ul>
|
||||||
<% for auth_provider in @auth_providers: %>
|
<% for auth_provider in @auth_providers: %>
|
||||||
<li><a href="<%= auth_provider.url %>"><%= auth_provider.name %></a></li>
|
<li><a href="<%= auth_provider.url %>"><%= auth_provider.name %></a></li>
|
||||||
|
|
|
@ -2,12 +2,12 @@
|
||||||
<h1>Join <%= Config.product_name %><small></small></h1>
|
<h1>Join <%= Config.product_name %><small></small></h1>
|
||||||
|
|
||||||
<div class="container">
|
<div class="container">
|
||||||
|
<form class="form-horizontal">
|
||||||
<form>
|
<p>
|
||||||
<%- @form %>
|
<%- @form %>
|
||||||
<button class="btn cancel">Cancel</button>
|
</p>
|
||||||
<button class="btn-primary submit">Create my account</button>
|
<a href="#/" class="btn cancel">Cancel</a>
|
||||||
|
<button class="btn btn-primary submit">Create my account</button>
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
|
@ -13,6 +13,15 @@ body {
|
||||||
background-image: url("../assets/glyphicons-halflings.png");
|
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 <form></form> area e. g. for modal dialogs
|
* removed margin of forms to not break the layout with submit buttons within <form></form> area e. g. for modal dialogs
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -92,6 +92,18 @@ class ApplicationController < ActionController::Base
|
||||||
return false
|
return false
|
||||||
end
|
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)
|
# return auth not ok (no session exists)
|
||||||
if !session[:user_id]
|
if !session[:user_id]
|
||||||
message = 'no valid session, user_id'
|
message = 'no valid session, user_id'
|
||||||
|
@ -134,7 +146,7 @@ class ApplicationController < ActionController::Base
|
||||||
:o_id => object.id,
|
:o_id => object.id,
|
||||||
:history_type_id => history_type.id,
|
:history_type_id => history_type.id,
|
||||||
:history_object_id => history_object.id,
|
:history_object_id => history_object.id,
|
||||||
:created_by_id => session[:user_id]
|
:created_by_id => current_user.id
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -5,37 +5,70 @@ class SessionsController < ApplicationController
|
||||||
|
|
||||||
# "Create" a login, aka "log the user in"
|
# "Create" a login, aka "log the user in"
|
||||||
def create
|
def create
|
||||||
logger.debug 'session create'
|
|
||||||
# logger.debug params.inspect
|
|
||||||
user = User.authenticate( params[:username], params[:password] )
|
user = User.authenticate( params[:username], params[:password] )
|
||||||
|
|
||||||
# auth failed
|
# auth failed
|
||||||
if !user
|
if !user
|
||||||
render :json => { :error => 'login failed' }, :status => :unprocessable_entity
|
render :json => { :error => 'login failed' }, :status => :unprocessable_entity
|
||||||
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
user = User.find_fulldata(user.id)
|
||||||
|
|
||||||
# do not show password
|
# do not show password
|
||||||
user['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
|
# auto population of default collections
|
||||||
default_collection = default_collections()
|
default_collection = default_collections()
|
||||||
|
|
||||||
# set session user_id
|
# 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
|
# 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
|
end
|
||||||
|
|
||||||
def show
|
def show
|
||||||
|
|
||||||
|
user_id = nil
|
||||||
|
|
||||||
# no valid sessions
|
# 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 => {
|
render :json => {
|
||||||
:error => 'no valid session',
|
:error => 'no valid session',
|
||||||
:config => config_frontend,
|
:config => config_frontend,
|
||||||
|
@ -45,7 +78,7 @@ class SessionsController < ApplicationController
|
||||||
|
|
||||||
# Save the user ID in the session so it can be used in
|
# Save the user ID in the session so it can be used in
|
||||||
# subsequent requests
|
# subsequent requests
|
||||||
user = user_data_full( session[:user_id] )
|
user = user_data_full( user_id )
|
||||||
|
|
||||||
# auto population of default collections
|
# auto population of default collections
|
||||||
default_collection = default_collections()
|
default_collection = default_collections()
|
||||||
|
@ -60,10 +93,14 @@ class SessionsController < ApplicationController
|
||||||
|
|
||||||
# "Delete" a login, aka "log the user out"
|
# "Delete" a login, aka "log the user out"
|
||||||
def destroy
|
def destroy
|
||||||
|
|
||||||
# Remove the user id from the session
|
# Remove the user id from the session
|
||||||
@_current_user = session[:user_id] = nil
|
@_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 => { }
|
render :json => { }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,7 @@ class TicketOverviewsController < ApplicationController
|
||||||
# GET /tickets
|
# GET /tickets
|
||||||
# GET /tickets.json
|
# GET /tickets.json
|
||||||
def show
|
def show
|
||||||
|
|
||||||
# build up attributes hash
|
# build up attributes hash
|
||||||
overview_selected = nil
|
overview_selected = nil
|
||||||
overviews = Overview.all
|
overviews = Overview.all
|
||||||
|
@ -376,7 +376,7 @@ class TicketOverviewsController < ApplicationController
|
||||||
|
|
||||||
# load article ids
|
# load article ids
|
||||||
# if item.history_object == 'Ticket'
|
# if item.history_object == 'Ticket'
|
||||||
tickets.push Ticket.find(item.o_id)
|
tickets.push Ticket.find( item['o_id'] )
|
||||||
# end
|
# end
|
||||||
# if item.history_object 'Ticket::Article'
|
# if item.history_object 'Ticket::Article'
|
||||||
# tickets.push Ticket::Article.find(item.o_id)
|
# tickets.push Ticket::Article.find(item.o_id)
|
||||||
|
@ -386,8 +386,8 @@ class TicketOverviewsController < ApplicationController
|
||||||
# end
|
# end
|
||||||
|
|
||||||
# load users
|
# load users
|
||||||
if !users[item.created_by_id]
|
if !users[ item['created_by_id'] ]
|
||||||
users[item.created_by_id] = user_data_full(item.created_by_id)
|
users[ item['created_by_id'] ] = user_data_full( item['created_by_id'] )
|
||||||
end
|
end
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -411,7 +411,7 @@ class TicketOverviewsController < ApplicationController
|
||||||
|
|
||||||
# load article ids
|
# load article ids
|
||||||
# if item.history_object == 'Ticket'
|
# if item.history_object == 'Ticket'
|
||||||
tickets.push Ticket.find(item.o_id)
|
tickets.push Ticket.find( item['o_id'] )
|
||||||
# end
|
# end
|
||||||
# if item.history_object 'Ticket::Article'
|
# if item.history_object 'Ticket::Article'
|
||||||
# tickets.push Ticket::Article.find(item.o_id)
|
# tickets.push Ticket::Article.find(item.o_id)
|
||||||
|
@ -421,8 +421,8 @@ class TicketOverviewsController < ApplicationController
|
||||||
# end
|
# end
|
||||||
|
|
||||||
# load users
|
# load users
|
||||||
if !users[item.created_by_id]
|
if !users[ item['created_by_id'] ]
|
||||||
users[item.created_by_id] = user_data_full(item.created_by_id)
|
users[ item['created_by_id'] ] = user_data_full( item['created_by_id'] )
|
||||||
end
|
end
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -25,12 +25,15 @@ class History < ActiveRecord::Base
|
||||||
where( :history_type_id => History::Type.where( :name => ['created', 'updated']) ).
|
where( :history_type_id => History::Type.where( :name => ['created', 'updated']) ).
|
||||||
order('created_at DESC, id DESC').
|
order('created_at DESC, id DESC').
|
||||||
limit(10)
|
limit(10)
|
||||||
|
datas = []
|
||||||
stream.each do |item|
|
stream.each do |item|
|
||||||
item['history_object'] = item.history_object
|
data = item.attributes
|
||||||
item['history_type'] = item.history_type
|
data['history_object'] = item.history_object
|
||||||
|
data['history_type'] = item.history_type
|
||||||
|
datas.push data
|
||||||
# item['history_attribute'] = item.history_attribute
|
# item['history_attribute'] = item.history_attribute
|
||||||
end
|
end
|
||||||
return stream
|
return datas
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.recent_viewed(user)
|
def self.recent_viewed(user)
|
||||||
|
@ -40,12 +43,15 @@ class History < ActiveRecord::Base
|
||||||
where( :history_type_id => History::Type.where( :name => ['viewed']) ).
|
where( :history_type_id => History::Type.where( :name => ['viewed']) ).
|
||||||
order('created_at DESC, id DESC').
|
order('created_at DESC, id DESC').
|
||||||
limit(10)
|
limit(10)
|
||||||
|
datas = []
|
||||||
stream.each do |item|
|
stream.each do |item|
|
||||||
item['history_object'] = item.history_object
|
data = item.attributes
|
||||||
item['history_type'] = item.history_type
|
data['history_object'] = item.history_object
|
||||||
|
data['history_type'] = item.history_type
|
||||||
|
datas.push data
|
||||||
# item['history_attribute'] = item.history_attribute
|
# item['history_attribute'] = item.history_attribute
|
||||||
end
|
end
|
||||||
return stream
|
return datas
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
|
@ -13,31 +13,38 @@ class User < ApplicationModel
|
||||||
store :preferences
|
store :preferences
|
||||||
|
|
||||||
def self.authenticate( username, password )
|
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
|
user = User.where( :login => username, :active => true ).first
|
||||||
return nil if user.nil?
|
|
||||||
logger.debug 'auth'
|
# try second lookup with email
|
||||||
logger.debug username
|
if !user
|
||||||
logger.debug user.login
|
user = User.where( :email => username, :active => true ).first
|
||||||
logger.debug password
|
end
|
||||||
logger.debug user.password
|
|
||||||
logger.debug user.inspect
|
# no user found
|
||||||
# return user
|
if !user
|
||||||
return user if user.password == password
|
return nil
|
||||||
return
|
end
|
||||||
|
|
||||||
|
# auth ok
|
||||||
|
if user.password == password
|
||||||
|
return user
|
||||||
|
end
|
||||||
|
|
||||||
|
# auth failed
|
||||||
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.create_from_hash!(hash)
|
def self.create_from_hash!(hash)
|
||||||
# logger.debug(hash.inspect)
|
|
||||||
# raise hash.to_yaml
|
|
||||||
# exit
|
|
||||||
url = ''
|
url = ''
|
||||||
if hash['info']['urls'] then
|
if hash['info']['urls'] then
|
||||||
url = hash['info']['urls']['Website'] || hash['info']['urls']['Twitter'] || ''
|
url = hash['info']['urls']['Website'] || hash['info']['urls']['Twitter'] || ''
|
||||||
end
|
end
|
||||||
# logger.debug(hash['info'].inspect)
|
|
||||||
# raise url.to_yaml
|
|
||||||
# exit
|
|
||||||
# logger.debug('aaaaaaaa')
|
|
||||||
roles = Role.where( :name => 'Customer' )
|
roles = Role.where( :name => 'Customer' )
|
||||||
create(
|
create(
|
||||||
:login => hash['info']['nickname'] || hash['uid'],
|
:login => hash['info']['nickname'] || hash['uid'],
|
||||||
|
@ -61,7 +68,6 @@ class User < ApplicationModel
|
||||||
user = User.find(user_id)
|
user = User.find(user_id)
|
||||||
data = user.attributes
|
data = user.attributes
|
||||||
|
|
||||||
|
|
||||||
# get linked accounts
|
# get linked accounts
|
||||||
data['accounts'] = {}
|
data['accounts'] = {}
|
||||||
authorizations = user.authorizations() || []
|
authorizations = user.authorizations() || []
|
||||||
|
|
Loading…
Reference in a new issue