simply_auth 0.6.0 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0001e3ce2a6ca0f68b35de04fde16ccf62818250f061efedaf6139b4037b7839
4
- data.tar.gz: 9126aeca9a3e00085c1991d0bdf80017cb7098b950bc25139b391fd7881443c3
3
+ metadata.gz: 750533d97a9a4c3cf78e8edbba37de4de5747551c95de6635dddf1b296b1f067
4
+ data.tar.gz: 1ac2b5510e6fddeaa74aa5ea27e1c31f2e15554c7c572bec4cf8b116e2ccef1e
5
5
  SHA512:
6
- metadata.gz: d9b60106600ae9cd02ff8d8d265d8b4bca505eba968218ded87244f7033b2636a5938d3abb30e4e2cad232acd84ebe41a79ae16a101e08342f4d7e1355bcad10
7
- data.tar.gz: 437797106a7e8ab995a3ca3127f9332885529702c1a12397de0c4ceedc3b7ef1ae831a325029b31c347310a155a3bcfefe5cb1ce067ad6098dc5bab3fa3f643e
6
+ metadata.gz: 8c1954bf11a7d3c6e2e8660dcf53376e5e6143d476a03197a9fa83277a6fcc21a21e5c1380e427e98ecdedb91ef0c7116c657bef52e05234f9f87eb125f77dba
7
+ data.tar.gz: 5cd9bef3147731ad68e3563e121b1ea51a1d39a8771f940851456c8bfb42bed99222d3f1d5caadf52b31b7c057ac2dc042ca98845e7b4abec3b9aafee7f7e245
@@ -1,7 +1,8 @@
1
1
  module SimplyAuth
2
2
  class RegistrationsController < ApplicationController
3
+ before_action :load_signup_form
3
4
  def new
4
- @user = SimplyAuth::User.new
5
+ @html = @step["html"].gsub("/registrations", registrations_path(form: @signup_form.id))
5
6
  end
6
7
 
7
8
  def index
@@ -12,23 +13,65 @@ module SimplyAuth
12
13
  def after_registration(user); end
13
14
 
14
15
  def create
15
- @user = SimplyAuth::User.new(user_params)
16
- if @user.save
16
+ session["simply_auth_form_submission"] ||= {}
17
+ if (session["simply_auth_form_submission"]["id"] != @signup_form.id)
18
+ session["simply_auth_form_submission"] = {}
19
+ end
20
+ session["simply_auth_form_submission"]["id"] = @signup_form.id
21
+ session["simply_auth_form_submission"]["attributes"] ||= {}
22
+ user_params = user_params(@step["attributes"])
23
+ user_params.each do |k, v|
24
+ v = v.to_h if v.respond_to?(:to_h)
25
+ session["simply_auth_form_submission"]["attributes"][k] = v
26
+ end
27
+ if @step == @signup_form.steps.last
28
+ @user = SimplyAuth::User.new(session["simply_auth_form_submission"]["attributes"])
29
+ @user.save
17
30
  after_registration(@user)
18
-
19
- @session = SimplyAuth::Session.new(email: user_params[:email], password: user_params[:password])
31
+
32
+ @session = SimplyAuth::Session.new(email: @user.email, password: session["simply_auth_form_submission"]["attributes"]["password"])
20
33
  @session.save
34
+ session.delete("simply_auth_form_submission")
21
35
  session[:simply_auth_session_id] = @session.id
22
36
  redirect_to "/"
23
37
  else
24
- render :new
38
+ redirect_to new_registration_path(form: @signup_form.id)
25
39
  end
26
40
  end
27
41
 
28
42
  private
29
43
 
