我正在建立我大学的在线社区。 p>
我想允许前往" ABC大学"使用" facebook-omniauth"登录。
但我不知道如何写这个逻辑...... 你知道怎么做这个逻辑吗?
会话控制器
def create
auth = request.env["omniauth.auth"]
session[:omniauth] = auth
user = User.sign_in_from_facebook(auth)
session[:user_id] = user.id
redirect_to root_url, notice: "Signed In"
end
用户模型
def self.sign_in_from_facebook(auth)
find_by(provider: auth['provider'], uid: auth['uid'] ) || create_user_from_facebook(auth)
end
def self.create_user_from_facebook(auth)
create(
avatar: process_uri(auth['info']['image'] + "?width=9999"),
email: auth['info']['email'],
provider: auth['provider'],
uid: auth['uid'],
name: auth['info']['name'],
token: auth['credentials']['token'],
gender: auth['extra']['raw_info']['gender'],
education: auth['extra']['raw_info']['education'],
bio: auth['extra']['raw_info']['bio']
)
end