Commit 2169521f by tady

Merge commit '4b339e54' into wip/feat/1225

parents 4453a877 4b339e54
...@@ -81,3 +81,6 @@ gem 'ancestry' ...@@ -81,3 +81,6 @@ gem 'ancestry'
# profiler # profiler
gem 'rack-mini-profiler' gem 'rack-mini-profiler'
# Google smtp
gem 'gmail_xoauth'
...@@ -65,6 +65,8 @@ GEM ...@@ -65,6 +65,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)
...@@ -82,6 +84,7 @@ GEM ...@@ -82,6 +84,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)
...@@ -183,6 +186,7 @@ DEPENDENCIES ...@@ -183,6 +186,7 @@ DEPENDENCIES
coderay coderay
coffee-rails (~> 4.0.0) coffee-rails (~> 4.0.0)
devise devise
gmail_xoauth
jbuilder (~> 1.2) jbuilder (~> 1.2)
omniauth-google-oauth2 omniauth-google-oauth2
pg pg
......
if window.location.pathname.match /edit|new/ if window.location.pathname.match /edit|new|fork/
$ -> $ ->
......
require 'nkf'
class PostsController < ApplicationController class PostsController < ApplicationController
before_action :set_post, only: [:show, :edit, :update, :destroy] before_action :set_post, only: [:show, :edit, :update, :destroy]
...@@ -49,6 +51,28 @@ class PostsController < ApplicationController ...@@ -49,6 +51,28 @@ class PostsController < ApplicationController
render action: 'new' render action: 'new'
end end
def mail
@post = set_post
smtp = Net::SMTP.new('smtp.gmail.com', 587)
smtp.enable_starttls_auto
smtp.start('gmail.com', current_user.email, current_user.google_auth_token, :xoauth2)
body = 'test'
body = <<EOT
From: #{current_user.email}
To: #{current_user.email}
Subject: #{NKF.nkf("-WjMm0", 'subject')}
Date: #{Time::now.strftime("%a, %d %b %Y %X %z")}
Mime-Version: 1.0
Content-Type: text/plain; charset=ISO-2022-JP
Content-Transfer-Encoding: 7bit
#{NKF.nkf("-Wjm0", body)}
EOT
smtp.send_mail body, current_user.email, current_user.email
smtp.finish
redirect_to root_path(id: @post.id)
end
# GET /posts/1/edit # GET /posts/1/edit
def edit def edit
end end
......
...@@ -19,6 +19,7 @@ class User < ActiveRecord::Base ...@@ -19,6 +19,7 @@ class User < ActiveRecord::Base
password: Devise.friendly_token[0,20] password: Devise.friendly_token[0,20]
) )
end end
user.update_attribute(:google_auth_token, access_token.credentials['token'])
user user
end end
end end
<div style="text-align:right"> <div style="text-align:right">
<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;">
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;"> <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 Fork
</a> </a>
......
...@@ -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
......
...@@ -5,6 +5,7 @@ Rendezvous::Application.routes.draw do ...@@ -5,6 +5,7 @@ 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/fork' => 'posts#fork', as: 'fork_post'
get 'posts/:id/mail' => 'posts#mail', as: 'mail_post'
resources :posts resources :posts
......
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