At the Forge - Authenticating to a Rails Application
To install a new plugin—say, acts_as_authenticated—we must provide its URL to script/plugin. This is as easy as the following:
script/plugin install http://svn.techno-weenie.net/projects/plugins/acts_as_authenticated
Now, what happens when you install a plugin? Rails installs it into the vendor/plugins directory, under a new directory named after the plugin. Thus, my installation of acts_as_authenticated installed a number of files into vendor/plugins/acts_as_authenticated.
In and of itself, installing the plugin doesn't change my Rails installation or add any new functionality. Rather, a plugin typically creates one or more generators, which are used to create or modify files used by the application.
In the case of acts_as_authenticated, it comes with two different generators, which we can see by going into the generators subdirectory. Here, there are two generators, named authenticated and authenticated_mailer. If we go into the authenticated directory, we see authenticated_generator, which is what defines the generator. This allows us to go to the root directory of our Rails application and type:
script/generate authenticated user account
The above tells Rails that we want to use the authenticated plugin, which it finds in the plugin directory. The other arguments to this command indicate the model (and table name) we will use (user in this case), and the controller that should be generated to handle accounts.
The generator creates a migration file, defining the columns of the Users table using Ruby for greater database independence. In order to create the columns of the database, we must run the migration:
Using my PostgreSQL database client, I now can see that the migration did its job:
atf_development=# \d users Table "public.users" Column | Type | ---------------------------+-----------------------------+ id | integer | login | character varying(255) | email | character varying(255) | crypted_password | character varying(40) | salt | character varying(40) | created_at | timestamp without time zone | updated_at | timestamp without time zone | remember_token | character varying(255) | remember_token_expires_at | timestamp without time zone |
Now that I have incorporated acts_as_authenticated into my application, I should be able to do several simple things:
Mark pages as open to the public.
Mark pages as private—that is, open only to registered users.
Allow people to register.
Allow users to log in.
Allow users to log out.
All of this is not only possible with acts_as_authenticated, but it's also quite easy. To make pages require authentication by default, we can say:
Of course, if we require that people log in before they use the login page, users will find themselves in an infinite loop. So, we can add an exception for that at the top of account_controller.rb:
before_filter :login_required, :except => [:login, :signup]
Once this filter is in place, trying to visit any page other than login or :signup bounces us back to the login page.
I'm going to register, by entering my login name, my e-mail address and my password (twice) into the registration form. Once I click on the submit button, the application inserts my data into the database. I'm in there, with ID #1, and my plain-text data as well as my encrypted data.
Moreover, after registering with the site, I am now signed in as well. I can view any page I want, without having to log in again. My login will last until I go to the /account/logout URL. Unfortunately, the default index.rhtml page that comes with acts_as_authenticated does not make it clear when you have logged out. We can check that easily by adding a line to the top, showing the contents of non-blank notices:
<p><%= flash[:notice] if not flash[:notice].blank? %></p>
We now have a basically working version of an authenticated Web server. People can register (and log in if they are already registered), and we can add both restricted and unrestricted pages via the controller and the before_filter :login_required command.
Practical Task Scheduling Deployment
July 20, 2016 12:00 pm CDT
One of the best things about the UNIX environment (aside from being stable and efficient) is the vast array of software tools available to help you do your job. Traditionally, a UNIX tool does only one thing, but does that one thing very well. For example, grep is very easy to use and can search vast amounts of data quickly. The find tool can find a particular file or files based on all kinds of criteria. It's pretty easy to string these tools together to build even more powerful tools, such as a tool that finds all of the .log files in the /home directory and searches each one for a particular entry. This erector-set mentality allows UNIX system administrators to seem to always have the right tool for the job.
Cron traditionally has been considered another such a tool for job scheduling, but is it enough? This webinar considers that very question. The first part builds on a previous Geek Guide, Beyond Cron, and briefly describes how to know when it might be time to consider upgrading your job scheduling infrastructure. The second part presents an actual planning and implementation framework.
Join Linux Journal's Mike Diehl and Pat Cameron of Help Systems.
Free to Linux Journal readers.Register Now!
- Stunnel Security for Oracle
- SourceClear Open
- Murat Yener and Onur Dundar's Expert Android Studio (Wrox)
- SUSE LLC's SUSE Manager
- My +1 Sword of Productivity
- Managing Linux Using Puppet
- Google's SwiftShader Released
- Non-Linux FOSS: Caffeine!
- Parsing an RSS News Feed with a Bash Script
- Doing for User Space What We Did for Kernel Space
With all the industry talk about the benefits of Linux on Power and all the performance advantages offered by its open architecture, you may be considering a move in that direction. If you are thinking about analytics, big data and cloud computing, you would be right to evaluate Power. The idea of using commodity x86 hardware and replacing it every three years is an outdated cost model. It doesn’t consider the total cost of ownership, and it doesn’t consider the advantage of real processing power, high-availability and multithreading like a demon.
This ebook takes a look at some of the practical applications of the Linux on Power platform and ways you might bring all the performance power of this open architecture to bear for your organization. There are no smoke and mirrors here—just hard, cold, empirical evidence provided by independent sources. I also consider some innovative ways Linux on Power will be used in the future.Get the Guide