2011-10-03 6 views
3

사용자는 가입시 등록 된 이메일 주소를 변경할 수있는 "프로필 수정"페이지를 원합니다.rails3.1에서 Devise로 이메일 주소를 변경하는 방법

나는 다음과 같은 과정을 가지고 싶습니다

:

  • 사용자가 입력에 그는 이메일 필드에 변경을 수행하기 전에 확인을 위해 자신의 암호가 있습니다.
  • 페이지를 제출 한 후 사용자는 Devise의 기본 가입과 마찬가지로 확인 메일을 받아야합니다.
  • 사용자가 메일의 확인 토큰 URL을 클릭하자마자 이메일 변경이 완료됩니다.

어떻게하면됩니까?

+0

이 어떤 도움이됩니까? https://github.com/Mandaryn/devise/commit/92ee45e60d65b5e127f74973ea866ed7d4dcef20 – MKK

+0

다음 단계를 모두 수행하면 전자 메일을 변경할 수있는 "프로필 편집 (전자 메일)"페이지를 어떻게 준비 할 수 있습니까? https://github.com/heimidal/devise/commit/1961de6b5deb7c1799a265d506221fef9d7bb6a9 – MKK

답변

0

광산 사이트에서 이와 동일한 흐름을 만들었습니다.

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 

에 추가 가 (라우팅이 더있을 수 있습니다,하지만 난 얼마 전에 이런 짓을)/

추가가 config (설정) 할 routes.rb : 여기에 당신이 할 수있는 일의 예 응용 프로그램/컨트롤러/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. 
관련 문제