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! %> + + +