Skip to content

Commit

Permalink
Create SignUp component
Browse files Browse the repository at this point in the history
  • Loading branch information
vpereira committed Sep 15, 2021
1 parent da9417c commit b3a7fb6
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 0 deletions.
29 changes: 29 additions & 0 deletions src/api/app/components/sign_up_component.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
- if proxy_auth_enabled?
- if proxy_auth_register_page.blank?
%p Sorry, signing up is currently disabled
- else
%p= link_to 'Use this link to Sign Up', proxy_auth_register_page
- else
= form_tag(users_path, method: :post, class: 'sign-up', autocomplete: 'off') do
.form-group
= label_tag 'login', 'Username:'
%abbr.text-danger{ title: 'required' } *
= text_field_tag 'login', nil, placeholder: 'Username', autocomplete: 'off', class: 'form-control', required: true
.form-group
= label_tag 'email', 'Email:'
%abbr.text-danger{ title: 'required' } *
= text_field_tag 'email', nil, placeholder: 'Email address', autocomplete: 'off', class: 'form-control', type: 'email', required: true
.form-group
= label_tag 'password', 'Password:'
%abbr.text-danger{ title: 'required' } *
= password_field_tag :password, nil, id: 'pwd', placeholder: 'Enter a password', autocomplete: 'off', class: 'form-control', required: true
.form-group
= label_tag 'password_confirmation', 'Password confirmation:'
%abbr.text-danger{ title: 'required' } *
= password_field_tag(:password_confirmation, nil, id: 'pwd_confirmation', placeholder: 'Password confirmation', autocomplete: 'off',
class: 'form-control', required: true)
= hidden_field_tag 'register', 'true'
= submit_tag submit_btn_text, class: 'btn btn-primary'
- unless User.session
or
= link_to('Log In', new_session_path)
20 changes: 20 additions & 0 deletions src/api/app/components/sign_up_component.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# frozen_string_literal: true

class SignUpComponent < ApplicationComponent
attr_accessor :submit_btn_text

def initialize(submit_btn_text: 'Sign Up', create_page: false, config: CONFIG)
super

@config = config
@submit_btn_text = sanitize(create_page ? 'Create' : submit_btn_text)
end

def proxy_auth_enabled?
@config['proxy_auth_mode'] == :on
end

def proxy_auth_register_page
@config['proxy_auth_register_page']
end
end
19 changes: 19 additions & 0 deletions src/api/spec/components/sign_up_component_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
require 'rails_helper'

RSpec.describe SignUpComponent, type: :component do
context 'signing up disabled' do
let(:config) { { 'proxy_auth_mode' => :on } }

it do
expect(render_inline(described_class.new(config: config)).to_html).to have_text('signing up is currently disabled')
end

context 'there is a proxy auth register page' do
let(:config) { { 'proxy_auth_mode' => :on, 'proxy_auth_register_page' => 'http://foo.org' } }

it do
expect(render_inline(described_class.new(config: config)).to_html).to have_text('Use this link to Sign Up')
end
end
end
end

0 comments on commit b3a7fb6

Please sign in to comment.