Improved getting started.
This commit is contained in:
parent
3256c6c934
commit
99e9751612
7 changed files with 210 additions and 33 deletions
65
Gemfile.lock
65
Gemfile.lock
|
@ -1,5 +1,5 @@
|
||||||
GEM
|
GEM
|
||||||
remote: https://rubygems.org/
|
remote: http://rubygems.org/
|
||||||
specs:
|
specs:
|
||||||
actionmailer (3.2.2)
|
actionmailer (3.2.2)
|
||||||
actionpack (= 3.2.2)
|
actionpack (= 3.2.2)
|
||||||
|
@ -28,6 +28,7 @@ GEM
|
||||||
activesupport (3.2.2)
|
activesupport (3.2.2)
|
||||||
i18n (~> 0.6)
|
i18n (~> 0.6)
|
||||||
multi_json (~> 1.0)
|
multi_json (~> 1.0)
|
||||||
|
addressable (2.2.7)
|
||||||
arel (3.0.2)
|
arel (3.0.2)
|
||||||
builder (3.0.0)
|
builder (3.0.0)
|
||||||
coffee-rails (3.2.2)
|
coffee-rails (3.2.2)
|
||||||
|
@ -37,9 +38,25 @@ GEM
|
||||||
coffee-script-source
|
coffee-script-source
|
||||||
execjs
|
execjs
|
||||||
coffee-script-source (1.2.0)
|
coffee-script-source (1.2.0)
|
||||||
|
daemons (1.1.8)
|
||||||
|
delayed_job (3.0.1)
|
||||||
|
activesupport (~> 3.0)
|
||||||
|
delayed_job_active_record (0.3.2)
|
||||||
|
activerecord (> 2.1.0)
|
||||||
|
delayed_job (~> 3.0.0)
|
||||||
|
eco (1.0.0)
|
||||||
|
coffee-script
|
||||||
|
eco-source
|
||||||
|
execjs
|
||||||
|
eco-source (1.1.0.rc.1)
|
||||||
erubis (2.7.0)
|
erubis (2.7.0)
|
||||||
execjs (1.3.0)
|
execjs (1.3.0)
|
||||||
multi_json (~> 1.0)
|
multi_json (~> 1.0)
|
||||||
|
faraday (0.7.6)
|
||||||
|
addressable (~> 2.2)
|
||||||
|
multipart-post (~> 1.1)
|
||||||
|
rack (~> 1.1)
|
||||||
|
hashie (1.2.0)
|
||||||
hike (1.2.1)
|
hike (1.2.1)
|
||||||
i18n (0.6.0)
|
i18n (0.6.0)
|
||||||
journey (1.0.3)
|
journey (1.0.3)
|
||||||
|
@ -47,12 +64,35 @@ GEM
|
||||||
railties (>= 3.2.0, < 5.0)
|
railties (>= 3.2.0, < 5.0)
|
||||||
thor (~> 0.14)
|
thor (~> 0.14)
|
||||||
json (1.6.6)
|
json (1.6.6)
|
||||||
|
koala (1.3.0)
|
||||||
|
faraday (~> 0.7.0)
|
||||||
|
multi_json (~> 1.0)
|
||||||
mail (2.4.4)
|
mail (2.4.4)
|
||||||
i18n (>= 0.4.0)
|
i18n (>= 0.4.0)
|
||||||
mime-types (~> 1.16)
|
mime-types (~> 1.16)
|
||||||
treetop (~> 1.4.8)
|
treetop (~> 1.4.8)
|
||||||
mime-types (1.18)
|
mime-types (1.18)
|
||||||
multi_json (1.2.0)
|
multi_json (1.2.0)
|
||||||
|
multipart-post (1.1.5)
|
||||||
|
oauth (0.4.5)
|
||||||
|
oauth2 (0.5.2)
|
||||||
|
faraday (~> 0.7)
|
||||||
|
multi_json (~> 1.0)
|
||||||
|
omniauth (1.0.2)
|
||||||
|
hashie (~> 1.2)
|
||||||
|
rack
|
||||||
|
omniauth-facebook (1.2.0)
|
||||||
|
omniauth-oauth2 (~> 1.0.0)
|
||||||
|
omniauth-linkedin (0.0.6)
|
||||||
|
omniauth-oauth (~> 1.0.0)
|
||||||
|
omniauth-oauth (1.0.0)
|
||||||
|
oauth
|
||||||
|
omniauth (~> 1.0)
|
||||||
|
omniauth-oauth2 (1.0.0)
|
||||||
|
oauth2 (~> 0.5.0)
|
||||||
|
omniauth (~> 1.0)
|
||||||
|
omniauth-twitter (0.0.8)
|
||||||
|
omniauth-oauth (~> 1.0)
|
||||||
polyglot (0.3.3)
|
polyglot (0.3.3)
|
||||||
rack (1.4.1)
|
rack (1.4.1)
|
||||||
rack-cache (1.2)
|
rack-cache (1.2)
|
||||||
|
@ -84,6 +124,7 @@ GEM
|
||||||
railties (~> 3.2.0)
|
railties (~> 3.2.0)
|
||||||
sass (>= 3.1.10)
|
sass (>= 3.1.10)
|
||||||
tilt (~> 1.3)
|
tilt (~> 1.3)
|
||||||
|
simple_oauth (0.1.5)
|
||||||
sprockets (2.1.2)
|
sprockets (2.1.2)
|
||||||
hike (~> 1.2)
|
hike (~> 1.2)
|
||||||
rack (~> 1.0)
|
rack (~> 1.0)
|
||||||
|
@ -94,6 +135,11 @@ GEM
|
||||||
treetop (1.4.10)
|
treetop (1.4.10)
|
||||||
polyglot
|
polyglot
|
||||||
polyglot (>= 0.3.1)
|
polyglot (>= 0.3.1)
|
||||||
|
twitter (2.1.0)
|
||||||
|
activesupport (>= 2.3.9, < 4)
|
||||||
|
faraday (~> 0.7)
|
||||||
|
multi_json (~> 1.0)
|
||||||
|
simple_oauth (~> 0.1)
|
||||||
tzinfo (0.3.32)
|
tzinfo (0.3.32)
|
||||||
uglifier (1.2.4)
|
uglifier (1.2.4)
|
||||||
execjs (>= 0.3.0)
|
execjs (>= 0.3.0)
|
||||||
|
@ -103,10 +149,21 @@ PLATFORMS
|
||||||
ruby
|
ruby
|
||||||
|
|
||||||
DEPENDENCIES
|
DEPENDENCIES
|
||||||
coffee-rails (~> 3.2.1)
|
coffee-rails (~> 3.2.2)
|
||||||
|
daemons
|
||||||
|
delayed_job_active_record
|
||||||
|
eco
|
||||||
jquery-rails
|
jquery-rails
|
||||||
json
|
json
|
||||||
|
koala
|
||||||
|
mail
|
||||||
|
mime-types
|
||||||
|
omniauth
|
||||||
|
omniauth-facebook
|
||||||
|
omniauth-linkedin
|
||||||
|
omniauth-twitter
|
||||||
rails (= 3.2.2)
|
rails (= 3.2.2)
|
||||||
sass-rails (~> 3.2.3)
|
sass-rails (~> 3.2.4)
|
||||||
sqlite3
|
sqlite3
|
||||||
uglifier (>= 1.0.3)
|
twitter
|
||||||
|
uglifier (>= 1.2.3)
|
||||||
|
|
|
@ -11,26 +11,53 @@ class Index extends App.Controller
|
||||||
super
|
super
|
||||||
|
|
||||||
# check authentication
|
# check authentication
|
||||||
return if !@authenticate()
|
# return if !@authenticate()
|
||||||
|
|
||||||
# set title
|
# set title
|
||||||
@title 'Get Started'
|
@title 'Get Started'
|
||||||
|
|
||||||
@render()
|
|
||||||
|
|
||||||
@navupdate '#get_started'
|
@navupdate '#get_started'
|
||||||
|
|
||||||
render: ->
|
@master_user = 0
|
||||||
@html App.view('getting_started')(
|
|
||||||
form: @formGen( model: App.User, required: 'invite_agent' ),
|
# @render()
|
||||||
|
@fetch()
|
||||||
|
|
||||||
|
fetch: ->
|
||||||
|
|
||||||
|
# get data
|
||||||
|
@ajax = new App.Ajax
|
||||||
|
@ajax.ajax(
|
||||||
|
type: 'GET',
|
||||||
|
url: '/getting_started',
|
||||||
|
data: {
|
||||||
|
# view: @view,
|
||||||
|
}
|
||||||
|
processData: true,
|
||||||
|
success: (data, status, xhr) =>
|
||||||
|
|
||||||
|
# get meta data
|
||||||
|
@master_user = data.master_user
|
||||||
|
|
||||||
|
# load group collection
|
||||||
|
@loadCollection( type: 'Group', data: data.groups )
|
||||||
|
|
||||||
|
# load role collection
|
||||||
|
@loadCollection( type: 'Role', data: data.roles )
|
||||||
|
|
||||||
|
# render page
|
||||||
|
@render()
|
||||||
)
|
)
|
||||||
|
|
||||||
cancel: ->
|
render: ->
|
||||||
@log 'cancel....'
|
@html App.view('getting_started')(
|
||||||
@navigate 'login'
|
form_agent: @formGen( model: App.User, required: 'invite_agent' ),
|
||||||
|
form_master: @formGen( model: App.User, required: 'signup' ),
|
||||||
|
master_user: @master_user,
|
||||||
|
)
|
||||||
|
if !@master_user
|
||||||
|
@el.find('.agent_user').removeClass('hide')
|
||||||
|
|
||||||
submit: (e) ->
|
submit: (e) ->
|
||||||
@log 'submit'
|
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
@params = @formParam(e.target)
|
@params = @formParam(e.target)
|
||||||
|
|
||||||
|
@ -38,13 +65,16 @@ class Index extends App.Controller
|
||||||
if !@params.login && @params.email
|
if !@params.login && @params.email
|
||||||
@params.login = @params.email
|
@params.login = @params.email
|
||||||
|
|
||||||
# find agent role
|
|
||||||
role = App.Role.findByAttribute("name", "Agent")
|
|
||||||
@params.role_ids = role.id
|
|
||||||
|
|
||||||
# set invite flag
|
# set invite flag
|
||||||
@params.invite = true
|
@params.invite = true
|
||||||
|
|
||||||
|
# find agent role
|
||||||
|
role = App.Role.findByAttribute("name", "Agent")
|
||||||
|
if role
|
||||||
|
@params.role_ids = role.id
|
||||||
|
else
|
||||||
|
@params.role_ids = [0]
|
||||||
|
|
||||||
@log 'updateAttributes', @params
|
@log 'updateAttributes', @params
|
||||||
user = new App.User
|
user = new App.User
|
||||||
user.load(@params)
|
user.load(@params)
|
||||||
|
@ -61,14 +91,41 @@ class Index extends App.Controller
|
||||||
# send email
|
# send email
|
||||||
|
|
||||||
# clear form
|
# clear form
|
||||||
@render()
|
# @fetch()
|
||||||
|
auth = new App.Auth
|
||||||
|
auth.login(
|
||||||
|
data: {
|
||||||
|
username: @params.login,
|
||||||
|
password: @params.password,
|
||||||
|
},
|
||||||
|
success: @success
|
||||||
|
# error: @error,
|
||||||
|
)
|
||||||
# error: =>
|
# error: =>
|
||||||
# @modalHide()
|
# @modalHide()
|
||||||
)
|
)
|
||||||
|
|
||||||
Config.Routes['getting_started'] = Index
|
|
||||||
|
|
||||||
#class App.GetStarted extends App.Router
|
success: (data, status, xhr) =>
|
||||||
# routes:
|
@log 'login:success', data
|
||||||
# 'getting_started': Index
|
|
||||||
#Config.Controller.push App.GetStarted;
|
if @master_user
|
||||||
|
# login check
|
||||||
|
auth = new App.Auth
|
||||||
|
auth.loginCheck()
|
||||||
|
|
||||||
|
# add notify
|
||||||
|
Spine.trigger 'notify:removeall'
|
||||||
|
# @notify
|
||||||
|
# type: 'success',
|
||||||
|
# msg: 'Thanks for joining. Email sent to "' + @params.email + '". Please verify your email address.'
|
||||||
|
|
||||||
|
@el.find('.master_user').fadeOut('slow', =>
|
||||||
|
@el.find('.agent_user').fadeIn()
|
||||||
|
)
|
||||||
|
# redirect to #
|
||||||
|
# @navigate '#getting_started'
|
||||||
|
# @fetch()
|
||||||
|
|
||||||
|
|
||||||
|
Config.Routes['getting_started'] = Index
|
||||||
|
|
|
@ -92,6 +92,21 @@ class App.Auth extends App.Ajax
|
||||||
success: (data, status, xhr) =>
|
success: (data, status, xhr) =>
|
||||||
console.log 'logincheck:success', data
|
console.log 'logincheck:success', data
|
||||||
|
|
||||||
|
# if session is not valid
|
||||||
|
if data.error
|
||||||
|
|
||||||
|
# update config
|
||||||
|
for key, value of data.config
|
||||||
|
window.Config[key] = value
|
||||||
|
|
||||||
|
# empty session
|
||||||
|
window.Session = {}
|
||||||
|
|
||||||
|
# rebuild navbar with new navbar items
|
||||||
|
Spine.trigger 'navrebuild'
|
||||||
|
|
||||||
|
return false;
|
||||||
|
|
||||||
# set avatar
|
# set avatar
|
||||||
if !data.session.image
|
if !data.session.image
|
||||||
data.session.image = 'http://placehold.it/48x48'
|
data.session.image = 'http://placehold.it/48x48'
|
||||||
|
|
|
@ -4,12 +4,21 @@
|
||||||
<div class="container">
|
<div class="container">
|
||||||
|
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="span6">
|
<% if @master_user: %>
|
||||||
|
<div class="span6 master_user">
|
||||||
|
<h2>Master Agent</h2>
|
||||||
|
<form class="form-stacked">
|
||||||
|
<%- @form_master %>
|
||||||
|
<button class="btn-primary submit">Next...</button>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
<% end %>
|
||||||
|
<div class="span6 agent_user hide">
|
||||||
<h2>Invite Agents</h2>
|
<h2>Invite Agents</h2>
|
||||||
<form class="form-stacked">
|
<form class="form-stacked">
|
||||||
<%- @form %>
|
<%- @form_agent %>
|
||||||
|
<button class="btn-primary submit">Send Invitation</button>
|
||||||
</form>
|
</form>
|
||||||
<button class="btn-primary submit">Send Invitation</button>
|
|
||||||
</div>
|
</div>
|
||||||
<div class="span6">
|
<div class="span6">
|
||||||
<h2>Tour</h2>
|
<h2>Tour</h2>
|
||||||
|
|
28
app/controllers/getting_started_controller.rb
Normal file
28
app/controllers/getting_started_controller.rb
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
class GettingStartedController < ApplicationController
|
||||||
|
|
||||||
|
def index
|
||||||
|
|
||||||
|
# check if first user already exists
|
||||||
|
master_user = 0
|
||||||
|
count = User.all.count()
|
||||||
|
if count == 1
|
||||||
|
master_user = 1
|
||||||
|
end
|
||||||
|
|
||||||
|
# get all groups
|
||||||
|
@groups = Group.where( :active => true )
|
||||||
|
@roles = Role.where( :active => true )
|
||||||
|
|
||||||
|
# return result
|
||||||
|
respond_to do |format|
|
||||||
|
format.json {
|
||||||
|
render :json => {
|
||||||
|
:master_user => master_user,
|
||||||
|
:groups => @groups,
|
||||||
|
:roles => @roles,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
|
@ -55,16 +55,23 @@ class UsersController < ApplicationController
|
||||||
# POST /users.json
|
# POST /users.json
|
||||||
def create
|
def create
|
||||||
@user = User.new(params[:user])
|
@user = User.new(params[:user])
|
||||||
# params[:user][:role_ids] = params[:role_ids]
|
|
||||||
# logger.debug params[:user].inspect
|
|
||||||
@user.created_by_id = (current_user && current_user.id) || 1
|
@user.created_by_id = (current_user && current_user.id) || 1
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
if @user.save
|
if @user.save
|
||||||
|
|
||||||
# if it's a signup, add user to customer role
|
# if it's a signup, add user to customer role
|
||||||
if @user.created_by_id == 1
|
if @user.created_by_id == 1
|
||||||
role_id = Role.where( :name => 'Customer' ).first.id
|
|
||||||
@user.role_ids = [role_id]
|
# check if it's first user
|
||||||
|
count = User.all.count()
|
||||||
|
role_ids = []
|
||||||
|
if count <= 2
|
||||||
|
role_ids.push Role.where( :name => 'Admin' ).first.id
|
||||||
|
role_ids.push Role.where( :name => 'Agent' ).first.id
|
||||||
|
else
|
||||||
|
role_ids.push Role.where( :name => 'Customer' ).first.id
|
||||||
|
end
|
||||||
|
@user.role_ids = role_ids
|
||||||
|
|
||||||
# else do assignment as defined
|
# else do assignment as defined
|
||||||
else
|
else
|
||||||
|
@ -78,6 +85,7 @@ class UsersController < ApplicationController
|
||||||
|
|
||||||
# send inviteation if needed
|
# send inviteation if needed
|
||||||
if params[:invite]
|
if params[:invite]
|
||||||
|
|
||||||
# logger.debug('IIIIIIIIIIIIIIIIIIIIIIIIIIIIII')
|
# logger.debug('IIIIIIIIIIIIIIIIIIIIIIIIIIIIII')
|
||||||
# exit '123'
|
# exit '123'
|
||||||
end
|
end
|
||||||
|
|
|
@ -39,6 +39,9 @@ Zammad::Application.routes.draw do
|
||||||
# networks
|
# networks
|
||||||
resources :networks, :only => [:create, :show, :index, :update, :destroy]
|
resources :networks, :only => [:create, :show, :index, :update, :destroy]
|
||||||
|
|
||||||
|
# getting_started
|
||||||
|
match '/getting_started', :to => 'getting_started#index'
|
||||||
|
|
||||||
# sessions
|
# sessions
|
||||||
resources :sessions, :only => [:create, :destroy, :show]
|
resources :sessions, :only => [:create, :destroy, :show]
|
||||||
match '/signin', :to => 'sessions#create'
|
match '/signin', :to => 'sessions#create'
|
||||||
|
|
Loading…
Reference in a new issue