Commit f0482b07 by tadyjp

Merge pull request #4 from tadyjp/wip/feat/1225

[WIP] 1228 - Fork, Gmail
parents 9a8f28d6 b9a53535
...@@ -77,3 +77,8 @@ gem 'ancestry' ...@@ -77,3 +77,8 @@ gem 'ancestry'
# profiler # profiler
gem 'rack-mini-profiler' gem 'rack-mini-profiler'
# Send mail via gmail oauth
# ref. https://github.com/popgiro/action-gmailer
gem 'mail'
gem 'action-gmailer', github: 'popgiro/action-gmailer'
GIT GIT
remote: git://github.com/popgiro/action-gmailer.git
revision: e04b69f578ead4514f6cea5ac85db16896f7e71c
specs:
action-gmailer (0.1.0)
actionmailer
activesupport
gmail_xoauth
GIT
remote: git://github.com/vmg/redcarpet.git remote: git://github.com/vmg/redcarpet.git
revision: 52c5fa3c5753d2125e827f235cdf4cb730484902 revision: 52c5fa3c5753d2125e827f235cdf4cb730484902
branch: master branch: master
...@@ -64,6 +73,8 @@ GEM ...@@ -64,6 +73,8 @@ GEM
execjs (2.0.2) execjs (2.0.2)
faraday (0.8.8) faraday (0.8.8)
multipart-post (~> 1.2.0) multipart-post (~> 1.2.0)
gmail_xoauth (0.4.1)
oauth (>= 0.3.6)
hashie (2.0.5) hashie (2.0.5)
hike (1.2.3) hike (1.2.3)
httpauth (0.2.0) httpauth (0.2.0)
...@@ -81,6 +92,7 @@ GEM ...@@ -81,6 +92,7 @@ GEM
minitest (4.7.5) minitest (4.7.5)
multi_json (1.8.2) multi_json (1.8.2)
multipart-post (1.2.0) multipart-post (1.2.0)
oauth (0.4.7)
oauth2 (0.8.1) oauth2 (0.8.1)
faraday (~> 0.8) faraday (~> 0.8)
httpauth (~> 0.1) httpauth (~> 0.1)
...@@ -165,6 +177,7 @@ PLATFORMS ...@@ -165,6 +177,7 @@ PLATFORMS
ruby ruby
DEPENDENCIES DEPENDENCIES
action-gmailer!
ancestry ancestry
better_errors better_errors
binding_of_caller binding_of_caller
...@@ -172,6 +185,7 @@ DEPENDENCIES ...@@ -172,6 +185,7 @@ DEPENDENCIES
coffee-rails (~> 4.0.0) coffee-rails (~> 4.0.0)
devise devise
jbuilder (~> 1.2) jbuilder (~> 1.2)
mail
omniauth-google-oauth2 omniauth-google-oauth2
pg pg
rack-mini-profiler rack-mini-profiler
......
if window.location.pathname.match /edit|new/ if window.location.pathname.match /edit|new|fork/
$ -> $ ->
......
require 'mail'
require 'action_gmailer'
module RV::Mailer
def self.compose_mail(subject, body, user)
mail = Mail.new do
from user.email
to user.email
subject subject
body body
end
# set ActionGmailer
config = {
oauth2_token: user.google_auth_token,
account: user.email
}.merge(Rendezvous::Application.config.action_mailer.smtp_settings)
mail.delivery_method(ActionGmailer::DeliveryMethod, config)
mail
end
end
require 'nkf'
require 'rv/mailer'
class PostsController < ApplicationController class PostsController < ApplicationController
before_action :set_post, only: [:show, :edit, :update, :destroy] before_action :set_post, only: [:show, :edit, :update, :destroy]
...@@ -42,6 +45,22 @@ class PostsController < ApplicationController ...@@ -42,6 +45,22 @@ class PostsController < ApplicationController
@post = Post.new @post = Post.new
end end
def fork
@post = set_post.clone
@post.title = @post.title.gsub(/%Name/, current_user.name)
@post.title = Time.now.strftime(@post.title) # TODO
render action: 'new'
end
def mail
@post = set_post
subject = @post.title
body = @post.body
RV::Mailer.compose_mail(subject, body, current_user).deliver
redirect_to root_path(id: @post.id)
end
# GET /posts/1/edit # GET /posts/1/edit
def edit def edit
end end
...@@ -111,4 +130,5 @@ class PostsController < ApplicationController ...@@ -111,4 +130,5 @@ class PostsController < ApplicationController
_param_hash _param_hash
end end
end end
end end
...@@ -9,16 +9,17 @@ class User < ActiveRecord::Base ...@@ -9,16 +9,17 @@ class User < ActiveRecord::Base
# Device # Device
def self.find_for_google_oauth2(access_token, signed_in_resource=nil) def self.find_for_google_oauth2(access_token, signed_in_resource=nil)
data = access_token.info data = access_token.info
user = User.where(:email => data["email"]).first user = User.where(:email => data["email"]).first
unless user unless user
user = User.create(name: data["name"], user = User.create(name: data["name"],
image_url: data["image"], image_url: data["image"],
email: data["email"], email: data["email"],
password: Devise.friendly_token[0,20] password: Devise.friendly_token[0,20]
) )
end end
user user.update_attribute(:google_auth_token, access_token.credentials['token'])
user
end end
end end
<div class="text-box title" style="position:relative;"> <div style="text-align:right">
<a href="<%= post_path(@post) %>"><%= @post.title %></a> <a href="<%= mail_post_path(@post) %>" class="btn navbar-btn" style!="position:absolute;right:0;top:0;margin-top:2px;margin-top:3px;margin-right:3px;">
<a href="<%= edit_post_path(@post) %>" class="btn btn-primary navbar-btn" style="position:absolute;right:0;top:0;margin-top:2px;margin-top:3px;margin-right:3px;"> Mail
</a>
<a href="<%= fork_post_path(@post) %>" class="btn navbar-btn" style!="position:absolute;right:0;top:0;margin-top:2px;margin-top:3px;margin-right:3px;">
Fork
</a>
<a href="<%= edit_post_path(@post) %>" class="btn btn-primary navbar-btn" style!="position:absolute;right:0;top:0;margin-top:2px;margin-top:3px;margin-right:3px;">
<span class="glyphicon glyphicon-pencil"></span> <span class="glyphicon glyphicon-pencil"></span>
</a> </a>
</div> </div>
<div class="text-box title" style!="position:relative;">
<a href="<%= post_path(@post) %>"><%= @post.title %></a>
</div>
<div class="text-box meta"> <div class="text-box meta">
<% @post.tags.each do |tag| %> <% @post.tags.each do |tag| %>
<span class="label label-info"> <span class="label label-info">
......
...@@ -21,5 +21,18 @@ module Rendezvous ...@@ -21,5 +21,18 @@ module Rendezvous
# The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded. # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
# config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s] # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
# config.i18n.default_locale = :de # config.i18n.default_locale = :de
# config.action_mailer.delivery_method = :action_gmailer
config.action_mailer.smtp_settings = {
smtp_host: 'smtp.gmail.com',
smtp_port: 587,
helo_domain: 'gmail.com',
auth_type: :xoauth2,
# oauth2_token: 'FIXME',
# account: 'FIXME'
}
end end
end end
...@@ -2,7 +2,7 @@ Rails.application.config.middleware.use OmniAuth::Builder do ...@@ -2,7 +2,7 @@ Rails.application.config.middleware.use OmniAuth::Builder do
provider :google_oauth2, ENV["GOOGLE_KEY"], ENV["GOOGLE_SECRET"], provider :google_oauth2, ENV["GOOGLE_KEY"], ENV["GOOGLE_SECRET"],
{ {
:name => "google_oauth2", :name => "google_oauth2",
:scope => "userinfo.email, userinfo.profile", :scope => "https://mail.google.com/, userinfo.email, userinfo.profile",
:prompt => "select_account", :prompt => "select_account",
:image_aspect_ratio => "square", :image_aspect_ratio => "square",
:image_size => 50 :image_size => 50
......
...@@ -4,6 +4,9 @@ Rendezvous::Application.routes.draw do ...@@ -4,6 +4,9 @@ Rendezvous::Application.routes.draw do
post 'posts/preview' => 'posts#preview' post 'posts/preview' => 'posts#preview'
get 'posts/show_fragment' => 'posts#show_fragment' get 'posts/show_fragment' => 'posts#show_fragment'
get 'posts/:id/fork' => 'posts#fork', as: 'fork_post'
get 'posts/:id/mail' => 'posts#mail', as: 'mail_post'
resources :posts resources :posts
devise_for :users, :controllers => { :omniauth_callbacks => "users/omniauth_callbacks" } devise_for :users, :controllers => { :omniauth_callbacks => "users/omniauth_callbacks" }
......
class AddTokenToUser < ActiveRecord::Migration
def change
add_column :users, :google_auth_token, :string
end
end
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
# #
# It's strongly recommended that you check this file into your version control system. # It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20131213005609) do ActiveRecord::Schema.define(version: 20131226161253) do
create_table "post_tags", force: true do |t| create_table "post_tags", force: true do |t|
t.integer "post_id", null: false t.integer "post_id", null: false
...@@ -55,6 +55,7 @@ ActiveRecord::Schema.define(version: 20131213005609) do ...@@ -55,6 +55,7 @@ ActiveRecord::Schema.define(version: 20131213005609) do
t.datetime "last_sign_in_at" t.datetime "last_sign_in_at"
t.string "current_sign_in_ip" t.string "current_sign_in_ip"
t.string "last_sign_in_ip" t.string "last_sign_in_ip"
t.string "google_auth_token"
end end
add_index "users", ["email"], name: "index_users_on_email", unique: true add_index "users", ["email"], name: "index_users_on_email", unique: true
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment