Added UsersController#confirm_email with route and some specs
This commit is contained in:
parent
f42055ae24
commit
ea85daadc4
7 changed files with 45 additions and 5 deletions
|
|
@ -150,4 +150,13 @@ class UsersController < ApplicationController
|
||||||
tar_path = PhotoMover::move_photos(current_user)
|
tar_path = PhotoMover::move_photos(current_user)
|
||||||
send_data( File.open(tar_path).read, :filename => "#{current_user.id}.tar" )
|
send_data( File.open(tar_path).read, :filename => "#{current_user.id}.tar" )
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def confirm_email
|
||||||
|
if current_user.confirm_email(params[:token])
|
||||||
|
flash[:notice] = I18n.t('users.confirm_email.email_confirmed', :email => current_user.email)
|
||||||
|
elsif current_user.unconfirmed_email.present?
|
||||||
|
flash[:error] = I18n.t('users.confirm_email.email_not_confirmed')
|
||||||
|
end
|
||||||
|
redirect_to edit_user_path
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@
|
||||||
%p
|
%p
|
||||||
!= t('notifier.confirm_email.click_link', :unconfirmed_email => @receiver.unconfirmed_email)
|
!= t('notifier.confirm_email.click_link', :unconfirmed_email => @receiver.unconfirmed_email)
|
||||||
%br
|
%br
|
||||||
= link_to root_url, root_url
|
= link_to confirm_email_url(:token => @receiver.confirm_email_token), confirm_email_url(:token => @receiver.confirm_email_token)
|
||||||
|
|
||||||
%br
|
%br
|
||||||
%br
|
%br
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
!= t('notifier.hello', :name => @receiver.profile.first_name)
|
!= t('notifier.hello', :name => @receiver.profile.first_name)
|
||||||
|
|
||||||
!= t('notifier.confirm_email.click_link', :unconfirmed_email => @receiver.unconfirmed_email)
|
!= t('notifier.confirm_email.click_link', :unconfirmed_email => @receiver.unconfirmed_email)
|
||||||
!= root_url
|
!= confirm_email_url(:token => @receiver.confirm_email_token)
|
||||||
|
|
||||||
!= "#{t('notifier.love')} \n"
|
!= "#{t('notifier.love')} \n"
|
||||||
!= t('notifier.diaspora')
|
!= t('notifier.diaspora')
|
||||||
|
|
|
||||||
|
|
@ -735,6 +735,9 @@ en:
|
||||||
unconfirmed_email_not_changed: "E-Mail Change Failed"
|
unconfirmed_email_not_changed: "E-Mail Change Failed"
|
||||||
public:
|
public:
|
||||||
does_not_exist: "User %{username} does not exist!"
|
does_not_exist: "User %{username} does not exist!"
|
||||||
|
confirm_email:
|
||||||
|
email_confirmed: "E-Mail %{email} activated"
|
||||||
|
email_not_confirmed: "E-Mail could not be activated. Wrong link?"
|
||||||
|
|
||||||
webfinger:
|
webfinger:
|
||||||
fetch_failed: "failed to fetch webfinger profile for %{profile_url}"
|
fetch_failed: "failed to fetch webfinger profile for %{profile_url}"
|
||||||
|
|
|
||||||
|
|
@ -48,6 +48,7 @@ Diaspora::Application.routes.draw do
|
||||||
get 'public/:username' => :public, :as => 'users_public'
|
get 'public/:username' => :public, :as => 'users_public'
|
||||||
match 'getting_started' => :getting_started, :as => 'getting_started'
|
match 'getting_started' => :getting_started, :as => 'getting_started'
|
||||||
get 'getting_started_completed' => :getting_started_completed
|
get 'getting_started_completed' => :getting_started_completed
|
||||||
|
get 'confirm_email/:token' => :confirm_email, :as => 'confirm_email'
|
||||||
end
|
end
|
||||||
|
|
||||||
# This is a hack to overide a route created by devise.
|
# This is a hack to overide a route created by devise.
|
||||||
|
|
|
||||||
|
|
@ -180,4 +180,31 @@ describe UsersController do
|
||||||
response.should redirect_to new_user_session_path
|
response.should redirect_to new_user_session_path
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe '#confirm_email' do
|
||||||
|
before do
|
||||||
|
@user.update_attribute(:unconfirmed_email, 'my@newemail.com')
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'redirects to to the user edit page' do
|
||||||
|
get 'confirm_email', :token => @user.confirm_email_token
|
||||||
|
response.should redirect_to edit_user_path
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'confirms email' do
|
||||||
|
get 'confirm_email', :token => @user.confirm_email_token
|
||||||
|
@user.reload
|
||||||
|
@user.email.should eql('my@newemail.com')
|
||||||
|
request.flash[:notice].should eql(I18n.t('users.confirm_email.email_confirmed', :email => 'my@newemail.com'))
|
||||||
|
request.flash[:error].should be_blank
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'does NOT confirm email with wrong token' do
|
||||||
|
get 'confirm_email', :token => @user.confirm_email_token.reverse
|
||||||
|
@user.reload
|
||||||
|
@user.email.should_not eql('my@newemail.com')
|
||||||
|
request.flash[:error].should eql(I18n.t('users.confirm_email.email_not_confirmed'))
|
||||||
|
request.flash[:notice].should be_blank
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -686,7 +686,7 @@ describe User do
|
||||||
alice.mail_confirm_email.should eql(false)
|
alice.mail_confirm_email.should eql(false)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe '#confirm_email' do
|
describe '#confirm_email' do
|
||||||
context 'on user with unconfirmed email' do
|
context 'on user with unconfirmed email' do
|
||||||
before do
|
before do
|
||||||
|
|
@ -729,14 +729,14 @@ describe User do
|
||||||
user.unconfirmed_email.should eql(nil)
|
user.unconfirmed_email.should eql(nil)
|
||||||
user.confirm_email_token.should eql(nil)
|
user.confirm_email_token.should eql(nil)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'returns false and does not change anything on blank token' do
|
it 'returns false and does not change anything on blank token' do
|
||||||
user.confirm_email("").should eql(false)
|
user.confirm_email("").should eql(false)
|
||||||
user.email.should_not eql("alice@newmail.com")
|
user.email.should_not eql("alice@newmail.com")
|
||||||
user.unconfirmed_email.should eql(nil)
|
user.unconfirmed_email.should eql(nil)
|
||||||
user.confirm_email_token.should eql(nil)
|
user.confirm_email_token.should eql(nil)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'returns false and does not change anything on blank token' do
|
it 'returns false and does not change anything on blank token' do
|
||||||
user.confirm_email(nil).should eql(false)
|
user.confirm_email(nil).should eql(false)
|
||||||
user.email.should_not eql("alice@newmail.com")
|
user.email.should_not eql("alice@newmail.com")
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue