1
votes

I'm using devise 3.5.2 and rails 4.2.1 I followed the Email-Only-Sign-Up but there is something I don't understand in the flow of informations.

I've updated my views/devise/registrations/new.html.erb file and request only an email to open an account.

I didn't touched my confirmations_instructions.html.erb mailer but updated the routes as mentioned and overwrite the Devise ConfirmationController as well (I used the Rails 4, Devise 3 code), and the User model.

I can create an account without a password from my updated views/devise/registrations/new.html.erb, I receive my untouched confirmations_instructions mail and when I click on the link I reach /users/confirmation?confirmation_token=xxxxx and it is processed by my ConfirmationsController#show method which is still a little bit complicated for my skills level.

I would expect to arrive on the new views/devise/confirmations/show.html.erb file that I've created who would retain my token and allow my user to set their password. The submit button would confirm my user.

Instead of that, then token I sent directly, my user is confirmed and I land on my login page.

Here are my routes:

user_confirmation POST /users/confirmation(.:format) confirmations#create new_user_confirmation GET /users/confirmation/new(.:format) confirmations#new GET /users/confirmation(.:format) confirmations#show confirm PATCH /confirm(.:format) confirmations#confirm

the custom ConfirmationController is a copy paste of the wiki page, the views are customised but should not compromised the whole process. My routes.rb file has been updated just as mentioned, like my User model where I added the password_match? and password_required? methods (there's was only my devise module declaration and few has_many has_one relationships...).

If someone can help me ^^

2
Have the same problem since updating to 3.5.2. Did you find a solution?cseelus

2 Answers

0
votes

You need to add password and password_confirmation fields in the form where you confirm your token.

app/view/confirmations

= form_for(resource, :as => resource_name) do |f|
        = f.password_field :password, class:"password-field", placeholder: "New password"
        = f.password_field :password_confirmation, class:"password-field", placeholder: "Confirm new password"
        = f.hidden_field :confirmation_token, value: @original_token
        = f.submit "Confirm account and create password"

For detailed steps, use this documentation.

0
votes

I'v created a views/devise/confirmations/show.html.erb file:

  <%= form_for(resource, as: resource_name, url: registration_path(resource_name)) do |f| %>

    <div class="row">
      <div class="col-md-4 my_label">
        <%= f.label :password %>
      </div>
      <div class='col-md-8 my_field'>
        <%= f.password_field :password, autocomplete: "off", class: 'form-control', placeholder: 'mypassword'  %>
      </div>
    </div>  

    <div class="row">      
      <div class='col-md-4 my_label'>    
        <%= f.label :password_confirmation %>
      </div>
      <div class='col-md-8 my_field'>          
        <%= f.password_field :password_confirmation, autocomplete: "off", class: 'form-control', placeholder: 'mypassword'  %>
      </div>
    </div>  

    <%= f.input :confirmation_token, :as => :hidden, :input_html => { :value => @original_token } %>

    <div class="row actions">
      <div class='col-md-4'></div>
      <div class='col-md-8 center-block'>
        <%= f.submit("Create my Account", class: "btn btn-success button_submit") %><br>
        <%= render "devise/shared/links" %>
      </div>  
    </div>
  <% end %>

I hope this should work but my problem is that when I click on the link in confirmation mail, it's not mapped to this view and I don't know why. When I read my log I know that the token is processed by the ConfirmationController#show method but it doesn't display the show view...