ssh root@YOURDOMAIN
adduser deploy
visudo # Add deploy ALL=(ALL) ALL
| # Ignore static version of the site (used to upload error pages to S3 for Heroku errors) | |
| /out |
#Simple Authentication with Bcrypt
This tutorial is for adding authentication to a vanilla Ruby on Rails app using Bcrypt and has_secure_password.
The steps below are based on Ryan Bates's approach from Railscast #250 Authentication from Scratch (revised).
You can see the final source code here: repo. I began with a stock rails app using rails new gif_vault
##Steps
| # I created a generic Rails like ApplicationController so that you can just | |
| # run this code via a command line prompt without the need for Rails | |
| module Recorder | |
| def self.included(base) | |
| base.send(:before_filter, :some_method) | |
| base.send(:after_filter, :another_method) | |
| end |
| module ActionController | |
| class Metal | |
| attr_internal :cached_content_for | |
| end | |
| module Caching | |
| module Actions | |
| def _save_fragment(name, options) | |
| return unless caching_allowed? |
By default, Rails applications build URLs based on the primary key -- the id column from the database. Imagine we have a Person model and associated controller. We have a person record for Bob Martin that has id number 6. The URL for his show page would be:
/people/6
But, for aesthetic or SEO purposes, we want Bob's name in the URL. The last segment, the 6 here, is called the "slug". Let's look at a few ways to implement better slugs.
| <?php | |
| class Encryption { | |
| var $skey = "yourSecretKey"; // change this | |
| public function safe_b64encode($string) { | |
| $data = base64_encode($string); | |
| $data = str_replace(array('+','/','='),array('-','_',''),$data); | |
| return $data; | |
| } |
| class AuthenticationsController < ApplicationController | |
| # This is the callback method from OmniAuth's GitHub authentication. | |
| # following http://railscasts.com/episodes/236-omniauth-part-2 | |
| def create | |
| omniauth = request.env["omniauth.auth"] | |
| authentication = Authentication.find_by_provider_and_uid(omniauth['provider'], omniauth['uid']) | |
| if authentication | |
| sign_in_and_redirect(:user, authentication.user) | |
| end | |
| <?xml version="1.0" encoding="utf-8"?> | |
| <!-- | |
| Google Material Design Color Palette for Android http://www.google.com/design/spec/style/color.html#color-ui-color-palette | |
| Spreadsheet used to create this reosurce - http://bit.ly/mdcolor_spreadsheet | |
| Link to this colors.xml resource file - http://bit.ly/mdcolorsxml | |
| Harshad Kale | |
| https://github.com/kalehv | |
| harshad.kale@gmail.com |
Each of these commands will run an ad hoc http static server in your current (or specified) directory, available at http://localhost:8000. Use this power wisely.
$ python -m SimpleHTTPServer 8000