Customizing Devise vs Creating own authentication for multi page registration - ruby-on-rails

I'm creating a ruby on rails project (soon to be a mobile app). I wanted to utilize the Devise gem for authentication, but I am struggling with the customization of Devise. I wanted to implement a multi-page registration/sign up process. The standard devise gem automatically provides a form that includes email and password. For my project, I wanted the users to add in their name on one page, then their email on the next page, and then their password on the page after, etc. Please see the attached jpg picture for a super basic example.
So far, I separated the registration controller from the devise package. The registration controller comes with the new.html.erb and the edit.html.erb files. I want to take the standard form in the new.html.erb file and split that into multiple html.erb files. The controller would obviously need to be connected to these multiple files. As I was working on it, I realized how complicated it is. I'm wondering is it better to create my own authentication process instead of devise, or is it better to stick with devise?
I really want to make it work with devise, so if you have any suggestions on how to customize the gem to implement the multipage registration that I want, please let me know.

This can be done by modifying the views and the devise controller to accept multi-part registration, but it is cumbersome: I would counsel you to avoid it. Rather, another option would be to: (i) use devise to handle the email and username in one form and then (ii) handle the multi-part registration using the wicked gem - whose sole purpose for existence is to handle multi part registration problems.

Related

Rails 3.x authentication using existing table fields

I have Rails 3.2.11 application that i need to hook up with login. The Devise Database Authenticatable would have been ok except:
I can't create table/fields and need to use existing fields(Devise wants to create user model).
Instead of user model, i have to use "existing model (student) with email and password fields.
Would any of you Rails guru tell me how to customize Devise or if to use something different.
Basic requirement is: use login system where someone has to register but use existing table/fields.
Thank you
The quick answer if you can't add fields to your table, Devise is not a authentication choice. It needs certain basic specific fields to work.
You can set Devise with a specific model name, as Peter de Ridder points out. But, without these required fields, several wild errors will show up (like "missing column" among others more cryptic).
Note that in this Devise's wiki article refers to these fields as required:
https://github.com/plataformatec/devise/wiki/How-To:-change-an-already-existing-table-to-add-devise-required-columns
You can customize devise as much as you want. Railscasts #210 gives information about customization options. You can create a devise model with any name you want btw. For example, you can do:
rails generate devise Student
If you want a Student model. Pretty much everything in Devise can be customized, altough some changes are easier then others. You could also get all the controllers from devise at github and customize or just override them in your own application. The devise wiki has a lot of information about customizing:
https://github.com/plataformatec/devise/wiki
I can also recommend the revised railscast #250 authentication from scratch (also railscasts available for authorization from scratch), if you want full control on all your authentication options.

Split devise edit user registration into 2 separate forms to change email and change password?

I've searched topics but this exact question doesn't come up. Is it possible to separate the Devise user form to make it 2 separate forms?
change email
change password?
You only have to create a simple CRUD, as in any other case. it is also posible to generate the view that devise uses and/or override the controllers.
https://github.com/plataformatec/devise/wiki/How-To:-Manage-users-through-a-CRUD-interface
Managing your users is not really devise related, devise only really handles authentication.

User registration server-side wizard with Devise authentication

All the authentication plugins I've seen are implementing one-page user registration - user enters all his fields and then they are submitted at once. So the Devise authentication does.
Bun now we have requirements to do multi-page registration wizard.
Implementing it with JQuery with posting on last wizard's page would be easy if we haven't a requirement that user should be created on the very first page and then, on other pages should provide more and more information with saving after each page submit.
How would you suggest to implement this in a project which is using Devise authentication? How does this correspond to user's activation process (I mean sending account confirmation e-mails)?
Multistep forms have nothing to do with any authentication plugin you use. It depends on how you integrate it.
The complexity becomes much harder since you have multiple requests from page to page.
- How do I keep the data?
- When do I create the database model?
- Should I use hidden fields an pass the values from page to page or should I stick them in the session?
Those are all questions that pop up at some point and you should try sorting them out beforehand.
Creating the model on the initial request has the big disadvantage that you could end up with a bogus database entry, which obviously you don't want.
You could create a temporary model for instance, that you use for collecting the userdata and at the end you create your real usermodel, going through devise, based on this tmp model and delete it when you're done...
Ryan Bates talks in one of his screencasts about multistep forms. http://railscasts.com/episodes/217-multistep-forms
might be interesting for you to watch.

How to Customize Registration using Devise on Rails?

I'm currently working on a Rails project and have decided to use Devise for user registration. The site is using MongoDB (mongoid gem), and I am planning to create a simple sign-up/sign-in system.
So, there is a link in the home page that allows the user to click on it or open in another tab. If he decides to click it, there should be a popup modal that contains the fields and sign-up button, etc. If he opens a new tab, he should see a dedicated page for the sign up process.
So, here is what I have so far. I have installed devise and am able to sign up properly. However, I also want to create the modal effect, in which I used jQuery UI dialog attached to the sign-up link. Then I loaded the sign-up page (/user/sign-up) using dialog.load("path") and stripped the layout when it is an ajax request.
I know this is not the best method to use, so I've been reluctant. Is there a better way of doing this? Preferably a standard method. Any help would be appreciated, or just point me to the right direction. Tutorials will be very nice and helpful. Thanks a lot in advance!
I am not sure if I understand the question, but try this. Run
rails generate devise:views
To create the devise views.
In the views/devise/registration folder you will find the registration page. You should now have access to both the form code and the path user_session mapping to /users/sign_in.
You now have the form and the path, so you should be able to play with the AJAXifying it.

Adding additional fields (with validation) to Devise view/model in Rails app

It seems there's not a whole lot of documentation out there covering how to add custom fields to a Devise authentication solution in a Rails 3 app.
Along with the required e-mail and password for users to sign up, I'd like a few other custom fields put in and validated and since there are no controllers generated with Devise, how does one do this?
I needed this same thing. There is a great article I found to help me:
http://ykyuen.wordpress.com/2011/03/03/rails-%E2%80%93-add-custom-fields-to-devise-user-model/
When you do rails generate devise_views all the views for the features you selected will go in your app/views/devise folder. You could simply add the fields defined in your model to those views. If you need to customize the controller, create
class YourModel::DeviseFeaturesController
by DeviseFeatures I meant RegistrationsController, ConfirmationsController or whichever features you decided to use.
There is a great screencast about it: RailsCasts-customizing-devise

Resources