From e8adcf8cc7edf24cb0dd1087f9ecc8d26d0c5b34 Mon Sep 17 00:00:00 2001 From: guange <8863824@gmail.com> Date: Wed, 4 May 2016 15:40:18 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0sso=20model?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/sso_controller.rb | 4 ++-- app/models/sso.rb | 4 ++++ app/models/user.rb | 2 ++ db/migrate/20160504060751_create_ssos.rb | 16 +++++++++++++++ db/schema.rb | 25 ++++++++++++++---------- 5 files changed, 39 insertions(+), 12 deletions(-) create mode 100644 app/models/sso.rb create mode 100644 db/migrate/20160504060751_create_ssos.rb diff --git a/app/controllers/sso_controller.rb b/app/controllers/sso_controller.rb index 0ae7b7449..2a7ac6db3 100644 --- a/app/controllers/sso_controller.rb +++ b/app/controllers/sso_controller.rb @@ -30,8 +30,8 @@ class SsoController < ApplicationController end def login(id) - - start_user_session(user) + sso = Sso.find(id) + start_user_session(sso.user) end end diff --git a/app/models/sso.rb b/app/models/sso.rb new file mode 100644 index 000000000..d7cf54dc3 --- /dev/null +++ b/app/models/sso.rb @@ -0,0 +1,4 @@ +class Sso < ActiveRecord::Base + belongs_to :user + attr_accessible :email, :name, :openid, :password, :school, :sex +end diff --git a/app/models/user.rb b/app/models/user.rb index dc7a3e741..9b8cb2b8d 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -181,6 +181,8 @@ class User < Principal has_one :user_wechat + has_one :sso + # add by zjc has_one :level, :class_name => 'UserLevels', :dependent => :destroy has_many :memos , :foreign_key => 'author_id' diff --git a/db/migrate/20160504060751_create_ssos.rb b/db/migrate/20160504060751_create_ssos.rb new file mode 100644 index 000000000..a01a7fe35 --- /dev/null +++ b/db/migrate/20160504060751_create_ssos.rb @@ -0,0 +1,16 @@ +class CreateSsos < ActiveRecord::Migration + def change + create_table :ssos do |t| + t.references :user + t.string :openid + t.string :name + t.string :password + t.string :email + t.integer :sex + t.string :school + + t.timestamps + end + add_index :ssos, :user_id + end +end diff --git a/db/schema.rb b/db/schema.rb index 3d3a54105..677b030df 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20160429030819) do +ActiveRecord::Schema.define(:version => 20160504060751) do create_table "activities", :force => true do |t| t.integer "act_id", :null => false @@ -1673,15 +1673,6 @@ ActiveRecord::Schema.define(:version => 20160429030819) do t.datetime "updated_at", :null => false end - create_table "shield_wechats", :force => true do |t| - t.string "container_type" - t.integer "container_id" - t.string "shield_type" - t.integer "shield_id" - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false - end - create_table "softapplications", :force => true do |t| t.string "name" t.text "description" @@ -1700,6 +1691,20 @@ ActiveRecord::Schema.define(:version => 20160429030819) do t.integer "project_id" end + create_table "ssos", :force => true do |t| + t.integer "user_id" + t.string "openid" + t.string "name" + t.string "password" + t.string "email" + t.integer "sex" + t.string "school" + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false + end + + add_index "ssos", ["user_id"], :name => "index_ssos_on_user_id" + create_table "student_work_projects", :force => true do |t| t.integer "homework_common_id" t.integer "student_work_id"