-
Notifications
You must be signed in to change notification settings - Fork 182
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #29 from backburnerstudios/welcome-page-and-oauth
Welcome page and oauth
- Loading branch information
Showing
21 changed files
with
351 additions
and
9 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<Settings><!--This file was automatically generated by Ruby plugin. | ||
You are allowed to: | ||
1. Reorder generators | ||
2. Remove generators | ||
3. Add installed generators | ||
To add new installed generators automatically delete this file and reload the project. | ||
--><GeneratorsGroup><Generator name="active_record:migration" /><Generator name="active_record:model" /><Generator name="active_record:observer" /><Generator name="active_record:session_migration" /><Generator name="controller" /><Generator name="erb:controller" /><Generator name="erb:mailer" /><Generator name="erb:scaffold" /><Generator name="generator" /><Generator name="helper" /><Generator name="integration_test" /><Generator name="mailer" /><Generator name="metal" /><Generator name="migration" /><Generator name="model" /><Generator name="model_subclass" /><Generator name="observer" /><Generator name="performance_test" /><Generator name="plugin" /><Generator name="resource" /><Generator name="scaffold" /><Generator name="scaffold_controller" /><Generator name="session_migration" /><Generator name="stylesheets" /><Generator name="test_unit:controller" /><Generator name="test_unit:helper" /><Generator name="test_unit:integration" /><Generator name="test_unit:mailer" /><Generator name="test_unit:model" /><Generator name="test_unit:observer" /><Generator name="test_unit:performance" /><Generator name="test_unit:plugin" /><Generator name="test_unit:scaffold" /></GeneratorsGroup></Settings> |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,3 +18,7 @@ | |
|
||
# Ignore test coverage | ||
/coverage/* | ||
|
||
# Ignore application configuration | ||
/config/application.yml | ||
.idea |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<Settings><!--This file was automatically generated by Ruby plugin. | ||
You are allowed to: | ||
1. Remove rake task | ||
2. Add existing rake tasks | ||
To add existing rake tasks automatically delete this file and reload the project. | ||
--><RakeGroup description="" fullCmd="" taksId="rake" /></Settings> |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,49 @@ | ||
# Viewing Party | ||
|
||
This is the base repo for the viewing party project used for Turing's Backend Module 3. | ||
[![Build Status](https://travis-ci.org/backburnerstudios/viewing_party.svg?branch=main)](https://travis-ci.org/backburnerstudios/viewing_party) | ||
|
||
This application is a means to explore movies and create viewing parties for you and friends. | ||
|
||
### About this Project | ||
The application utilizes [Google OAuth](https://developers.google.com/identity/protocols/oauth2) | ||
for [Calendar API access](https://developers.google.com/calendar) to save these events. We also | ||
use the [Movie DB API](https://developers.themoviedb.org/3/getting-started/introduction) for movie data. | ||
|
||
Viewing party is an application in which users can explore movie options and create a viewing party event for the user and friend's. | ||
Example wireframes to follow are found [here](https://backend.turing.io/module3/projects/viewing_party/wireframes) | ||
|
||
## Learning Goals of the Project | ||
|
||
- Consume JSON APIs that require authentication | ||
- Build an application that authenticates using OAuth | ||
- Implement a self-referential relationship in ActiveRecord | ||
- Utilize Continuous Integration using Travis CI | ||
- Organize and refactor code to be more maintainable | ||
- Apply RuboCop’s style guide for code quality | ||
- Deploy to Heroku | ||
|
||
#### Extension / Exploration Goals (1 extension is required) | ||
|
||
- Send email from a Rails application | ||
- Use ActionCable for chat functionality | ||
- Implement front-end JavaScript for more dynamic pages | ||
- Extend movie exploration by consuming additional API endpoints | ||
- Deploy with another hosting provider | ||
|
||
## Project Board and Hosting | ||
|
||
- Project Board: https://github.com/backburnerstudios/viewing_party/projects/1 | ||
- Live site: https://movie-screening.herokuapp.com/ | ||
|
||
## Local Setup | ||
|
||
1. Fork and Clone the repo | ||
2. Install gem packages: `bundle install` | ||
3. Setup the database: `rails db:create` | ||
3. Setup the database: `rails db:{dropcreate,migrate,seed}` | ||
4. Run all tests: `rspec` | ||
|
||
|
||
## Versions | ||
## Tech Stack Versions | ||
|
||
- Ruby 2.5.3 | ||
|
||
- Rails 5.2.4.3 | ||
|
||
|
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,8 @@ | ||
class ApplicationController < ActionController::Base | ||
protect_from_forgery with: :exception | ||
helper_method :current_user | ||
|
||
def current_user | ||
@current_user ||= User.find(session[:user_id]) if session[:user_id] | ||
end | ||
end |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
class SessionsController < ApplicationController | ||
def create | ||
access_data = request.env['omniauth.auth'] | ||
user = User.parse_omniauth(access_data) | ||
user.google_token = access_data.credentials.token | ||
|
||
refresh_token = access_data.credentials.refresh_token | ||
user.google_refresh_token = refresh_token if refresh_token.present? | ||
|
||
user.save | ||
|
||
session[:user_id] = user.id | ||
redirect_to root_path | ||
end | ||
end |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
class WelcomeController < ApplicationController | ||
def index | ||
# do something here? | ||
end | ||
end |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
class User < ApplicationRecord | ||
validates_presence_of :username | ||
validates :uid, presence: true, uniqueness: true | ||
validates :google_token, presence: true, uniqueness: true | ||
|
||
def self.parse_omniauth(access_data) | ||
where(uid: access_data.info.uid).first_or_initialize do |user| | ||
user.username = access_data.info.email | ||
user.uid = access_data.uid | ||
end | ||
end | ||
end |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<h1>Welcome to the Viewing Party!</h1> | ||
|
||
<% if current_user %> | ||
<p>Welcome back, <%= current_user.username %>!</p> | ||
<% else %> | ||
<%= link_to 'Log in with Google', '/auth/google_oauth2' %> | ||
<% end %> | ||
|
||
<hr> | ||
|
||
<h2>This application is a means to explore movies and create viewing parties for you and friends.</h2> | ||
|
||
Utilizing <%= link_to 'the Movie DB API', 'https://www.themoviedb.org/' %> and the power of | ||
<%= link_to 'Google Calendar', 'https://calendar.google.com' %>, you can create a viewing party with your friends! |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
Rails.application.config.middleware.use OmniAuth::Builder do | ||
provider :google_oauth2, ENV['GOOGLE_CLIENT_ID'], ENV['GOOGLE_CLIENT_SECRET'], {scope: "userinfo.email, calendar"} | ||
end |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,7 @@ | ||
Rails.application.routes.draw do | ||
# For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html | ||
root to: 'welcome#index' | ||
|
||
get '/auth/:provider/callback', to: 'sessions#create' | ||
get '/auth/failure', to: redirect('/') | ||
end |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
class CreateUsers < ActiveRecord::Migration[5.2] | ||
def change | ||
create_table :users do |t| | ||
t.string :uid | ||
t.string :username | ||
t.string :google_token | ||
t.string :google_refresh_token | ||
|
||
t.timestamps | ||
end | ||
add_index :users, :uid | ||
add_index :users, :username | ||
end | ||
end |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# This file is auto-generated from the current state of the database. Instead | ||
# of editing this file, please use the migrations feature of Active Record to | ||
# incrementally modify your database, and then regenerate this schema definition. | ||
# | ||
# Note that this schema.rb definition is the authoritative source for your | ||
# database schema. If you need to create the application database on another | ||
# system, you should be using db:schema:load, not running all the migrations | ||
# from scratch. The latter is a flawed and unsustainable approach (the more migrations | ||
# you'll amass, the slower it'll run and the greater likelihood for issues). | ||
# | ||
# It's strongly recommended that you check this file into your version control system. | ||
|
||
ActiveRecord::Schema.define(version: 2020_08_20_043729) do | ||
|
||
# These are extensions that must be enabled in order to support this database | ||
enable_extension "plpgsql" | ||
|
||
create_table "users", force: :cascade do |t| | ||
t.string "uid" | ||
t.string "username" | ||
t.string "google_token" | ||
t.string "google_refresh_token" | ||
t.datetime "created_at", null: false | ||
t.datetime "updated_at", null: false | ||
t.index ["uid"], name: "index_users_on_uid" | ||
t.index ["username"], name: "index_users_on_username" | ||
end | ||
|
||
end |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
require 'faker' | ||
|
||
FactoryBot.define do | ||
factory :user do | ||
username { "#{Faker::Games::WorldOfWarcraft.hero} #{Faker::Number.number(digits: 3)}" } | ||
uid { Faker::Number.within(range: 100000..999999) } | ||
google_token { Faker::Number.within(range: 100000..999999) } | ||
google_refresh_token { Faker::Number.within(range: 100000..999999) } | ||
end | ||
end |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
require 'rails_helper' | ||
|
||
RSpec.describe 'Sessions spec', type: :feature do | ||
it 'logs the user in via google mock' do | ||
stub_omniauth | ||
user = create(:user, username: '[email protected]') | ||
|
||
visit root_path | ||
|
||
click_link 'Log in with Google' | ||
|
||
expect(page).to have_content("Welcome back, #{user.username}") | ||
end | ||
end |
Oops, something went wrong.