Commit 2169521f by tady

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

parents 4453a877 4b339e54
......@@ -81,3 +81,6 @@ gem 'ancestry'
# profiler
gem 'rack-mini-profiler'
# Google smtp
gem 'gmail_xoauth'
......@@ -65,6 +65,8 @@ GEM
execjs (2.0.2)
faraday (0.8.8)
multipart-post (~> 1.2.0)
gmail_xoauth (0.4.1)
oauth (>= 0.3.6)
hashie (2.0.5)
hike (1.2.3)
httpauth (0.2.0)
......@@ -82,6 +84,7 @@ GEM
minitest (4.7.5)
multi_json (1.8.2)
multipart-post (1.2.0)
oauth (0.4.7)
oauth2 (0.8.1)
faraday (~> 0.8)
httpauth (~> 0.1)
......@@ -183,6 +186,7 @@ DEPENDENCIES
coderay
coffee-rails (~> 4.0.0)
devise
gmail_xoauth
jbuilder (~> 1.2)
omniauth-google-oauth2
pg
......
if window.location.pathname.match /edit|new/
if window.location.pathname.match /edit|new|fork/
$ ->
......
require 'nkf'
class PostsController < ApplicationController
before_action :set_post, only: [:show, :edit, :update, :destroy]
......@@ -49,6 +51,28 @@ class PostsController < ApplicationController
render action: 'new'
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
def edit
end
......
......@@ -9,16 +9,17 @@ class User < ActiveRecord::Base
# Device
def self.find_for_google_oauth2(access_token, signed_in_resource=nil)
data = access_token.info
user = User.where(:email => data["email"]).first
data = access_token.info
user = User.where(:email => data["email"]).first
unless user
user = User.create(name: data["name"],
image_url: data["image"],
email: data["email"],
password: Devise.friendly_token[0,20]
)
end
user
unless user
user = User.create(name: data["name"],
image_url: data["image"],
email: data["email"],
password: Devise.friendly_token[0,20]
)
end
user.update_attribute(:google_auth_token, access_token.credentials['token'])
user
end
end
<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;">
Fork
</a>
......
......@@ -2,7 +2,7 @@ Rails.application.config.middleware.use OmniAuth::Builder do
provider :google_oauth2, ENV["GOOGLE_KEY"], ENV["GOOGLE_SECRET"],
{
:name => "google_oauth2",
:scope => "userinfo.email, userinfo.profile",
:scope => "https://mail.google.com/, userinfo.email, userinfo.profile",
:prompt => "select_account",
:image_aspect_ratio => "square",
:image_size => 50
......
......@@ -5,6 +5,7 @@ Rendezvous::Application.routes.draw do
post 'posts/preview' => 'posts#preview'
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
......
class AddTokenToUser < ActiveRecord::Migration
def change
add_column :users, :google_auth_token, :string
end
end
......@@ -11,7 +11,7 @@
#
# 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|
t.integer "post_id", null: false
......@@ -55,6 +55,7 @@ ActiveRecord::Schema.define(version: 20131213005609) do
t.datetime "last_sign_in_at"
t.string "current_sign_in_ip"
t.string "last_sign_in_ip"
t.string "google_auth_token"
end
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