Commit 0a3c624

mo <mo.khan@gmail.com>
2017-12-24 23:28:34
add registration page.
1 parent 39d16f1
Changed files (9)
app/assets/javascripts/application.js
@@ -10,6 +10,7 @@
 // Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
 // about supported directives.
 //
+//= require jquery
 //= require bootstrap
 //= require rails-ujs
 //= require turbolinks
app/controllers/registrations_controller.rb
@@ -0,0 +1,16 @@
+class RegistrationsController < ApplicationController
+  def new
+    @user = User.new
+  end
+
+  def create
+    User.create!(user_params)
+    redirect_to new_session_path
+  end
+
+  private
+
+  def user_params
+    params.require(:user).permit(:email, :password)
+  end
+end
app/models/user.rb
@@ -1,5 +1,7 @@
 class User < ApplicationRecord
   has_secure_password
+  validates :email, presence: true, email: true, uniqueness: true
+
   after_initialize do
     self.uuid = SecureRandom.uuid unless self.uuid
   end
app/views/registrations/new.html.erb
@@ -0,0 +1,18 @@
+<div class="container">
+  <div class="row">
+    <div class="col">
+      <h1>Register</h1>
+
+      <%= form_for @user, url: registrations_path, method: :post do |form| %>
+        <div class="form-group">
+          <%= form.email_field :email, class: 'form-control', placeholder: User.human_attribute_name(:email), autofocus: true, required: :required %>
+        </div>
+        <div class="form-group">
+          <%= form.password_field :password, class: 'form-control', placeholder: User.human_attribute_name(:password), required: :required %>
+        </div>
+        <%= form.button t('.register'), type: 'submit', class: 'btn btn-primary', data: { disable_with: t('.loading') } %>
+        <%= link_to "Login", new_session_path %>
+      <% end %>
+    </div>
+  </div>
+</div>
app/views/sessions/new.html.erb
@@ -10,6 +10,7 @@
           <%= form.password_field :password, class: 'form-control', placeholder: User.human_attribute_name(:password), required: :required %>
         </div>
         <%= form.button t('.login'), type: 'submit', class: 'btn btn-primary', data: { disable_with: t('.loading') } %>
+        <%= link_to "Register", new_registration_path %>
       <% end %>
 
       <%= debug @saml_request.try(:to_xhtml) %>
config/locales/en.yml
@@ -31,3 +31,6 @@
 
 en:
   hello: "Hello world"
+  registrations:
+    new:
+      register: "Register"
config/routes.rb
@@ -5,5 +5,6 @@ Rails.application.routes.draw do
   post "/session/new" => "sessions#new"
   resource :metadata, only: [:show]
   resource :dashboard, only: [:show]
+  resources :registrations, only: [:new, :create]
   root to: "sessions#new"
 end
Gemfile
@@ -62,6 +62,8 @@ end
 gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
 gem 'dotenv-rails'
 gem 'saml-kit', '0.2.18'
+gem 'rails-assets-jquery', source: 'https://rails-assets.org'
 gem 'rails-assets-bootstrap', source: 'https://rails-assets.org'
 gem 'jwt'
 gem 'activerecord-session_store'
+gem "email_validator"
Gemfile.lock
@@ -77,6 +77,8 @@ GEM
     dotenv-rails (2.2.1)
       dotenv (= 2.2.1)
       railties (>= 3.2, < 5.2)
+    email_validator (1.6.0)
+      activemodel
     erubi (1.7.0)
     execjs (2.7.0)
     ffaker (2.7.0)
@@ -250,6 +252,7 @@ DEPENDENCIES
   capybara (~> 2.13)
   coffee-rails (~> 4.2)
   dotenv-rails
+  email_validator
   ffaker
   jbuilder (~> 2.5)
   jwt
@@ -258,6 +261,7 @@ DEPENDENCIES
   puma (~> 3.7)
   rails (~> 5.1.4)
   rails-assets-bootstrap!
+  rails-assets-jquery!
   rails-controller-testing
   rails_12factor
   rspec-rails (~> 3.6)