30
- def user_params
31
- params.require(:user).permit(:name, :email, :password, data: params[:user][:data].try(:keys))
44
+ def user_params(step_attributes)
45
+ permissions = []
46
+ data_attributes = []
47
+ step_attributes.each do |attribute|
48
+ if attribute.starts_with?("data.")
49
+ data_attributes.push(attribute.gsub("data.", ""))
50
+ else
51
+ permissions << attribute
52
+ end
53
+ end
54
+ if data_attributes.any?
55
+ permissions.push(data: data_attributes)
56
+ end
57
+ params.require(:user).permit(permissions)
58
+ end
59
+
60
+ def load_signup_form
61
+ @user_pool = SimplyAuth::UserPool.find(SimplyAuth::Config.user_pool_id)
62
+ forms = SimplyAuth::SignupForm.all(@user_pool.application_id)
63
+ @signup_form = params[:form] ? forms.find{|f| f.id == params[:form]} : forms.first
64
+ session["simply_auth_form_submission"] ||= {}
65
+ session["simply_auth_form_submission"]["attributes"] ||= {}
66
+ @step = @signup_form.steps.find do |s|
67
+ s["attributes"].any? do |attribute|
68
+ if attribute.starts_with?("data.")
69
+ session["simply_auth_form_submission"]["attributes"]["data"][attribute.gsub("data.", "")].blank?
70
+ else
71
+ session["simply_auth_form_submission"]["attributes"][attribute].blank?
72
+ end
73
+ end
74
+ end
32
75
  end
33
76
  end
34
77
  end
@@ -1,9 +1,9 @@
1
1
  module SimplyAuth
2
2
  class UserPool < Model
3
3
  validates :name, presence: true
4
- attr_accessor :name
4
+ attr_accessor :name, :application_id
5
5
  def attributes
6
- super.merge(name: name)
6
+ super.merge(name: name, application_id: application_id)
7
7
  end
8
8
 
9
9
  def self.instance_path(ids = [])
