-
Notifications
You must be signed in to change notification settings - Fork 32
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
New user Registration, Confirmation and session management workflow #160
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
7611364
Alter Users schema to match the latest requirements
danguita b3c5f47
Implement new user Registration, Session and Password recovery workflow
danguita c629f65
Catalan translations
8587e7f
Merge branch 'master' into 126-user-sign-up-workflow
af72602
Adjust year of birth range
2dc12e4
Get rid of duplicated login route
50084ad
Fix gender attribute translation
b445168
Fix confirmation year in test
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
class User::ConfirmationRequestsController < User::BaseController | ||
before_action :require_no_authentication | ||
|
||
def new | ||
@user_confirmation_request_form = User::ConfirmationRequestForm.new | ||
end | ||
|
||
def create | ||
@user_confirmation_request_form = User::ConfirmationRequestForm.new( | ||
user_confirmation_request_params.merge(site: current_site) | ||
) | ||
|
||
if @user_confirmation_request_form.save | ||
flash.now[:notice] = "Please check your inbox to get instructions." | ||
else | ||
flash.now[:alert] = "The email address specified doesn't seem to be valid." | ||
end | ||
|
||
render :new | ||
end | ||
|
||
private | ||
|
||
def user_confirmation_request_params | ||
params.require(:user_confirmation_request).permit(:email) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,23 @@ | ||
class User::RegistrationsController < User::BaseController | ||
before_action :require_no_authentication | ||
|
||
def new | ||
@user_registration_form = User::RegistrationForm.new | ||
end | ||
|
||
def create | ||
@user_registration_form = User::RegistrationForm.new( | ||
user_registration_params.merge(site: current_site, creation_ip: remote_ip) | ||
) | ||
|
||
if @user_registration_form.save | ||
redirect_to root_path, notice: "Please check your inbox for confirmation." | ||
flash[:notice] = t(".success") | ||
else | ||
flash.now[:alert] = "The data you entered doesn't seem to be valid. Please try again." | ||
render :new | ||
flash[:alert] = t(".error") | ||
end | ||
|
||
redirect_to new_user_sessions_path | ||
end | ||
|
||
private | ||
|
||
def user_registration_params | ||
params.require(:user_registration).permit( | ||
:email, | ||
:name, | ||
:password, | ||
:password_confirmation | ||
) | ||
params.require(:user_registration).permit(:email) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,69 @@ | ||
class User::ConfirmationForm | ||
include ActiveModel::Model | ||
|
||
attr_accessor :email, :site | ||
attr_accessor( | ||
:confirmation_token, | ||
:name, | ||
:password, | ||
:password_confirmation, | ||
:year_of_birth, | ||
:gender | ||
) | ||
attr_reader :user | ||
|
||
validates :email, :site, :user, presence: true | ||
validates :name, :year_of_birth, :gender, presence: true | ||
validates :password, presence: true, confirmation: true | ||
validates :user, presence: true | ||
|
||
def save | ||
send_confirmation_email if valid? | ||
return false unless valid? | ||
|
||
confirm_user if save_user | ||
end | ||
|
||
def user | ||
@user ||= User.find_by(email: email) | ||
@user ||= User.find_by_confirmation_token(confirmation_token) | ||
end | ||
|
||
def email | ||
@email ||= user.email | ||
end | ||
|
||
private | ||
|
||
def send_confirmation_email | ||
user.regenerate_confirmation_token | ||
deliver_confirmation_email | ||
def save_user | ||
@user = user.tap do |user_attributes| | ||
user_attributes.name = name | ||
user_attributes.password = password | ||
user_attributes.year_of_birth = year_of_birth | ||
user_attributes.gender = gender | ||
end | ||
|
||
if @user.valid? | ||
@user.save | ||
|
||
@user | ||
else | ||
promote_errors(@user.errors) | ||
|
||
false | ||
end | ||
end | ||
|
||
def confirm_user | ||
user.confirm! | ||
deliver_welcome_email | ||
end | ||
|
||
protected | ||
|
||
def deliver_confirmation_email | ||
User::UserMailer.confirmation_instructions(user, site).deliver_later | ||
def promote_errors(errors_hash) | ||
errors_hash.each do |attribute, message| | ||
errors.add(attribute, message) | ||
end | ||
end | ||
|
||
def deliver_welcome_email | ||
User::UserMailer.welcome(user, user.source_site).deliver_later | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
class User::ConfirmationRequestForm | ||
include ActiveModel::Model | ||
|
||
attr_accessor :email, :site | ||
attr_reader :user | ||
|
||
validates :email, :site, :user, presence: true | ||
|
||
def save | ||
send_confirmation_email if valid? | ||
end | ||
|
||
def user | ||
@user ||= User.find_by(email: email) | ||
end | ||
|
||
private | ||
|
||
def send_confirmation_email | ||
user.regenerate_confirmation_token | ||
deliver_confirmation_email | ||
end | ||
|
||
protected | ||
|
||
def deliver_confirmation_email | ||
User::UserMailer.confirmation_instructions(user, site).deliver_later | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do need more sleep 馃槥