Rails 3.x authentication using existing table fields - ruby-on-rails

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.

Related

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.

How Do I Create a User Profile With Devise?

I really like how devise offers an easy to use registration system out of the box but I'm having trouble extending it to do what I need. I need to create a public user profile for each user that shows their information like name, email, bio, and more info. I've done this in the past before with a users/show function but since devise doesn't provide any easily editable controllers, I'm having trouble figuring out how to do this. I've already run rails generate devise:views to copy the devise views to my app but I don't know where to go from here. Any help would be much appreciated.
Sounds like you want users to update their profile at the same time they create their account? If so, you can setup an associated Profile model with the User model. Using accepts_nested_attributes_for you can then create a record for the nested model on devise user registration submit/creation.
Here's a great screencast covering nested models and I also suggest you search other devise relate SO posts as this question has been discussed before.
There is an alternative approach, that is simpler to implement — only allow registered users edit/update their profile. This way you don't have to alter the Devise views and you can setup the various CRUD actions via a separate non-devise controller.
Throw in an Access Control List (ACL) solution such as CanCan (there are other alternatives too!) and you can even allow other users view profiles but deny access to edit/destroy etc.

How do I create a login form in Rails 3?

I have a User model (with all validators and properties defined) and a UsersController. For the controller, I have a login action and a login.html.erb view file. How do I create a simple login form that validates the username and password?
I'd strongly recommend you take a look at using either Authlogic or Devise to do your login. You can find a number of tutorials that will help guide you through setting up either service. I like the Railscasts on the two subjects:
http://railscasts.com/episodes/209-introducing-devise
http://railscasts.com/episodes/160-authlogic
If you want to roll your own authentication, you can. Railscasts also provides a tutorial on doing that:
http://railscasts.com/episodes/250-authentication-from-scratch

Authentication with Ruby on Rails & Devise

I am about to build a new site in ruby on rails for residents at my college.
The site will allow residents to change their passwords for the college-firewalls (which means there are certain requirements).
On the site, each resident will have an account with a number of data assigned to it, and for this I need some authentication.
I've been studying Devise for almost the entire day now, but im starting to wonder if I have a too complicated task, to complete it with Devise.
Problem is, I need the passwords to be stored with DES-encryption, something Im not sure if Devise can handle.
Another thing is, users can't make their own profile. Admins will do that (to ensure correct data), which means that user-creation is not the default one. Since there are no controllers for this, is it even possible to do it that way?
I'm not sure if I should keep on going with Devise, or bite the bullet and write it all from scratch instead. Some opinions would be appreciated.
This page on the Devise wiki ( https://github.com/plataformatec/devise/wiki/How-To:-Create-a-custom-encryptor ) tells you how to set up a custom encryptor.
To make it so that admins create a user, remove the :registerable module from the User model. Then add a user resource to your app, example:
scope 'admin' do
resources :users
end
Set up the new/edit pages with your profile fields, etc., normal rails programming.
For an example using CanCan to control access to the users resource, have a look at this post: http://zyphmartin.com/blog/manage-users-with-devise-and-cancan.
If devise does not exactly do what you need, maybe this recent webcast from Ryan Bates will help you.

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