@@ -1,72 +1 @@
1
- <div class='container'>
2
- <div class='d-flex flex-row'>
3
- <h2 class='mr-auto'>Sign Up</h2>
4
- <div>
5
- <span class='mr-2'>Already a member?</span>
6
- <%= link_to "Log In", new_session_path, class: "btn btn-secondary" %>
7
- </div>
8
- </div>
9
- <%= form_for @user, url: [:registrations], html: {class: "needs-validation", novalidate: true} do |f| %>
10
- <div class='form-group'>
11
- <%= f.label :name, "Name *" %>
12
- <%= f.text_field :name, class: "form-control #{"is-invalid" if @user.errors[:name].any? }", required: true %>
13
- <div class='invalid-feedback'>
14
- <% if @user.errors[:name].any? %>
15
- <%= @user.errors[:name].map{|m| "Name #{m}."}.join(" ") %>
16
- <% else %>
17
- Please provide your name.
18
- <% end %>
19
- </div>
20
- </div>
21
- <div class='form-group'>
22
- <%= f.label :email, "Email *" %>
23
- <%= f.text_field :email, class: "form-control #{"is-invalid" if @user.errors[:email].any? }", required: true, type: :email %>
24
- <div class='invalid-feedback'>
25
- <% if @user.errors[:email].grep(/taken/).any? %>
26
- That email is already registered. Would you like to <%= link_to "sign in", new_session_path(session: {email: @user.email}) %>?
27
- <% elsif @user.errors[:email].any? %>
28
- <%= @user.errors[:email].map{|m| "Email #{m}."}.join(" ") %>
29
- <% else %>
30
- Please provide your email.
31
- <% end %>
32
- </div>
33
- </div>
34
- <div class='form-group'>
35
- <%= f.label :password, "Password *" %>
36
- <%= f.password_field :password, class: "form-control #{"is-invalid" if @user.errors[:password].any? }", required: true %>
37
- <div class='invalid-feedback'>
38
- <% if @user.errors[:password].any? %>
39
- <%= @user.errors[:password].map{|m| "Password #{m}."}.join(" ") %>
40
- <% else %>
41
- Please provide a password.
42
- <% end %>
43
- </div>
44
- </div>
45
- <%= render partial: "additional_fields", locals: {form: f} %>
46
- <%= f.submit "Sign Up", class: "btn btn-primary" %>
47
- <% end %>
48
-
49
- <script>
50
- (function() {
51
- 'use strict';
52
- window.addEventListener('load', function() {
53
- var forms = document.getElementsByClassName('needs-validation');
54
- var validation = Array.prototype.filter.call(forms, function(form) {
55
- form.addEventListener('submit', function(event) {
56
- if (form.checkValidity() === false) {
57
- event.preventDefault();
58
- event.stopPropagation();
59
- }
60
- form.classList.add('was-validated');
61
- }, false);
62
- });
63
- }, false);
64
- })();
65
- </script>
66
- <style>
67
- .field_with_errors ~ .invalid-feedback,
68
- .field_with_errors ~ .invalid-tooltip {
69
- display: block;
70
- }
71
- </style>
72
- </div>
1
+ <%= @html.html_safe %>
@@ -0,0 +1,72 @@
1
+ <div class='container'>
2
+ <div class='d-flex flex-row'>
3
+ <h2 class='mr-auto'>Sign Up</h2>
4
+ <div>
5
+ <span class='mr-2'>Already a member?</span>
6
+ <%= link_to "Log In", new_session_path, class: "btn btn-secondary" %>
7
+ </div>
8
+ </div>
9
+ <%= form_for @user, url: [:registrations], html: {class: "needs-validation", novalidate: true} do |f| %>
10
+ <div class='form-group'>
11
+ <%= f.label :name, "Name *" %>
12
+ <%= f.text_field :name, class: "form-control #{"is-invalid" if @user.errors[:name].any? }", required: true %>
13
+ <div class='invalid-feedback'>
14
+ <% if @user.errors[:name].any? %>
15
+ <%= @user.errors[:name].map{|m| "Name #{m}."}.join(" ") %>
16
+ <% else %>
17
+ Please provide your name.
18
+ <% end %>
19
+ </div>
20
+ </div>
21
+ <div class='form-group'>
22
+ <%= f.label :email, "Email *" %>
23
+ <%= f.text_field :email, class: "form-control #{"is-invalid" if @user.errors[:email].any? }", required: true, type: :email %>
24
+ <div class='invalid-feedback'>
25
+ <% if @user.errors[:email].grep(/taken/).any? %>
26
+ That email is already registered. Would you like to <%= link_to "sign in", new_session_path(session: {email: @user.email}) %>?
27
+ <% elsif @user.errors[:email].any? %>
28
+ <%= @user.errors[:email].map{|m| "Email #{m}."}.join(" ") %>
29
+ <% else %>
30
+ Please provide your email.
31
+ <% end %>
32
+ </div>
33
+ </div>
34
+ <div class='form-group'>
35
+ <%= f.label :password, "Password *" %>
36
+ <%= f.password_field :password, class: "form-control #{"is-invalid" if @user.errors[:password].any? }", required: true %>
37
+ <div class='invalid-feedback'>
38
+ <% if @user.errors[:password].any? %>
39
+ <%= @user.errors[:password].map{|m| "Password #{m}."}.join(" ") %>
40
+ <% else %>
41
+ Please provide a password.
42
+ <% end %>
43
+ </div>
44
+ </div>
45
+ <%= render partial: "additional_fields", locals: {form: f} %>
46
+ <%= f.submit "Sign Up", class: "btn btn-primary" %>
47
+ <% end %>
48
+
49
+ <script>
50
+ (function() {
51
+ 'use strict';
52
+ window.addEventListener('load', function() {
53
+ var forms = document.getElementsByClassName('needs-validation');
54
+ var validation = Array.prototype.filter.call(forms, function(form) {
55
+ form.addEventListener('submit', function(event) {
56
+ if (form.checkValidity() === false) {
57
+ event.preventDefault();
58
+ event.stopPropagation();
59
+ }
60
+ form.classList.add('was-validated');
61
+ }, false);
62
+ });
63
+ }, false);
64
+ })();
65
+ </script>
66
+ <style>
67
+ .field_with_errors ~ .invalid-feedback,
68
+ .field_with_errors ~ .invalid-tooltip {
69
+ display: block;
70
+ }
71
+ </style>
72
+ </div>
@@ -1,3 +1,3 @@
1
1
  module SimplyAuth
2
- VERSION = '0.6.0'
2
+ VERSION = '0.7.0'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simply_auth
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Fogle
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-03-16 00:00:00.000000000 Z
11
+ date: 2018-03-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -88,6 +88,7 @@ files:
88
88
  - app/views/simply_auth/passwords/new.html.erb
89
89
  - app/views/simply_auth/registrations/_additional_fields.html.erb
90
90
  - app/views/simply_auth/registrations/new.html.erb
91
+ - app/views/simply_auth/registrations/old-new.html.erb
91
92
  - app/views/simply_auth/sessions/new.html.erb
92
93
  - config/routes.rb
93
94
  - lib/simply_auth.rb