# LoginGenerator - multiple user types

**URL:** <https://www.ruby-forum.com/t/logingenerator-multiple-user-types/70997>\
**Category:** Rails\
**Created:** [February 20, 2006, 9:09pm UTC](https://www.ruby-forum.com/t/logingenerator-multiple-user-types/70997 "2006-02-20T21:09:09Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![aftershock](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/8e7dd6/32.png) [@aftershock](https://www.ruby-forum.com/u/aftershock)\
**Post date:** [February 20, 2006, 9:09pm UTC](https://www.ruby-forum.com/t/logingenerator-multiple-user-types/70997/1 "2006-02-20T21:09:09Z")

</div>

I have been looking at the LoginGenerator gem. Looks great and can be  
easily modified. However in my app I have two places where people can  
login, one is for in my case “employees” the other is for “users”. They  
are seperate tables in my database and have many different fields.

I have an admin area located at ./sysadmin/ where only “employees” can  
login, they will have roles of things like “engineer”, “admin”,  
“development” etc which alters what they can do.

The other area is for “users” these users also have roles (like  
client\_admin) different to the “employees” roles. Logging in here is  
only for our clients.

So on the surface it seems like I need to have the functionality of the  
logingenerator as two seperate instances running from two tables inside  
the same app.

Can’t work out the best way to do it. Have you done anything similar?

(I had thought about using STI, but have decided against that for a  
number of reasons).

---

<div class="post-metadata">

**Author:** ![aftershock](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/8e7dd6/32.png) [@aftershock](https://www.ruby-forum.com/u/aftershock)\
**Post date:** [February 20, 2006, 9:17pm UTC](https://www.ruby-forum.com/t/logingenerator-multiple-user-types/70997/2 "2006-02-20T21:17:12Z")

</div>

I’m wrestling with the exact same issues today. My first thought is  
to define two before filters. One would be :user\_login\_required and  
the other would be :employee\_login\_required. Then I just duplicate  
the login\_required method in the login\_system.rb and adjust models  
accordingly.

Perhaps someone has a better idea?

-Derrick S.

---

<div class="post-metadata">

**Author:** ![aftershock](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/8e7dd6/32.png) [@aftershock](https://www.ruby-forum.com/u/aftershock)\
**Post date:** [February 20, 2006, 9:30pm UTC](https://www.ruby-forum.com/t/logingenerator-multiple-user-types/70997/3 "2006-02-20T21:30:09Z")

</div>

Derrick S. wrote:

> I’m wrestling with the exact same issues today. My first thought is  
> to define two before filters. One would be :user\_login\_required and  
> the other would be :employee\_login\_required. Then I just duplicate  
> the login\_required method in the login\_system.rb and adjust models  
> accordingly.
> 
> Perhaps someone has a better idea?
> 
> -Derrick S.

Yes I see what you mean, that could be a way. So that would mean  
duplicating the “user” model as well. I suppose you could create a base  
model and the inherit it changing the required references to “user” to  
the other model.

I’m all new to this so other suggestion are very welcome in the mean  
time lets experiment!

---

<div class="post-metadata">

**Author:** ![aftershock](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/8e7dd6/32.png) [@aftershock](https://www.ruby-forum.com/u/aftershock)\
**Post date:** [February 20, 2006, 9:38pm UTC](https://www.ruby-forum.com/t/logingenerator-multiple-user-types/70997/4 "2006-02-20T21:38:25Z")

</div>

James W. wrote:

> Derrick S. wrote:
> 
> > I’m wrestling with the exact same issues today. My first thought is  
> > to define two before filters. One would be :user\_login\_required and  
> > the other would be :employee\_login\_required. Then I just duplicate  
> > the login\_required method in the login\_system.rb and adjust models  
> > accordingly.
> > 
> > Perhaps someone has a better idea?
> > 
> > -Derrick S.
> 
> Yes I see what you mean, that could be a way. So that would mean  
> duplicating the “user” model as well. I suppose you could create a base  
> model and the inherit it changing the required references to “user” to  
> the other model.
> 
> I’m all new to this so other suggestion are very welcome in the mean  
> time lets experiment!

No i’m being stupid I cannot inherit the model as they are very  
different and thats back to the SingleTableInheritance that I don’y want  
to use.

---

<div class="post-metadata">

**Author:** ![aftershock](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/8e7dd6/32.png) [@aftershock](https://www.ruby-forum.com/u/aftershock)\
**Post date:** [February 20, 2006, 10:39pm UTC](https://www.ruby-forum.com/t/logingenerator-multiple-user-types/70997/5 "2006-02-20T22:39:57Z")

</div>

On 2/20/06, James W. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> client\_admin) different to the “employees” roles. Logging in here is  
> only for our clients.

You may want to look at the user engine (or user generator if there is  
one).

[http://www.rails-engines.org/user\_engine](http://www.rails-engines.org/user_engine)

I’m still a newbie, but as I understand it the login engine and/or  
generator allows people to login. To get different roles for  
different people you can add the user engine to your setup.

Greg

–  
Greg F.  
The Norcross Group  
Forensics for the 21st Century

---

<div class="post-metadata">

**Author:** ![aftershock](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/8e7dd6/32.png) [@aftershock](https://www.ruby-forum.com/u/aftershock)\
**Post date:** [February 20, 2006, 11:42pm UTC](https://www.ruby-forum.com/t/logingenerator-multiple-user-types/70997/6 "2006-02-20T23:42:21Z")

</div>

On Feb 20, 2006, at 12:09 PM, James W. wrote:

> The other area is for “users” these users also have roles (like
> 
> (I had thought about using STI, but have decided against that for a  
> number of reasons).
> 
> –

James-

```
You might want to take a look at my new plugin acl_system. Its an

```

add on for the different login generaotrs that adds permissions and  
roles to the whole deal.

Its an acl/role type system that can sit on top of the  
acts\_as\_authenticated login system or any login system that  
implements a few requirements.

First lets see the candy ;-). This is what my post controller looks  
like in my sample app to demonstrate this plugin:

class PostController \< ApplicationController  
before\_filter :login\_required, :except =\> [:list, :index]  
access\_control(:new =\> ‘(admin | user | moderator) & !blacklist’,  
:create =\> ‘admin & !blacklist’,  
:edit =\> ‘(admin | moderator) & !blacklist’,  
:update =\> ‘(admin | moderator) & !blacklist’,  
:delete =\> ‘admin & (!moderator | !blacklist)’ )

There is also a helper method that can be used in the view or  
controller. In the view its handy for conditional menus or stuff like  
that.

\<% if permit?(“(admin | moderator) & !blacklist”, current\_user) %\>  
\<%= link\_to “Admin & Moderator only link”, :action =\>‘foo’ %\>  
\<% end %\>

Here is the link:  
[http://brainspl.at/articles/2006/02/20/new-plugin-acl\_system](http://brainspl.at/articles/2006/02/20/new-plugin-acl_system)

I reccomend that you use the acts\_as\_authenticated plugin instead of  
the login generator, its similar but much better.

Cheers-  
-Ezra Z.  
WebMaster  
Yakima Herald-Republic Newspaper  
removed\_email\_address@domain.invalid  
509-577-7732

---

<div class="post-metadata">

**Author:** ![aftershock](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/8e7dd6/32.png) [@aftershock](https://www.ruby-forum.com/u/aftershock)\
**Post date:** [February 21, 2006, 11:00pm UTC](https://www.ruby-forum.com/t/logingenerator-multiple-user-types/70997/7 "2006-02-21T23:00:35Z")

</div>

Ezra,

Many thanks again. I had looked at the engines bt decided against using  
them as it still does not address the issue I have which is I don’t just  
have one “users” table & model to set permissions/logins against, I also  
have another model & table with “employees” that needs seperate  
permissions, logins.

I have decided, probably wrongly, to duplicate the login\_required method  
in login\_system so that I have “employee\_login\_required” and  
“user\_login\_required”.

This means that I now have duplicate information in my models that is  
against DRY principles.
