Improved getting started.

This commit is contained in:
Martin Edenhofer 2012-04-10 21:57:18 +02:00
parent 3256c6c934
commit 99e9751612
7 changed files with 210 additions and 33 deletions

View file

@ -1,5 +1,5 @@
GEM
remote: https://rubygems.org/
remote: http://rubygems.org/
specs:
actionmailer (3.2.2)
actionpack (= 3.2.2)
@ -28,6 +28,7 @@ GEM
activesupport (3.2.2)
i18n (~> 0.6)
multi_json (~> 1.0)
addressable (2.2.7)
arel (3.0.2)
builder (3.0.0)
coffee-rails (3.2.2)
@ -37,9 +38,25 @@ GEM
coffee-script-source
execjs
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)
execjs (1.3.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)
i18n (0.6.0)
journey (1.0.3)
@ -47,12 +64,35 @@ GEM
railties (>= 3.2.0, < 5.0)
thor (~> 0.14)
json (1.6.6)
koala (1.3.0)
faraday (~> 0.7.0)
multi_json (~> 1.0)
mail (2.4.4)
i18n (>= 0.4.0)
mime-types (~> 1.16)
treetop (~> 1.4.8)
mime-types (1.18)
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)
rack (1.4.1)
rack-cache (1.2)
@ -84,6 +124,7 @@ GEM
railties (~> 3.2.0)
sass (>= 3.1.10)
tilt (~> 1.3)
simple_oauth (0.1.5)
sprockets (2.1.2)
hike (~> 1.2)
rack (~> 1.0)
@ -94,6 +135,11 @@ GEM
treetop (1.4.10)
polyglot
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)
uglifier (1.2.4)
execjs (>= 0.3.0)
@ -103,10 +149,21 @@ PLATFORMS
ruby
DEPENDENCIES
coffee-rails (~> 3.2.1)
coffee-rails (~> 3.2.2)
daemons
delayed_job_active_record
eco
jquery-rails
json
koala
mail
mime-types
omniauth
omniauth-facebook
omniauth-linkedin
omniauth-twitter
rails (= 3.2.2)
sass-rails (~> 3.2.3)
sass-rails (~> 3.2.4)
sqlite3
uglifier (>= 1.0.3)
twitter
uglifier (>= 1.2.3)

View file

@ -11,26 +11,53 @@ class Index extends App.Controller
super
# check authentication
return if !@authenticate()
# return if !@authenticate()
# set title
@title 'Get Started'
@render()
@navupdate '#get_started'
@master_user = 0
# @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()
)
render: ->
@html App.view('getting_started')(
form: @formGen( model: App.User, required: 'invite_agent' ),
form_agent: @formGen( model: App.User, required: 'invite_agent' ),
form_master: @formGen( model: App.User, required: 'signup' ),
master_user: @master_user,
)
cancel: ->
@log 'cancel....'
@navigate 'login'
if !@master_user
@el.find('.agent_user').removeClass('hide')
submit: (e) ->
@log 'submit'
e.preventDefault()
@params = @formParam(e.target)
@ -38,13 +65,16 @@ class Index extends App.Controller
if !@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
@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
user = new App.User
user.load(@params)
@ -61,14 +91,41 @@ class Index extends App.Controller
# send email
# clear form
@render()
# @fetch()
auth = new App.Auth
auth.login(
data: {
username: @params.login,
password: @params.password,
},
success: @success
# error: @error,
)
# error: =>
# @modalHide()
)
Config.Routes['getting_started'] = Index
#class App.GetStarted extends App.Router
# routes:
# 'getting_started': Index
#Config.Controller.push App.GetStarted;
success: (data, status, xhr) =>
@log 'login:success', data
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

View file

@ -92,6 +92,21 @@ class App.Auth extends App.Ajax
success: (data, status, xhr) =>
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
if !data.session.image
data.session.image = 'http://placehold.it/48x48'

View file

@ -4,12 +4,21 @@
<div class="container">
<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>
<form class="form-stacked">
<%- @form %>
<%- @form_agent %>
<button class="btn-primary submit">Send Invitation</button>
</form>
<button class="btn-primary submit">Send Invitation</button>
</div>
<div class="span6">
<h2>Tour</h2>

View 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

View file

@ -55,16 +55,23 @@ class UsersController < ApplicationController
# POST /users.json
def create
@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
respond_to do |format|
if @user.save
# if it's a signup, add user to customer role
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
@ -78,6 +85,7 @@ class UsersController < ApplicationController
# send inviteation if needed
if params[:invite]
# logger.debug('IIIIIIIIIIIIIIIIIIIIIIIIIIIIII')
# exit '123'
end

View file

@ -39,6 +39,9 @@ Zammad::Application.routes.draw do
# networks
resources :networks, :only => [:create, :show, :index, :update, :destroy]
# getting_started
match '/getting_started', :to => 'getting_started#index'
# sessions
resources :sessions, :only => [:create, :destroy, :show]
match '/signin', :to => 'sessions#create'