3
我想要一個「編輯個人資料」頁面,用戶可以在其中註冊時更改註冊的電子郵件地址。如何在Rails3.1上用Devise更改電子郵件地址
我想有以下過程:
- 用戶必須輸入自己的密碼,以確認他讓在電子郵件領域的變化之前。
- 提交該頁面後,用戶應該收到驗證郵件,就像Devise的默認註冊一樣。
- 只要用戶單擊郵件上的驗證令牌URL,電子郵件更改就會完成。
我該怎麼做?
我想要一個「編輯個人資料」頁面,用戶可以在其中註冊時更改註冊的電子郵件地址。如何在Rails3.1上用Devise更改電子郵件地址
我想有以下過程:
我該怎麼做?
我爲我的一個網站創建了同樣的流程。下面是你可以做什麼的例子:
添加到config/routes.rb中 (請注意,路由可能會更好,但我前一陣子這樣做)
scope :path => '/users', :controller => 'users' do
match 'verify_email' => :verify_email, :as => 'verify_email'
match 'edit_account_email' => :edit_account_email, :as => 'edit_account_email'
match 'update_account_email' => :update_account_email, :as => 'update_account_email'
end
增加應用程序/控制器/ users_controller.rb
def edit_account_email
@user=current_user
end
def update_account_email
@user=current_user
@user.password_not_needed=true
@user.email=params[:address]
if @user.save
flash[:notice]="your login email has been successfully updated."
else
flash[:alert]="oops! we were unable to activate your new login email. #{@user.errors}"
end
redirect_to edit_user_path
end
def verify_email
@user=current_user
@address=params[:address]
UserMailer.confirm_account_email(@user, @address).deliver
end
應用程序/郵寄者/ user_mailer.rb
class UserMailer < ActionMailer::Base
def confirm_account_email(user, address)
@user = user
@address = address
mail(
:to=>"#{user.name} <#{@address}>",
:from=>"your name <'[email protected]'>",
:subject=>"account email confirmation for #{user.name}"
)
end
end
應用程序/視圖/ user_mailer文件/ confirm_account_email.html.erb
<p>you can confirm that you'd like to use this email address to log in to your account by clicking the link below:</p>
<p><%= link_to('update your email', update_account_email_url(@user, :address=>@address)) %></p>
<p>if you choose not to confirm the new address, your current login email will remain active.
這是否幫助任何? https://github.com/Mandaryn/devise/commit/92ee45e60d65b5e127f74973ea866ed7d4dcef20 – MKK
如果我在這裏完成以下所有步驟,那麼我該如何準備「編輯配置文件(電子郵件)」頁面,以便在其中更改電子郵件? https://github.com/heimidal/devise/commit/1961de6b5deb7c1799a265d506221fef9d7bb6a9 – MKK