facebook login and import done
This commit is contained in:
parent
73b82bc177
commit
8d7e350c32
|
@ -46,6 +46,16 @@
|
||||||
opacity: 0.8;
|
opacity: 0.8;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.sign-up .role-label{
|
||||||
|
display: inline;
|
||||||
|
margin-left: 3px;
|
||||||
|
margin-right: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.sign-up input[type=checkbox]{
|
||||||
|
margin-top: 0;
|
||||||
|
}
|
||||||
|
|
||||||
.line{
|
.line{
|
||||||
border-bottom: 1px solid #EDEDED;
|
border-bottom: 1px solid #EDEDED;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,38 @@
|
||||||
class BasicInfosController < ApplicationController
|
class BasicInfosController < ApplicationController
|
||||||
layout "devise"
|
layout "devise"
|
||||||
def index
|
def index
|
||||||
|
if current_user.nil?
|
||||||
|
redirect_to "/users/sign_up"
|
||||||
|
end
|
||||||
|
@user = current_user
|
||||||
end
|
end
|
||||||
|
|
||||||
def form_page
|
def form_page
|
||||||
|
@user = User.find(params[:user_id])
|
||||||
|
end
|
||||||
|
|
||||||
|
def basic_info_update
|
||||||
|
@user = User.find(params[:id])
|
||||||
|
if @user.update_attributes(params[:user])
|
||||||
|
redirect_to basic_infos_role_page_path(:user_id => @user.id.to_s)
|
||||||
|
else
|
||||||
|
render :action=> "form_page"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def role_page
|
||||||
|
@roles = Role.where(:disabled => false)
|
||||||
|
@user_id = params[:user_id]
|
||||||
|
end
|
||||||
|
|
||||||
|
def role_update
|
||||||
|
user = User.find(params[:id])
|
||||||
|
if user.update_attributes(params[:user])
|
||||||
|
redirect_to root_path
|
||||||
|
else
|
||||||
|
@roles = Role.where(:disabled => false)
|
||||||
|
render :action => "role_page"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
|
@ -4,6 +4,8 @@ require 'json'
|
||||||
|
|
||||||
class FacebookController< ApplicationController
|
class FacebookController< ApplicationController
|
||||||
|
|
||||||
|
@@facebook_server = "http://fb.tp.rulingcom.com"
|
||||||
|
|
||||||
def register_fb
|
def register_fb
|
||||||
user = User.find(params[:user])
|
user = User.find(params[:user])
|
||||||
if !user.facebook
|
if !user.facebook
|
||||||
|
@ -17,8 +19,9 @@ class FacebookController< ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
def get_friends
|
def get_friends
|
||||||
if current_user.facebook
|
fb = current_user.facebook rescue nil
|
||||||
@url = "http://fb.tp.rulingcom.com/get_friends?identifier=" + current_user.facebook.fb_identifier
|
if fb
|
||||||
|
@url = "#{@@facebook_server}/get_friends?identifier=" + current_user.facebook.fb_identifier
|
||||||
uri = URI.parse(@url)
|
uri = URI.parse(@url)
|
||||||
http = Net::HTTP.new(uri.host, uri.port)
|
http = Net::HTTP.new(uri.host, uri.port)
|
||||||
request = Net::HTTP::Get.new(uri.request_uri)
|
request = Net::HTTP::Get.new(uri.request_uri)
|
||||||
|
@ -43,8 +46,43 @@ class FacebookController< ApplicationController
|
||||||
render :json=>{"success"=>true}.to_json
|
render :json=>{"success"=>true}.to_json
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def profile_import
|
||||||
|
temp_user = User.find(params[:user_id])
|
||||||
|
fb = temp_user.facebook rescue nil
|
||||||
|
if fb
|
||||||
|
@url = "#{@@facebook_server}/profile_import?identifier=" + fb.fb_identifier
|
||||||
|
uri = URI.parse(@url)
|
||||||
|
http = Net::HTTP.new(uri.host, uri.port)
|
||||||
|
request = Net::HTTP::Get.new(uri.request_uri)
|
||||||
|
response = http.request(request)
|
||||||
|
friends = response.body
|
||||||
|
data = JSON.parse(friends)
|
||||||
|
if data["success"]
|
||||||
|
user = JSON.parse(data["user"])
|
||||||
|
u = User.find(current_user.id)
|
||||||
|
u.first_name = user["first_name"]
|
||||||
|
u.last_name = user["last_name"]
|
||||||
|
u.office_tel = user["phone"]
|
||||||
|
u.email = user["email"]
|
||||||
|
u.sex = user["gender"] || "unknown"
|
||||||
|
u.remote_avatar_url = user["picture"] if user["picture"]
|
||||||
|
u.save!
|
||||||
|
render :json=>{"success"=>true,"user"=>user}.to_json
|
||||||
|
else
|
||||||
|
render :json=>{"success"=>false,"message"=>data["message"]}.to_json
|
||||||
|
end
|
||||||
|
|
||||||
|
else
|
||||||
|
render :json=>{"success"=>false,"message"=>"User is not connected to facebook."}.to_json
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def server_redirect
|
def server_redirect
|
||||||
# "http://fb.tp.rulingcom.com/login?callback=http://harry.tp.rulingcom.com/facebook/register_fb?user="+current_user.id.to_s rescue nil
|
@url = "#{@@facebook_server}/login?callback=#{request.protocol}#{request.host_with_port}/facebook/register_fb?user="+current_user.id.to_s rescue nil
|
||||||
redirect_to "http://new.tp.rulingcom.com"
|
if !@url.nil?
|
||||||
|
redirect_to @url
|
||||||
|
else
|
||||||
|
render :layout=> "devise"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
|
@ -0,0 +1,130 @@
|
||||||
|
|
||||||
|
<%#= devise_error_messages! %>
|
||||||
|
|
||||||
|
<input type="hidden" value="<%= @user.id.to_s %>" name="id" />
|
||||||
|
<div class="attributes">
|
||||||
|
<div class="attributes-header clearfix">
|
||||||
|
<h4><%=t(:sys_basic_form)%></h4>
|
||||||
|
</div>
|
||||||
|
<div class="attributes-body">
|
||||||
|
|
||||||
|
<!-- Avatar -->
|
||||||
|
<div class="control-group">
|
||||||
|
<%= f.label t("users.avatar"),:class=>"control-label muted" %>
|
||||||
|
<div class="controls">
|
||||||
|
<!-- if this page editing please add class "fileupload-edit" -->
|
||||||
|
<div class="fileupload fileupload-new clearfix <%= 'fileupload-edit' if @user.avatar.file %>" data-provides="fileupload">
|
||||||
|
<div class="fileupload-new thumbnail pull-left">
|
||||||
|
<% if @user.avatar? %>
|
||||||
|
<%= image_tag(@user.avatar.thumb.url) %>
|
||||||
|
<% else %>
|
||||||
|
<%= image_tag "person.png" %>
|
||||||
|
<% end %>
|
||||||
|
</div>
|
||||||
|
<div class="fileupload-preview fileupload-exists thumbnail pull-left"></div>
|
||||||
|
<span class="btn btn-file">
|
||||||
|
<span class="fileupload-new"><%= t(:select_image) %></span>
|
||||||
|
<span class="fileupload-exists"><%= t(:change) %></span>
|
||||||
|
<%= f.file_field :avatar %>
|
||||||
|
</span>
|
||||||
|
<a href="#" class="btn fileupload-exists" data-dismiss="fileupload"><%= t(:cancel) %></a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- First Name -->
|
||||||
|
<div class="control-group">
|
||||||
|
<%= f.label t("users.first_name"),{:class=>"control-label muted", :func=>"field_label"} %>
|
||||||
|
<div class="controls add-input">
|
||||||
|
<div class="add-target">
|
||||||
|
<div class="input-append">
|
||||||
|
<div class="tab-content">
|
||||||
|
<% @site_valid_locales.each_with_index do |locale, i| %>
|
||||||
|
<div class="tab-pane fade <%= ( i == 0 ) ? "active in" : '' %>" id="first_name_<%= locale %>">
|
||||||
|
<%= f.fields_for :first_name_translations do |f| %>
|
||||||
|
<%= f.text_field locale, :value => (@user.first_name_translations[locale] rescue nil), :placeholder=>"#{t("users.first_name")}" %>
|
||||||
|
<% end %>
|
||||||
|
</div>
|
||||||
|
<% end %>
|
||||||
|
</div>
|
||||||
|
<div class="btn-group" data-toggle="buttons-radio">
|
||||||
|
<% @site_valid_locales.each_with_index do |locale, i| %>
|
||||||
|
<a class="btn <%= ( i == 0 ) ? "active" : '' %>" href="#first_name_<%= locale %>" data-toggle="tab"><%= I18nVariable.from_locale(locale) %></a>
|
||||||
|
<% end %>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Last Name -->
|
||||||
|
<div class="control-group">
|
||||||
|
<%= f.label t("users.last_name"),{:class=>"control-label muted", :func=>"field_label"} %>
|
||||||
|
<div class="controls add-input">
|
||||||
|
<div class="add-target">
|
||||||
|
<div class="input-append">
|
||||||
|
<div class="tab-content">
|
||||||
|
<% @site_valid_locales.each_with_index do |locale, i| %>
|
||||||
|
<div class="tab-pane fade <%= ( i == 0 ) ? "active in" : '' %>" id="last_name_<%= locale %>">
|
||||||
|
<%= f.fields_for :last_name_translations do |f| %>
|
||||||
|
<%= f.text_field locale, :value => (@user.last_name_translations[locale] rescue nil), :placeholder=>"#{t("users.last_name")}" %>
|
||||||
|
<% end %>
|
||||||
|
</div>
|
||||||
|
<% end %>
|
||||||
|
</div>
|
||||||
|
<div class="btn-group" data-toggle="buttons-radio">
|
||||||
|
<% @site_valid_locales.each_with_index do |locale, i| %>
|
||||||
|
<a class="btn <%= ( i == 0 ) ? "active" : '' %>" href="#last_name_<%= locale %>" data-toggle="tab"><%= I18nVariable.from_locale(locale) %></a>
|
||||||
|
<% end %>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Mail -->
|
||||||
|
<div class="control-group">
|
||||||
|
<%= f.label t("users.email"),:class=>"control-label muted" %>
|
||||||
|
<div class="controls add-input">
|
||||||
|
<%= f.email_field :email %>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- ID Number -->
|
||||||
|
<div class="control-group">
|
||||||
|
<%= f.label t("users.sid"),:class=>"control-label muted" %>
|
||||||
|
<div class="controls add-input">
|
||||||
|
<%= f.text_field :sid %>
|
||||||
|
<span class="help-block"><%= t("users.sid_note")%></span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Office Tel Number -->
|
||||||
|
<div class="control-group">
|
||||||
|
<%= f.label t("users.office_tel"),:class=>"control-label muted" %>
|
||||||
|
<div class="controls add-input">
|
||||||
|
<%= f.text_field :office_tel %>
|
||||||
|
<span class="help-block"><%= t("users.office_tel_note")%></span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Gender -->
|
||||||
|
<div class="control-group">
|
||||||
|
<%= f.label t("users.sex"),:class=>"control-label muted" %>
|
||||||
|
<div class="controls">
|
||||||
|
<label class="radio inline">
|
||||||
|
<%= f.radio_button :sex, "male" %><%= t('users.male')%>
|
||||||
|
</label>
|
||||||
|
<label class="radio inline">
|
||||||
|
<%= f.radio_button :sex, "female" %><%= t('users.female')%>
|
||||||
|
</label>
|
||||||
|
<label class="radio inline">
|
||||||
|
<%= f.radio_button :sex, "unknown" %><%= t('users.unknown')%>
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</div>
|
|
@ -1 +1,35 @@
|
||||||
<%= stylesheet_link_tag "sign_up" %>
|
<% content_for :page_specific_css do -%>
|
||||||
|
<%= stylesheet_link_tag "lib/wrap-nav.css" %>
|
||||||
|
<%= stylesheet_link_tag "lib/pageslide.css" %>
|
||||||
|
<%= stylesheet_link_tag "lib/main-forms.css" %>
|
||||||
|
<%= stylesheet_link_tag "lib/fileupload.css" %>
|
||||||
|
<%= stylesheet_link_tag "lib/togglebox.css" %>
|
||||||
|
<% end -%>
|
||||||
|
<% content_for :page_specific_javascript do -%>
|
||||||
|
<%= javascript_include_tag "lib/jquery-ui-1.10.3.custom.min.js" %>
|
||||||
|
<%= javascript_include_tag "lib/jquery.tmpl.min.js" %>
|
||||||
|
<%= javascript_include_tag "lib/bootstrap-fileupload.js" %>
|
||||||
|
<%= javascript_include_tag "lib/bootstrap-datetimepicker.js" %>
|
||||||
|
<%= javascript_include_tag "lib/datetimepicker/date.time.picker.js" %>
|
||||||
|
<%= javascript_include_tag "lib/member/textarea-lang-btn.js" %>
|
||||||
|
<%= javascript_include_tag "lib/member/role-forms.js" %>
|
||||||
|
<% end -%>
|
||||||
|
|
||||||
|
|
||||||
|
<%= form_for @user, :url => basic_infos_basic_info_update_path, :html => { :multipart => true , :class=>"form-horizontal main-forms", :id=>"user-forms"} do |f| %>
|
||||||
|
|
||||||
|
<fieldset>
|
||||||
|
<div id="basic-area" class="input-area">
|
||||||
|
|
||||||
|
<%= f.error_messages %>
|
||||||
|
<%= render :partial => 'form_page', :locals => {:f => f}%>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="form-actions">
|
||||||
|
<input type="submit" value="Next" class="btn btn-primary" />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</fieldset>
|
||||||
|
|
||||||
|
<% end -%>
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
<div class="form">
|
<div class="form">
|
||||||
<h3 class="login-logo">Please select a method for Basic Info</h3>
|
<h3 class="login-logo">Please select a method for Basic Info</h3>
|
||||||
<div class="option-block">
|
<div class="option-block">
|
||||||
<a href="<%= basic_infos_form_path %>" class="btn btn-info btn-large">Form</a>
|
<a href="<%= basic_infos_form_path(:user_id=>@user.id.to_s) %>" class="btn btn-info btn-large">Form</a>
|
||||||
<div class="or">
|
<div class="or">
|
||||||
<div class="line left"></div>
|
<div class="line left"></div>
|
||||||
<span>OR</span>
|
<span>OR</span>
|
||||||
|
@ -12,7 +12,7 @@
|
||||||
</div>
|
</div>
|
||||||
<a href="javascript:void(0);" class="facebook"><img src="assets/facebook-logo.png" /></a>
|
<a href="javascript:void(0);" class="facebook"><img src="assets/facebook-logo.png" /></a>
|
||||||
</div>
|
</div>
|
||||||
<div class="option-block msg"></div>
|
<div class="option-block msg alert hide"><h4></h4><br /><a href="<%= basic_infos_role_page_path(:user_id => @user.id.to_s) %>" class="btn btn-primary hide">Next</a></div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
@ -24,14 +24,32 @@
|
||||||
timeInterval = null;
|
timeInterval = null;
|
||||||
$("a.facebook").click(function(){
|
$("a.facebook").click(function(){
|
||||||
facebookWindow = window.open('<%= facebook_server_path %>','login_window','height=668,width=1124,titlebar=0,statusbar=0,location=0');
|
facebookWindow = window.open('<%= facebook_server_path %>','login_window','height=668,width=1124,titlebar=0,statusbar=0,location=0');
|
||||||
|
clearInterval(timeInterval);
|
||||||
timeInterval = setInterval(function(){
|
timeInterval = setInterval(function(){
|
||||||
if( facebookWindow.closed ){
|
if( facebookWindow.closed ){
|
||||||
clearInterval(timeInterval);
|
clearInterval(timeInterval);
|
||||||
$.getJSON("/facebook/get_friends",function(data){
|
$(".msg").removeClass('hide').find("h4").text("Importing,please wait...");
|
||||||
if(!data.success){
|
$.ajax({
|
||||||
$(".msg").text(data.message);
|
url : "/facebook/profile_import",
|
||||||
}else{
|
data : {"user_id":"<%= @user.id.to_s %>"},
|
||||||
$(".msg").text("Import Succesfull!");
|
type : "get",
|
||||||
|
dataType : "json",
|
||||||
|
success : function(data){
|
||||||
|
if(!data.success){
|
||||||
|
$(".msg").removeClass('hide').addClass('alert-danger').find("h4").text(data.message);
|
||||||
|
}else{
|
||||||
|
var msg = "";
|
||||||
|
if (data.user.first_name){
|
||||||
|
msg+= "Welcome " + data.user.first_name + ", your data is successfully imported!"
|
||||||
|
}else{
|
||||||
|
msg = "Import Succesfull!"
|
||||||
|
}
|
||||||
|
$(".msg").removeClass('hide').addClass('alert-success').find("h4").text(msg);
|
||||||
|
$(".msg a").removeClass('hide');
|
||||||
|
}
|
||||||
|
},
|
||||||
|
error : function(){
|
||||||
|
$(".msg").removeClass('hide').addClass('alert-danger').find("h4").text("Error connecting the server!");
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,32 @@
|
||||||
|
<%= stylesheet_link_tag "sign_up" %>
|
||||||
|
<section id="main-wrap">
|
||||||
|
<div class="sign-up have-other-sign-in">
|
||||||
|
|
||||||
|
<% flash.each do |key, msg| %>
|
||||||
|
<%= content_tag :p, msg, :class => [key, "alert alert-error in fade"] %>
|
||||||
|
<% end %>
|
||||||
|
|
||||||
|
<div class="form">
|
||||||
|
<h3 class="login-logo">Please select a role</h3>
|
||||||
|
<div class="form-block">
|
||||||
|
<div class="form-list clearfix option-block">
|
||||||
|
<form action="<%= basic_infos_role_update_path %>" method="post">
|
||||||
|
<label>Roles</label>
|
||||||
|
<div class="control-group clear">
|
||||||
|
<% @roles.each do |role| %>
|
||||||
|
<input type="checkbox" name="user[role_ids][]" value="<%= role.id.to_s %>" />
|
||||||
|
<label class="role-label">
|
||||||
|
<%= role.title %>
|
||||||
|
</label>
|
||||||
|
<% end %>
|
||||||
|
<input type="hidden" name="id" value="<%= @user_id %>"
|
||||||
|
</div>
|
||||||
|
<h3 class="line"></h3>
|
||||||
|
<input type="submit" value="Finish" class="btn btn-primary pull-right" />
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</section>
|
|
@ -0,0 +1,13 @@
|
||||||
|
|
||||||
|
<%= stylesheet_link_tag "sign_up" %>
|
||||||
|
<section id="main-wrap">
|
||||||
|
<div class="sign-up have-other-sign-in">
|
||||||
|
<div class="form">
|
||||||
|
<h3 class="login-logo">Error</h3>
|
||||||
|
<div class="option-block">
|
||||||
|
<div class="option-block msg">There was a problem in getting your user info, please try again later.</div>
|
||||||
|
<a href="javascript:void(0);" onclick="window.close();">Close Window</a>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</section>
|
|
@ -19,6 +19,9 @@ Orbit::Application.routes.draw do
|
||||||
match 'load_orbit_bar' => 'pages#load_orbit_bar'
|
match 'load_orbit_bar' => 'pages#load_orbit_bar'
|
||||||
get 'basic_infos' => "basic_infos#index"
|
get 'basic_infos' => "basic_infos#index"
|
||||||
get 'basic_infos/form' => "basic_infos#form_page"
|
get 'basic_infos/form' => "basic_infos#form_page"
|
||||||
|
get 'basic_infos/role_page' => "basic_infos#role_page"
|
||||||
|
post 'basic_infos/role_update' => "basic_infos#role_update"
|
||||||
|
match 'basic_infos/basic_info_update' => "basic_infos#basic_info_update"
|
||||||
# routes for admin
|
# routes for admin
|
||||||
namespace :admin do
|
namespace :admin do
|
||||||
match 'user_actions' => 'user_actions#index'
|
match 'user_actions' => 'user_actions#index'
|
||||||
|
@ -321,6 +324,7 @@ Orbit::Application.routes.draw do
|
||||||
match "/facebook/get_friends" => "facebook#get_friends"
|
match "/facebook/get_friends" => "facebook#get_friends"
|
||||||
match "/facebook/disconnect" => "facebook#disconnect"
|
match "/facebook/disconnect" => "facebook#disconnect"
|
||||||
match "/facebook/server" => "facebook#server_redirect"
|
match "/facebook/server" => "facebook#server_redirect"
|
||||||
|
match "/facebook/profile_import" => "facebook#profile_import"
|
||||||
match "/desktop/wallpaper_upload" => "desktop#wallpaper_upload"
|
match "/desktop/wallpaper_upload" => "desktop#wallpaper_upload"
|
||||||
|
|
||||||
#match '/desktop_orbit/eventajaxload' => 'desktop_publications#create_journal'
|
#match '/desktop_orbit/eventajaxload' => 'desktop_publications#create_journal'
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
"type": "sftp",
|
"type": "sftp",
|
||||||
|
|
||||||
"save_before_upload": true,
|
"save_before_upload": true,
|
||||||
"upload_on_save": false,
|
"upload_on_save": true,
|
||||||
"sync_down_on_open": false,
|
"sync_down_on_open": false,
|
||||||
"sync_skip_deletes": false,
|
"sync_skip_deletes": false,
|
||||||
"confirm_downloads": false,
|
"confirm_downloads": false,
|
||||||
|
|
Loading…
Reference in New Issue