More advance signup flow

This commit is contained in:
2015-02-24 17:56:06 +01:00
parent 16418dde30
commit cb723ea432
19 changed files with 123 additions and 48 deletions
@@ -1,6 +1,7 @@
attr = DS.attr
App.Supplier = DS.Model.extend
name: attr 'string'
email: attr 'string'
time_zone: attr 'string'
address: attr 'string'
house_number: attr 'number'
@@ -1,5 +1,8 @@
= partial "global/top_menu"
= partial "global/side_menu"
.main-section= outlet
= view flash_message
= outlet modal
if loading
span.fa.fa-3x.fa-spinner.fa-spin
else
= partial "global/top_menu"
= partial "global/side_menu"
.main-section= outlet
= view flash_message
= outlet modal
+8 -1
View File
@@ -36,7 +36,7 @@ private
def set_locale
I18n.locale = (params[:locale].presence || I18n.default_locale).to_sym
end
def _render_with_renderer_json(resource, options)
serializer = build_json_serializer(resource, options)
@@ -55,6 +55,13 @@ private
"theme1"
end
def after_sign_in_path_for(resource)
case resource
when Employee then supplier_root_path
else root_path
end
end
def check_active_list_state
if current_user.try(:active_list_id)
unless active_list.active?
+3 -1
View File
@@ -14,7 +14,9 @@ class NewSuppliersController < ApplicationController
@new_supplier.current_employee = current_employee
if @new_supplier.save
redirect_to supplier_root_path
sign_in @new_supplier.employee unless current_employee
session[:supplier_id] = @new_supplier.supplier.try(:id)
redirect_to supplier_root_path(anchor: '/pages/introduction')
else
render 'new'
end
@@ -1,4 +1,8 @@
class RegistrationsController < Devise::RegistrationsController
protected
#def after_sign_up_path(resource)
#end
private
@@ -0,0 +1,7 @@
class Suppliers::SessionsController < Devise::SessionsController
def destroy
session[:supplier_id] = nil
super
end
end
+1 -1
View File
@@ -16,7 +16,7 @@ class Employee
end
view :by_confirmation_token, key: :confirmation_token # devise confirmable
devise :database_authenticatable, :recoverable, :rememberable, :trackable, :registerable, :confirmable
devise :database_authenticatable, :recoverable, :rememberable, :trackable #, :registerable #, :confirmable
property :unconfirmed_email
property :name
+1
View File
@@ -6,6 +6,7 @@ class Supplier
#devise :database_authenticatable, :recoverable, :rememberable, :trackable, :registerable, :confirmable
property :name
property :email
property :open, type: :boolean, default: false
property :time_zone, default: 'UTC'
property :night_offset, type: Fixnum, default: 0 # Minutes
+16 -8
View File
@@ -1,19 +1,20 @@
class NewSupplier
include ActiveAttr::Model
attr_accessor :current_employee
attr_reader :employee, :supplier
attribute :supplier_name
attribute :email
attribute :password
attribute :password_confirmation
without_current_supplier = { unless: 'current_employee.present?' }
without_current_employee = { unless: 'current_employee.present?' }
validates :supplier_name, presence: true
validates :email, email: without_current_supplier
validates :password, presence: without_current_supplier, confirmation: without_current_supplier
validates :email, email: without_current_employee
validates :password, presence: without_current_employee, confirmation: without_current_employee
validate :supplier_name_uniqueness
validate :employee_uniqueness
validate :employee_uniqueness_or_existence
def save
if valid?
@@ -27,15 +28,22 @@ class NewSupplier
private
def persist!
employee = Employee.new unconfirmed_email: email, password: password, password_confirmation: password_confirmation
@employee ||= Employee.new email: email, password: password, password_confirmation: password_confirmation
raise "Cannot create employee with #{attributes.inspect}" unless employee.save
supplier = Supplier.create name: supplier_name
@supplier = Supplier.create name: supplier_name
supplier.add_manager employee
end
def employee_uniqueness
def employee_uniqueness_or_existence
return if current_employee.present?
errors.add :email, :taken if Employee.count_by_email(email) > 0
if Employee.count_by_email(email) > 0
employee = Employee.find_by_email(email)
if employee.valid_password? password
@employee = employee
else
errors.add :email, :taken
end
end
end
def supplier_name_uniqueness
-1
View File
@@ -16,6 +16,5 @@ html lang="en"
= javascript_include_tag 'supplier/app/application'
= yield :head
/= javascript_include_tag "https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false&libraries=places&language=#{I18n.locale}"
body
#ember-app-container