Skip to content
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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Verification link in welcome mail #3992

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,21 @@ def shortlink
end
end

def verify_email
decrypted_user_id = User.validate_token(params[:token])
action_msg = "Email verification failed"
if decrypted_user_id != 0
user_obj = User.find(decrypted_user_id)
if user_obj.is_verified
action_msg = "Email already verified"
else
user_obj.update_column(:is_verified, true)
action_msg = "Successfully verified email"
end
end
redirect_to "/login", flash: { notice: action_msg }
end

private

def set_user
Expand Down
7 changes: 7 additions & 0 deletions app/views/welcome_mailer/notify_newcomer.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@

Looking forward to hearing from you soon,

Please click on the link below to verify your email.

<% verifaction_link="#{ActionMailer::Base.default_url_options[:host]}/verify/#{@user.generate_token}" %>
<%= link_to "#{verifaction_link}", verifaction_link%>

In case you are not able to click the link, try copy pasting the link in the browser.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @jywarren make sure too copy this change to the welcome-email-body feature whenever you push this PR to production as the changes made here are just on the fallback email body and the production would send the email using the welcome-email-body feature's content(if it's present).

Thanks!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, then this is an issue - we can't execute code in the features system, so this will need to be moved outside the <% end %> on this line: https://github.com/publiclab/plots2/pull/3992/files/b74bbcbd3d85ff70b18bc7eae14bf79105270976#diff-a3214821bc5b12012e6fbb54ad82f05aR29

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jywarren . Sorry but I am not getting what we are supposed to do?

Copy link
Contributor Author

@shubhscoder shubhscoder Feb 10, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh I think I got it. We need to move the verification link and the corresponding instructions regarding the mail outside the if else block right? Because if body is present then the verification link wont appear , so we need to move it outside the block. I will make a new PR for that. Thank you so much for the help!

The Public Lab Community
<% end %>

Expand Down
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
get 'people/:tagname' => 'users#list'
get 'signup' => 'users#new'
get 'home' => 'home#front'
get 'verify/:token' => 'users#verify_email'
resources :relationships, only: [:create, :destroy]

get '/wiki/:id/comments', to: 'wiki#comments'
Expand Down
14 changes: 14 additions & 0 deletions test/functional/users_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -282,4 +282,18 @@ def setup
assert_equal [], UserTag.where(uid: users(:bob).id, value: "notify-comment-indirect:false")
assert_equal [], UserTag.where(uid: users(:bob).id, value: 'digest:digest')
end

test 'upon verification redirection to login takes place' do
test_user = users(:admin)
email_verification_token = test_user.generate_token
get :verify_email, params: { token: email_verification_token }
assert_redirected_to "/login"
end

test 'upon verification the is_verified field gets updated appropriately' do
test_user = users(:admin)
email_verification_token = test_user.generate_token
get :verify_email, params: { token: email_verification_token }
assert_equal "Successfully verified email", flash[:notice]
end
end