This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class SessionsController < ApplicationController | |
skip_before_filter :verify_authenticity_token, only: :create | |
def create | |
# Find an identity here | |
identity_info = Identity.filter_auth_hash(auth_hash) | |
@identity = Identity.find_with_omniauth(identity_info) | |
if @identity.nil? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Identity < ActiveRecord::Base | |
belongs_to :member | |
def self.find_with_omniauth(info) | |
find_by provider: info[:provider], uid: info[:uid] | |
end | |
def self.create_with_omniauth(info) | |
create(uid: info[:uid], provider: info[:provider], oauth_token: info[:oauth_token], oauth_expires_at: info[:oauth_expires_at], oauth_secret: info[:oauth_secret]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Member < ActiveRecord::Base | |
has_many :identities | |
def self.create_with_omniauth(info) | |
# create(first_name: info[:first_name], last_name: info[:last_name], email: info[:email], gender: info[:gender], birthday: info[:birthday], nickname: info[:nickname], profile_picture: info[:profile_picture], location: info[:location]) | |
member = find_or_initialize_by_email(info[:email]) do |i| | |
i.first_name = info[:first_name] | |
i.last_name = info[:last_name] | |
i.email = info[:email] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Omniauth Authentication | |
get 'auth/:provider/callback' => 'sessions#create' | |
get 'auth/failure' => redirect('/') | |
get 'signout' => 'sessions#destroy', :as => 'signout' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
create_table "identities", force: true do |t| | |
t.integer "member_id" | |
t.string "uid" | |
t.string "provider" | |
t.string "oauth_token" | |
t.string "oauth_secret" | |
t.datetime "oauth_expires_at" | |
end | |
add_index "identities", ["member_id"], name: "index_identities_on_member_id", using: :btree |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
### BEGIN INIT INFO | |
# Provides: unicorn | |
# Required-Start: $remote_fs $syslog | |
# Required-Stop: $remote_fs $syslog | |
# Default-Start: 2 3 4 5 | |
# Default-Stop: 0 1 6 | |
# Short-Description: Manage unicorn server | |
# Description: Start, stop, restart unicorn server for a specific application. | |
### END INIT INFO |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rails_helper' | |
RSpec.describe HomeController, :type => :controller do | |
describe "GET index" do | |
it "renders the :index template" do | |
expect(get: root_url(subdomain: nil)).to route_to( | |
controller: "home", | |
action: "index") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Model | |
@user.should have(1).error_on(:username) # Checks whether there is an error in username | |
@user.errors[:username].should include("can't be blank") # check for the error message | |
#Rendering | |
response.should render_template(:index) | |
#Redirecting | |
response.should redirect_to(movies_path) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<% flash.each do |type, message| %> | |
<div class="alert <%= alert_class_for(type) %> fade in"> | |
<button class="close" data-dismiss="alert">×</button> | |
<%= message %> | |
</div> | |
<% end %> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
var NoScopeSoup = function($scope) { | |
var _this = this; | |
_this.myDataString = 'My Data'; | |
}; | |
NoScopeSoup.prototype.getMyData = function() { | |
return this.myDataString; |