Skip to content

Commit c906062

Browse files
authored
Merge pull request #112 from tms-phillips/bug/issue-108
Bug/issue 108
2 parents d427864 + 13297aa commit c906062

26 files changed

+243
-68
lines changed

app/assets/stylesheets/login.scss

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
.page-sessions.action-new,
22
.page-sessions.action-create,
33
.page-passwords.action-new,
4-
.page-passwords.action-edit {
4+
.page-passwords.action-edit,
5+
.page-confirmations.action-new {
56
padding-top: 25px;
67

78
.logos-asterisk {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# frozen_string_literal: true
2+
3+
class ConfirmationsController < Devise::ConfirmationsController
4+
before_action :require_unconfirmed!
5+
6+
def new
7+
super
8+
9+
resource.email = current_user.unconfirmed_email || current_user.email if user_signed_in?
10+
end
11+
12+
private
13+
14+
def require_unconfirmed!
15+
if user_signed_in? && current_user.confirmed? && current_user.unconfirmed_email.blank?
16+
redirect_to getting_started_path
17+
end
18+
end
19+
20+
def after_confirmation_path_for(_resource_name, resource)
21+
sign_in(resource)
22+
getting_started_path
23+
end
24+
25+
def after_resending_confirmation_instructions_path_for(_resource_name)
26+
login_path
27+
end
28+
29+
end

app/controllers/people_controller.rb

+1-2
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@ class PeopleController < ApplicationController
1515
respond_to :json, :only => [:index, :show]
1616

1717
rescue_from ActiveRecord::RecordNotFound do
18-
render :file => Rails.root.join('public', '404').to_s,
19-
:format => :html, :layout => false, :status => 404
18+
head :not_found
2019
end
2120

2221
rescue_from Diaspora::AccountClosed do

app/controllers/registrations_controller.rb

+37-24
Original file line numberDiff line numberDiff line change
@@ -6,33 +6,53 @@
66

77
class RegistrationsController < Devise::RegistrationsController
88
before_action :check_registrations_open_or_valid_invite!, except: :registrations_closed
9-
9+
before_action :configure_sign_up_params, only: [:create]
1010
layout -> { request.format == :mobile ? "application" : "with_header_with_footer" }
1111

1212
def create
13-
@user = User.build(user_params)
14-
15-
if @user.sign_up
16-
flash[:notice] = t("registrations.create.success")
17-
@user.process_invite_acceptence(invite) if invite.present?
18-
@user.seed_aspects
19-
@user.send_welcome_message
20-
WelcomeMailer.send_welcome_email(@user).deliver_now
21-
sign_in_and_redirect(:user, @user)
22-
logger.info "event=registration status=successful user=#{@user.diaspora_handle}"
23-
else
24-
@user.errors.delete(:person)
25-
26-
flash.now[:error] = @user.errors.full_messages.join(" - ")
27-
logger.info "event=registration status=failure errors='#{@user.errors.full_messages.join(', ')}'"
28-
render action: "new"
13+
build_resource(sign_up_params)
14+
raise unless resource.check_and_verify_captcha?
15+
super
16+
if resource.persisted?
17+
resource.process_invite_acceptence(invite) if invite.present?
18+
resource.seed_aspects
2919
end
20+
rescue
21+
resource.errors.delete(:person)
22+
flash.now[:error] = resource.errors.full_messages.join(" - ")
23+
logger.info "event=registration status=failure errors='#{resource.errors.full_messages.join(', ')}'"
24+
render action: "new"
3025
end
3126

3227
def registrations_closed
3328
render "registrations/registrations_closed"
3429
end
3530

31+
protected
32+
33+
def build_resource(hash = nil)
34+
super(hash)
35+
return if hash.nil? # return for 'new'
36+
resource.language = hash[:language]
37+
resource.language ||= I18n.locale.to_s
38+
resource.color_theme = hash[:color_theme]
39+
resource.color_theme ||= AppConfig.settings.default_color_theme
40+
resource.set_person(Person.new((hash[:person] || {}).except(:id)))
41+
resource.generate_keys
42+
resource.valid?
43+
errors = resource.errors
44+
errors.delete :person
45+
return if errors.size > 0
46+
end
47+
48+
def configure_sign_up_params
49+
devise_parameter_sanitizer.permit(:sign_up, keys: [:username, :email, :getting_started, :password, :password_confirmation, :language, :disable_mail, :show_community_spotlight_in_stream, :auto_follow_back, :auto_follow_back_aspect_id, :remember_me, :captcha, :captcha_key])
50+
end
51+
52+
def after_inactive_sign_up_path_for(_resource)
53+
login_path
54+
end
55+
3656
private
3757

3858
def check_registrations_open_or_valid_invite!
@@ -48,11 +68,4 @@ def invite
4868

4969
helper_method :invite
5070

51-
def user_params
52-
params.require(:user).permit(
53-
:username, :email, :getting_started, :password, :password_confirmation, :language, :disable_mail,
54-
:show_community_spotlight_in_stream, :auto_follow_back, :auto_follow_back_aspect_id,
55-
:remember_me, :captcha, :captcha_key
56-
)
57-
end
5871
end

app/helpers/sessions_helper.rb

+4
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ def display_password_reset_link?
1818
AppConfig.mail.enable? && devise_mapping.recoverable? && controller_name != "passwords"
1919
end
2020

21+
def display_confirmation_link?
22+
devise_mapping.confirmable? && controller_name != "confirmations"
23+
end
24+
2125
def flash_class(name)
2226
{notice: "success", alert: "danger", error: "danger"}[name.to_sym]
2327
end

app/models/user.rb

+18-2
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class User < ApplicationRecord
2828
otp_backup_code_length: 16,
2929
otp_number_of_backup_codes: 10
3030

31-
devise :registerable,
31+
devise :registerable, :confirmable,
3232
:recoverable, :rememberable, :trackable, :validatable,
3333
:lockable, :lastseenable, :lock_strategy => :none, :unlock_strategy => :none
3434

@@ -117,6 +117,7 @@ def unread_message_count
117117
def process_invite_acceptence(invite)
118118
self.invited_by = invite.user
119119
invite.use! unless AppConfig.settings.enable_registrations?
120+
save
120121
end
121122

122123
def invitation_code
@@ -550,6 +551,10 @@ def closed_account?
550551
person.closed_account
551552
end
552553

554+
def postpone_email_change?
555+
false
556+
end
557+
553558
def clear_account!
554559
clearable_fields.each do |field|
555560
self[field] = nil
@@ -579,6 +584,10 @@ def sign_up
579584
end
580585
end
581586

587+
def check_and_verify_captcha?
588+
AppConfig.settings.captcha.enable? ? valid_with_captcha? : true
589+
end
590+
582591
def flag_for_removal(remove_after)
583592
# flag inactive user for future removal
584593
if AppConfig.settings.maintenance.remove_old_users.enable?
@@ -599,13 +608,20 @@ def remember_me
599608
true
600609
end
601610

611+
protected
612+
613+
def after_confirmation
614+
self.send_welcome_message
615+
WelcomeMailer.send_welcome_email(self).deliver_now
616+
end
617+
602618
private
603619

604620
def clearable_fields
605621
attributes.keys - %w(id username encrypted_password created_at updated_at locked_at
606622
serialized_private_key getting_started
607623
disable_mail show_community_spotlight_in_stream
608624
strip_exif email remove_after export exporting
609-
exported_photos_file exporting_photos)
625+
exported_photos_file exporting_photos confirmed_at)
610626
end
611627
end

app/views/confirmations/_form.haml

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
= form_for resource, as: resource_name,
2+
url: confirmation_path(resource_name),
3+
html: {method: :post, class: "block-form"},
4+
autocomplete: "off" do |f|
5+
%fieldset
6+
- if mobile
7+
%legend
8+
= image_tag("branding/logos/header-logo2x.png", height: 40, width: 40)
9+
= AppConfig.settings.pod_name
10+
11+
- if mobile
12+
= f.label :email, t("registrations.new.email"), class: "control-label", id: "emailLabel"
13+
- else
14+
= f.label :email, t("registrations.new.email"), class: "sr-only control-label", id: "emailLabel"
15+
%i.entypo-mail
16+
= f.email_field :email,
17+
autofocus: true,
18+
class: "input-block-level form-control",
19+
data: {content: t("users.edit.your_email_private")},
20+
placeholder: t("registrations.new.email"),
21+
required: true,
22+
title: t("registrations.new.enter_email"),
23+
aria: {labelledby: "emailLabel"}
24+
25+
26+
= f.submit t("devise.confirmations.new.resend_confirmation"), class: "btn btn-large btn-block btn-primary"

app/views/confirmations/new.haml

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
- content_for :page_title do
2+
= AppConfig.settings.pod_name + " - " + t('devise.confirmations.new.resend_confirmation')
3+
4+
.container#login
5+
.text-center
6+
.logos-asterisk
7+
%h1
8+
= AppConfig.settings.pod_name
9+
10+
= render partial: "form", locals: {mobile: false}
11+
12+
.text-center
13+
- if display_password_reset_link?
14+
= link_to t('devise.shared.links.forgot_your_password'), new_password_path(resource_name), id: "forgot_password_link"
15+
%br
16+
- if display_registration_link?
17+
= link_to t('devise.shared.links.sign_up'), new_registration_path(resource_name)
+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
.stream#main-stream
2+
- flash.each do |name, msg|
3+
.expose#flash-container
4+
.flash-message{class: "message alert alert-#{flash_class name}", role: "alert"}
5+
= msg
6+
7+
.login-form
8+
.login-container
9+
= render partial: "form", locals: {mobile: true}
10+
11+
%footer.footer
12+
%ul
13+
- if display_password_reset_link?
14+
%li
15+
= link_to t("devise.shared.links.forgot_your_password"),
16+
new_password_path(resource_name),
17+
id: "forgot_password_link"
18+
- if display_registration_link?
19+
%li= link_to t("devise.shared.links.sign_up"), new_registration_path(resource_name)
20+
%li= link_to t("layouts.application.switch_to_standard_mode"), toggle_mobile_path

app/views/sessions/new.html.haml

+5
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@
1010
= render partial: "form", locals: {mobile: false}
1111

1212
.text-center
13+
- if display_confirmation_link?
14+
= link_to t('devise.shared.links.receive_confirmation'), new_confirmation_path(resource_name)
15+
%br
16+
OR
17+
%br
1318
- if display_password_reset_link?
1419
= link_to t('devise.shared.links.forgot_your_password'), new_password_path(resource_name), id: "forgot_password_link"
1520
%br

app/views/sessions/new.mobile.haml

+3
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414

1515
%footer.footer
1616
%ul
17+
- if display_confirmation_link?
18+
%li= link_to t('devise.shared.links.receive_confirmation'), new_confirmation_path(resource_name)
19+
OR
1720
- if display_password_reset_link?
1821
%li
1922
= link_to t("devise.shared.links.forgot_your_password"),

config/routes.rb

+5-3
Original file line numberDiff line numberDiff line change
@@ -125,10 +125,12 @@
125125
get :recovery_codes
126126
end
127127

128-
devise_for :users, controllers: {sessions: :sessions}, skip: :registration
128+
devise_for :users, controllers: { sessions: :sessions,
129+
registrations: :registrations,
130+
confirmations: :confirmations }
129131
devise_scope :user do
130-
get "/users/sign_up" => "registrations#new", :as => :new_user_registration
131-
post "/users" => "registrations#create", :as => :user_registration
132+
get "/users/sign_up" => "registrations#new"
133+
get "/users/sign_in" => "sessions#new"
132134
get "/registrations_closed" => "registrations#registrations_closed", :as => :registrations_closed
133135
end
134136

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
class AddConfirmableToUsers < ActiveRecord::Migration[5.2]
2+
3+
def up
4+
add_column :users, :confirmation_token, :string
5+
add_column :users, :confirmed_at, :datetime
6+
add_column :users, :confirmation_sent_at, :datetime
7+
add_index :users, :confirmation_token, unique: true
8+
execute("UPDATE users SET confirmed_at = NOW()")
9+
end
10+
11+
def down
12+
remove_columns :users, :confirmation_token, :confirmed_at, :confirmation_sent_at
13+
end
14+
15+
end

features/desktop/getting_started.feature

+3
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ Feature: new user registration
55
When I go to the new user registration page
66
And I fill in the new user form
77
And I submit the form
8+
And confirm the user "ohai"
9+
Then I should be on the new user session page
10+
When I sign in manually as "ohai" with password "secret"
811
Then I should be on the getting started page
912
Then I should see the 'getting started' contents
1013

features/desktop/invitations.feature

+6
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ Feature: Invitations
1010
And I am on my acceptance form page
1111
And I fill in the new user form
1212
And I press "Create account"
13+
And confirm the user "ohai"
14+
Then I should be on the new user session page
15+
When I sign in manually as "ohai" with password "secret"
1316
Then I should be on the getting started page
1417
And I should see "Well, hello there!"
1518
When I fill in the following:
@@ -23,6 +26,9 @@ Feature: Invitations
2326
And I am on my acceptance form page
2427
And I fill in the new user form
2528
And I press "Create account"
29+
And confirm the user "ohai"
30+
Then I should be on the new user session page
31+
When I sign in manually as "ohai" with password "secret"
2632
Then I should be on the getting started page
2733
And I should see "Well, hello there!"
2834
And I should be able to friend "[email protected]"

features/desktop/registrations.feature

+4-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ Feature: New user registration
88
Given I am on the new user registration page
99
When I fill in the new user form
1010
And I press "Create account"
11+
And confirm the user "ohai"
12+
Then I should be on the new user session page
13+
When I sign in manually as "ohai" with password "secret"
1114
Then I should be on the getting started page
1215
And I should see the 'getting started' contents
1316

@@ -21,4 +24,4 @@ Feature: New user registration
2124
When I fill in the new user form
2225
Given the registrations are closed
2326
When I press "Create account"
24-
Then I should see "Open signups are closed at this time"
27+
Then I should see "Open signups are closed at this time"

features/mobile/getting_started.feature

+3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ Feature: editing the getting started in the mobile view
66
When I follow "Create account" within ".navbar"
77
And I fill in the new user form
88
And I submit the form
9+
And confirm the user "ohai"
10+
Then I should be on the new user session page
11+
And I sign in manually as "ohai" with password "secret" on the mobile website
912
Then I should be on the getting started page
1013
Then I should see the 'getting started' contents
1114

features/mobile/invitations.feature

+3
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ Feature: Invitations
1010
And I am on my acceptance form page
1111
When I fill in the new user form
1212
And I press "Create account"
13+
And confirm the user "ohai"
14+
Then I should be on the new user session page
15+
And I sign in manually as "ohai" with password "secret" on the mobile website
1316
Then I should see the "welcome to diaspora" message
1417
And I should be able to friend "[email protected]"
1518
When I select "Family" from "user_aspects" within "#hello-there"

0 commit comments

Comments
 (0)