diff --git a/app/assets/stylesheets/sign_up.css b/app/assets/stylesheets/sign_up.css index 3e76f594..e681da25 100644 --- a/app/assets/stylesheets/sign_up.css +++ b/app/assets/stylesheets/sign_up.css @@ -46,6 +46,16 @@ opacity: 0.8; } +.sign-up .role-label{ + display: inline; + margin-left: 3px; + margin-right: 10px; +} + +.sign-up input[type=checkbox]{ + margin-top: 0; +} + .line{ border-bottom: 1px solid #EDEDED; } diff --git a/app/controllers/basic_infos_controller.rb b/app/controllers/basic_infos_controller.rb index 3439721b..2d91bfc7 100644 --- a/app/controllers/basic_infos_controller.rb +++ b/app/controllers/basic_infos_controller.rb @@ -1,9 +1,38 @@ class BasicInfosController < ApplicationController layout "devise" def index + if current_user.nil? + redirect_to "/users/sign_up" + end + @user = current_user end 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 \ No newline at end of file diff --git a/app/controllers/facebook_controller.rb b/app/controllers/facebook_controller.rb index 247b16cd..9dc7c581 100644 --- a/app/controllers/facebook_controller.rb +++ b/app/controllers/facebook_controller.rb @@ -4,6 +4,8 @@ require 'json' class FacebookController< ApplicationController + @@facebook_server = "http://fb.tp.rulingcom.com" + def register_fb user = User.find(params[:user]) if !user.facebook @@ -17,8 +19,9 @@ class FacebookController< ApplicationController end def get_friends - if current_user.facebook - @url = "http://fb.tp.rulingcom.com/get_friends?identifier=" + current_user.facebook.fb_identifier + fb = current_user.facebook rescue nil + if fb + @url = "#{@@facebook_server}/get_friends?identifier=" + current_user.facebook.fb_identifier uri = URI.parse(@url) http = Net::HTTP.new(uri.host, uri.port) request = Net::HTTP::Get.new(uri.request_uri) @@ -43,8 +46,43 @@ class FacebookController< ApplicationController render :json=>{"success"=>true}.to_json 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 - # "http://fb.tp.rulingcom.com/login?callback=http://harry.tp.rulingcom.com/facebook/register_fb?user="+current_user.id.to_s rescue nil - redirect_to "http://new.tp.rulingcom.com" + @url = "#{@@facebook_server}/login?callback=#{request.protocol}#{request.host_with_port}/facebook/register_fb?user="+current_user.id.to_s rescue nil + if !@url.nil? + redirect_to @url + else + render :layout=> "devise" + end end end \ No newline at end of file diff --git a/app/views/basic_infos/_form_page.html.erb b/app/views/basic_infos/_form_page.html.erb new file mode 100644 index 00000000..ca4d1514 --- /dev/null +++ b/app/views/basic_infos/_form_page.html.erb @@ -0,0 +1,130 @@ + + <%#= devise_error_messages! %> + + +
+
+

<%=t(:sys_basic_form)%>

+
+
+ + +
+ <%= f.label t("users.avatar"),:class=>"control-label muted" %> +
+ +
+
+ <% if @user.avatar? %> + <%= image_tag(@user.avatar.thumb.url) %> + <% else %> + <%= image_tag "person.png" %> + <% end %> +
+
+ + <%= t(:select_image) %> + <%= t(:change) %> + <%= f.file_field :avatar %> + + <%= t(:cancel) %> +
+
+
+ + +
+ <%= f.label t("users.first_name"),{:class=>"control-label muted", :func=>"field_label"} %> +
+
+
+
+ <% @site_valid_locales.each_with_index do |locale, i| %> +
" 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 %> +
+ <% end %> +
+
+ <% @site_valid_locales.each_with_index do |locale, i| %> + " href="#first_name_<%= locale %>" data-toggle="tab"><%= I18nVariable.from_locale(locale) %> + <% end %> + +
+
+
+
+
+ + +
+ <%= f.label t("users.last_name"),{:class=>"control-label muted", :func=>"field_label"} %> +
+
+
+
+ <% @site_valid_locales.each_with_index do |locale, i| %> +
" 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 %> +
+ <% end %> +
+
+ <% @site_valid_locales.each_with_index do |locale, i| %> + " href="#last_name_<%= locale %>" data-toggle="tab"><%= I18nVariable.from_locale(locale) %> + <% end %> + +
+
+
+
+
+ + +
+ <%= f.label t("users.email"),:class=>"control-label muted" %> +
+ <%= f.email_field :email %> +
+
+ + +
+ <%= f.label t("users.sid"),:class=>"control-label muted" %> +
+ <%= f.text_field :sid %> + <%= t("users.sid_note")%> +
+
+ + +
+ <%= f.label t("users.office_tel"),:class=>"control-label muted" %> +
+ <%= f.text_field :office_tel %> + <%= t("users.office_tel_note")%> +
+
+ + +
+ <%= f.label t("users.sex"),:class=>"control-label muted" %> +
+ + + +
+
+ +
+
diff --git a/app/views/basic_infos/form_page.html.erb b/app/views/basic_infos/form_page.html.erb index 771cd869..f82effce 100644 --- a/app/views/basic_infos/form_page.html.erb +++ b/app/views/basic_infos/form_page.html.erb @@ -1 +1,35 @@ -<%= stylesheet_link_tag "sign_up" %> \ No newline at end of file +<% 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| %> + +
+
+ + <%= f.error_messages %> + <%= render :partial => 'form_page', :locals => {:f => f}%> + +
+ +
+ +
+ +
+ +<% end -%> diff --git a/app/views/basic_infos/index.html.erb b/app/views/basic_infos/index.html.erb index bd6333f8..8df10bcc 100644 --- a/app/views/basic_infos/index.html.erb +++ b/app/views/basic_infos/index.html.erb @@ -4,7 +4,7 @@
- Form + Form
OR @@ -12,7 +12,7 @@
-
+


Next
@@ -24,14 +24,32 @@ timeInterval = null; $("a.facebook").click(function(){ facebookWindow = window.open('<%= facebook_server_path %>','login_window','height=668,width=1124,titlebar=0,statusbar=0,location=0'); + clearInterval(timeInterval); timeInterval = setInterval(function(){ if( facebookWindow.closed ){ clearInterval(timeInterval); - $.getJSON("/facebook/get_friends",function(data){ - if(!data.success){ - $(".msg").text(data.message); - }else{ - $(".msg").text("Import Succesfull!"); + $(".msg").removeClass('hide').find("h4").text("Importing,please wait..."); + $.ajax({ + url : "/facebook/profile_import", + data : {"user_id":"<%= @user.id.to_s %>"}, + 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!"); } }) } diff --git a/app/views/basic_infos/role_page.html.erb b/app/views/basic_infos/role_page.html.erb new file mode 100644 index 00000000..069fff6a --- /dev/null +++ b/app/views/basic_infos/role_page.html.erb @@ -0,0 +1,32 @@ +<%= stylesheet_link_tag "sign_up" %> +
+
+ + <% flash.each do |key, msg| %> + <%= content_tag :p, msg, :class => [key, "alert alert-error in fade"] %> + <% end %> + +
+ +
+
+
+ +
+ <% @roles.each do |role| %> + + + <% end %> + +

+ + +
+
+
+ +
+
\ No newline at end of file diff --git a/app/views/facebook/server_redirect.html.erb b/app/views/facebook/server_redirect.html.erb new file mode 100644 index 00000000..3bb865f6 --- /dev/null +++ b/app/views/facebook/server_redirect.html.erb @@ -0,0 +1,13 @@ + +<%= stylesheet_link_tag "sign_up" %> +
+
+
+ +
+
There was a problem in getting your user info, please try again later.
+ Close Window +
+ +
+
\ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 617f09b9..3b638b32 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -19,6 +19,9 @@ Orbit::Application.routes.draw do match 'load_orbit_bar' => 'pages#load_orbit_bar' get 'basic_infos' => "basic_infos#index" 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 namespace :admin do match 'user_actions' => 'user_actions#index' @@ -321,6 +324,7 @@ Orbit::Application.routes.draw do match "/facebook/get_friends" => "facebook#get_friends" match "/facebook/disconnect" => "facebook#disconnect" match "/facebook/server" => "facebook#server_redirect" + match "/facebook/profile_import" => "facebook#profile_import" match "/desktop/wallpaper_upload" => "desktop#wallpaper_upload" #match '/desktop_orbit/eventajaxload' => 'desktop_publications#create_journal' diff --git a/sftp-config.json b/sftp-config.json index f489bec4..0e0efa6c 100644 --- a/sftp-config.json +++ b/sftp-config.json @@ -6,7 +6,7 @@ "type": "sftp", "save_before_upload": true, - "upload_on_save": false, + "upload_on_save": true, "sync_down_on_open": false, "sync_skip_deletes": false, "confirm_downloads": false,