Adds registration controller for organizations
This commit is contained in:
29
app/controllers/organizations/registrations_controller.rb
Normal file
29
app/controllers/organizations/registrations_controller.rb
Normal file
@@ -0,0 +1,29 @@
|
||||
class Organizations::RegistrationsController < Devise::RegistrationsController
|
||||
include RecaptchaHelper
|
||||
|
||||
def new
|
||||
super do |user|
|
||||
user.build_organization
|
||||
end
|
||||
end
|
||||
|
||||
def create
|
||||
if verify_captcha?(resource)
|
||||
super do |user|
|
||||
# Removes unuseful "organization is invalid" error message
|
||||
user.errors.messages.delete(:organization)
|
||||
end
|
||||
else
|
||||
build_resource(sign_up_params)
|
||||
flash.now[:alert] = t('recaptcha.errors.verification_failed')
|
||||
respond_with resource
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def sign_up_params
|
||||
params.require(:user).permit(:email, :password, :phone_number, :password_confirmation, organization_attributes: [:name])
|
||||
end
|
||||
|
||||
end
|
||||
64
app/views/organizations/registrations/new.html.erb
Normal file
64
app/views/organizations/registrations/new.html.erb
Normal file
@@ -0,0 +1,64 @@
|
||||
<div class="row-full auth">
|
||||
<div class="row">
|
||||
<div class="small-12 medium-8 large-5 column small-centered">
|
||||
<div class="panel">
|
||||
<h1 class="text-center"><%= t("devise_views.organizations.registrations.new.title") %></h1>
|
||||
|
||||
<%= form_for(resource, as: :user, url: organization_registration_path) do |f| %>
|
||||
|
||||
<%= devise_error_messages! %>
|
||||
|
||||
<%= f.fields_for :organization do |fo| %>
|
||||
<div class="row">
|
||||
<div class="small-12 columns">
|
||||
<%= fo.label :organization_name, t("devise_views.organizations.registrations.new.organization_name_label") %>
|
||||
<%= fo.text_field :name, autofocus: true, placeholder: t("devise_views.organizations.registrations.new.organization_name_label") %>
|
||||
</div>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
<div class="row">
|
||||
<div class="small-12 columns">
|
||||
<%= f.label :email, t("devise_views.organizations.registrations.new.email_label") %>
|
||||
<%= f.email_field :email, placeholder: t("devise_views.organizations.registrations.new.email_label") %>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="small-12 columns">
|
||||
<%= f.label :phone_number, t("devise_views.organizations.registrations.new.phone_number_label") %>
|
||||
<%= f.text_field :phone_number, placeholder: t("devise_views.organizations.registrations.new.phone_number_label") %>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="small-12 columns">
|
||||
<%= f.label :password, t("devise_views.organizations.registrations.new.password_label"), class: "inline-block" %>
|
||||
<% if @minimum_password_length %>
|
||||
<span class="inline-block"><i><%= t("devise_views.organizations.registrations.new.min_length", min: @minimum_password_length) %></i></span>
|
||||
<% end %>
|
||||
<%= f.password_field :password, autocomplete: "off", placeholder: t("devise_views.organizations.registrations.new.password_label") %>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="small-12 columns">
|
||||
<%= f.label :password_confirmation, t("devise_views.organizations.registrations.new.password_confirmation_label") %>
|
||||
<%= f.password_field :password_confirmation, autocomplete: "off", placeholder: t("devise_views.organizations.registrations.new.password_confirmation_label") %>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<%= render 'shared/captcha', resource: resource %>
|
||||
|
||||
<div class="row">
|
||||
<div class="small-12 columns">
|
||||
<%= f.submit t("devise_views.organizations.registrations.new.submit"), class: "button radius expand" %>
|
||||
</div>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
<%= render "devise/shared/links" %>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -5,6 +5,7 @@ en:
|
||||
debate: Debate
|
||||
user: User
|
||||
vote: Vote
|
||||
organization: Organization
|
||||
attributes:
|
||||
comment:
|
||||
body: Comment
|
||||
@@ -19,4 +20,6 @@ en:
|
||||
first_name: "First name"
|
||||
last_name: "Last name"
|
||||
nickname: Nickname
|
||||
password: Password
|
||||
password: Password
|
||||
organization:
|
||||
name: Organization name
|
||||
|
||||
@@ -5,6 +5,7 @@ es:
|
||||
debate: Debate
|
||||
user: Usuario
|
||||
vote: Voto
|
||||
organization: Organización
|
||||
attributes:
|
||||
comment:
|
||||
body: Comentario
|
||||
@@ -19,4 +20,6 @@ es:
|
||||
first_name: Nombre
|
||||
last_name: Apellidos
|
||||
nickname: Pseudónimo
|
||||
password: Contraseña
|
||||
password: Contraseña
|
||||
organization:
|
||||
name: Nombre de organización
|
||||
|
||||
@@ -60,6 +60,17 @@ en:
|
||||
min_length: "(%{min} characters minimum)"
|
||||
password_confirmation_label: "Confirm password"
|
||||
submit: "Sign up"
|
||||
organizations:
|
||||
registrations:
|
||||
new:
|
||||
title: "Sign up as organization"
|
||||
organization_name_label: "Organization name"
|
||||
email_label: "Email"
|
||||
password_label: "Password"
|
||||
phone_number_label: "Phone number"
|
||||
min_length: "(%{min} characters minimum)"
|
||||
password_confirmation_label: "Confirm password"
|
||||
submit: "Sign up"
|
||||
sessions:
|
||||
new:
|
||||
title: "Log in"
|
||||
@@ -77,6 +88,7 @@ en:
|
||||
login: "Log in"
|
||||
signup: "Sign up"
|
||||
signin_with_provider: "Sign in with %{provider}"
|
||||
organization_signup: "Sign up as an organization"
|
||||
new_password: "Forgot your password?"
|
||||
new_confirmation: "Didn't receive confirmation instructions?"
|
||||
new_unlock: "Didn't receive unlock instructions?"
|
||||
|
||||
@@ -60,6 +60,17 @@ es:
|
||||
min_length: "(mínimo %{min} caracteres)"
|
||||
password_confirmation_label: "Confirmar contraseña"
|
||||
submit: "Registrarse"
|
||||
organizations:
|
||||
registrations:
|
||||
new:
|
||||
title: "Registrarse como organización"
|
||||
organization_name_label: "Nombre de la organización"
|
||||
email_label: "Email"
|
||||
password_label: "Contraseña"
|
||||
phone_number_label: "Teléfono"
|
||||
min_length: "(mínimo %{min} caracteres)"
|
||||
password_confirmation_label: "Confirmar contraseña"
|
||||
submit: "Registrarse"
|
||||
sessions:
|
||||
new:
|
||||
title: "Entrar"
|
||||
@@ -76,6 +87,7 @@ es:
|
||||
links:
|
||||
login: "Entrar"
|
||||
signup: "Registrarse"
|
||||
organization_signup: "Registro para organizaciones"
|
||||
signin_with_provider: "Entrar con %{provider}"
|
||||
new_password: "¿Olvidaste tu contraseña?"
|
||||
new_confirmation: "¿No has recibido instrucciones para confirmar tu cuenta?"
|
||||
|
||||
@@ -1,5 +1,10 @@
|
||||
Rails.application.routes.draw do
|
||||
devise_for :users, controllers: { registrations: 'users/registrations' }
|
||||
devise_for :organizations, class_name: 'User',
|
||||
controllers: {
|
||||
registrations: 'organizations/registrations',
|
||||
sessions: 'devise/sessions'
|
||||
}
|
||||
|
||||
# The priority is based upon order of creation: first created -> highest priority.
|
||||
# See how all your routes lay out with "rake routes".
|
||||
|
||||
32
spec/features/organizations_spec.rb
Normal file
32
spec/features/organizations_spec.rb
Normal file
@@ -0,0 +1,32 @@
|
||||
require 'rails_helper'
|
||||
|
||||
feature 'Organizations' do
|
||||
|
||||
scenario 'Organizations can be created' do
|
||||
user = User.organizations.where(email: 'green@peace.com').first
|
||||
expect(user).to_not be
|
||||
|
||||
visit new_organization_registration_path
|
||||
|
||||
fill_in 'user_organization_attributes_name', with: 'Greenpeace'
|
||||
fill_in 'user_email', with: 'green@peace.com'
|
||||
fill_in 'user_password', with: 'greenpeace'
|
||||
fill_in 'user_password_confirmation', with: 'greenpeace'
|
||||
|
||||
click_button 'Sign up'
|
||||
|
||||
user = User.organizations.where(email: 'green@peace.com').first
|
||||
expect(user).to be
|
||||
expect(user).to be_organization
|
||||
expect(user.organization).to_not be_verified
|
||||
end
|
||||
|
||||
scenario "Organization fields are validated" do
|
||||
visit new_organization_registration_path
|
||||
click_button 'Sign up'
|
||||
|
||||
expect(page).to have_content "Email can't be blank"
|
||||
expect(page).to have_content "Password can't be blank"
|
||||
expect(page).to have_content "Organization name can't be blank"
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user