Sha256: ed2adec3b3191c2897c4ed4f7cda5fbd348881c97b57824a1cc20f8c44d68206

Contents?: true

Size: 1.46 KB

Versions: 69

Compression:

Stored size: 1.46 KB

Contents

require_dependency "mtdevise/application_controller"

module Mtdevise
	class AccountsController < ApplicationController

		# Layouts and Filters
		layout :layouts_resolver_accounts
		before_action :redirect_if_coming_form_sign_up, only: :new
		before_action :authenticate_user!, except: [:new, :create]

		# Accounts Index
		def index
			@accounts = current_user.accounts
		end

		# Accounts Registration
		def new
			@account = Mtdevise::Account.new
			@account.build_owner unless user_signed_in?
		end

		# Accounts Create action
		def create
			account = if user_signed_in?
			Mtdevise::Account.create(account_params)
			else
				Mtdevise::Account.create_with_owner(account_params)
			end
		
			@account = account
			if account.valid?
				flash[:success] = "Your account has been successfully created."

			if user_signed_in?
				account.owner = current_user
				account.users << current_user
				account.save
				redirect_to mtdevise.accounts_path

			else
				sign_in account.owner
				redirect_to mtdevise.root_url(:subdomain => account.subdomain)
			end

			else
				flash[:error] = "Sorry, your account could not be created."
				render :new
			end

		end

		private

		def redirect_if_coming_form_sign_up
			redirect_to accounts_path if request.url =~ /#{sign_up_path}/ && user_signed_in?
		end

		def account_params
			params.require(:account).permit(:name, :firstname, :lastname, :username, :subdomain, { :owner_attributes => [:email, :password, :password_confirmation]})
		end

	end
end

Version data entries

69 entries across 69 versions & 1 rubygems

Version Path
mtdevise-3.8.1 app/controllers/mtdevise/accounts_controller.rb
mtdevise-3.8.0 app/controllers/mtdevise/accounts_controller.rb
mtdevise-3.7.0 app/controllers/mtdevise/accounts_controller.rb
mtdevise-3.6.2 app/controllers/mtdevise/accounts_controller.rb
mtdevise-3.6.1 app/controllers/mtdevise/accounts_controller.rb
mtdevise-3.6.0 app/controllers/mtdevise/accounts_controller.rb
mtdevise-3.5.11 app/controllers/mtdevise/accounts_controller.rb
mtdevise-3.5.10 app/controllers/mtdevise/accounts_controller.rb
mtdevise-3.5.9 app/controllers/mtdevise/accounts_controller.rb
mtdevise-3.5.8 app/controllers/mtdevise/accounts_controller.rb
mtdevise-3.5.7 app/controllers/mtdevise/accounts_controller.rb
mtdevise-3.5.5 app/controllers/mtdevise/accounts_controller.rb
mtdevise-3.5.1 app/controllers/mtdevise/accounts_controller.rb
mtdevise-3.5.0 app/controllers/mtdevise/accounts_controller.rb
mtdevise-3.0.4 app/controllers/mtdevise/accounts_controller.rb
mtdevise-3.0.2 app/controllers/mtdevise/accounts_controller.rb
mtdevise-3.0.0 app/controllers/mtdevise/accounts_controller.rb
mtdevise-2.7.0 app/controllers/mtdevise/accounts_controller.rb
mtdevise-2.6.6 app/controllers/mtdevise/accounts_controller.rb
mtdevise-2.6.5 app/controllers/mtdevise/accounts_controller.rb