# Extending SiteController -- how to get current\_user

**URL:** <https://www.ruby-forum.com/t/extending-sitecontroller-how-to-get-current-user/135177>\
**Category:** Radiant CMS\
**Created:** [April 18, 2008, 9:12pm UTC](https://www.ruby-forum.com/t/extending-sitecontroller-how-to-get-current-user/135177 "2008-04-18T21:12:47Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![georges](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/bcef8e/32.png) [@georges](https://www.ruby-forum.com/u/georges)\
**Post date:** [April 18, 2008, 9:12pm UTC](https://www.ruby-forum.com/t/extending-sitecontroller-how-to-get-current-user/135177/1 "2008-04-18T21:12:47Z")

</div>

Hey guys,

I’m putting together a rudimentary extension to create member system  
that will allow me to restrict certain front-end pages to certain logged  
in users.

However, as this is my first real Rails attempt, I’m hitting some walls.  
I have extended the Page model and the User model to work the way I  
require, but I can’t get the current\_user in the SiteController.

What is the proper way to access the current logged in user in a  
controller? I see that LoginSystem is setting it, but I don’t really  
understand where it then goes.

Sorry if this hits on some basic knowledge questions, but I’m starting  
out here 🙂

Thanks,

georges

---

<div class="post-metadata">

**Author:** ![georges](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/bcef8e/32.png) [@georges](https://www.ruby-forum.com/u/georges)\
**Post date:** [April 18, 2008, 10:29pm UTC](https://www.ruby-forum.com/t/extending-sitecontroller-how-to-get-current-user/135177/2 "2008-04-18T22:29:53Z")

</div>

The current\_user method used in Radiant and the member system are  
probably (or should be) different things, unless all of your members  
should have logins to the admin interface. However, assuming this is  
not the case, you’ll need to extend the SiteController, probably using  
an included module. The module would redefine/intercept various methods  
in the controller. When we built something similar for Redken, we  
turned on the session (using session :disabled =\> false), used  
alias\_method\_chain to intercept process\_page so we could pass the  
current\_user to the page, and added some before\_filters to login from  
cookies and do other similar tasks. All told, it was probably around 30  
lines of code, outside of the generated user/login boilerplate.

Sean
