From 3b0bbd42895d7769255aba047894120808249379 Mon Sep 17 00:00:00 2001 From: Pavel Date: Sun, 4 Apr 2010 16:00:08 +0300 Subject: [PATCH] d --- online/app/controllers/user_controller.rb | 127 ++++++++++++++++-------------- 1 file changed, 66 insertions(+), 61 deletions(-) diff --git a/online/app/controllers/user_controller.rb b/online/app/controllers/user_controller.rb index aa87cdc..728239f 100644 --- a/online/app/controllers/user_controller.rb +++ b/online/app/controllers/user_controller.rb @@ -34,71 +34,76 @@ class UserController < ApplicationController end def permission @userF = session[:facebook_session].user - if @userF.has_permission?("publish_stream") && session[:facebook_session].user.has_permission?("email") - @fbuser = User.find(:first, :conditions => ["uid = ?", @userF.uid]) - - if @fbuser && @fbuser.deleted - debug_message("User #{session[:facebook_session].user.uid} was already exist but he was in deleted status. So now he is totally deleted and will be added soon") - @fbuser.destroy - @fbuser = nil - end - #if user does not exist yet in DB inserting in DB - if @fbuser == nil - #getting user info - begin - #if user has birthday - if @userF.birthday != nil - birthday_mask = /(\w+)\ (\d+)\, (\d+)/ - dateOfBirth = birthday_mask.match(@userF.birthday) - #if birthday ok for us - if (Months[$1] == nil) - birthday = "" + @fbuser = User.find(:first, :conditions => ["uid = ?", @userF.uid]) + if @fbuser.blank? + if @userF.has_permission?("publish_stream") && session[:facebook_session].user.has_permission?("email") + @fbuser = User.find(:first, :conditions => ["uid = ?", @userF.uid]) + + if @fbuser && @fbuser.deleted + debug_message("User #{session[:facebook_session].user.uid} was already exist but he was in deleted status. So now he is totally deleted and will be added soon") + @fbuser.destroy + @fbuser = nil + end + #if user does not exist yet in DB inserting in DB + if @fbuser == nil + #getting user info + begin + #if user has birthday + if @userF.birthday != nil + birthday_mask = /(\w+)\ (\d+)\, (\d+)/ + dateOfBirth = birthday_mask.match(@userF.birthday) + #if birthday ok for us + if (Months[$1] == nil) + birthday = "" + else + birthday = Date.new(dateOfBirth[3].to_i,Months[dateOfBirth[1]],dateOfBirth[2].to_i) + end else - birthday = Date.new(dateOfBirth[3].to_i,Months[dateOfBirth[1]],dateOfBirth[2].to_i) + birthday = "" + #end if @userF.birthday != nil end - else - birthday = "" - #end if @userF.birthday != nil - end - #gathering affiliations - @affiliation = "" - if @userF.affiliations - @userF.affiliations.each do |one_affiliation| - @affiliation += one_affiliation.name + " | " + #gathering affiliations + @affiliation = "" + if @userF.affiliations + @userF.affiliations.each do |one_affiliation| + @affiliation += one_affiliation.name + " | " + end end + + #gathering other params + myParams = { + :uid => @userF.uid, + :birthday => birthday, + :relation => @userF.relationship_status, + :gender => @userF.sex, + :first_name => @userF.first_name, + :last_name => @userF.last_name, + :status => "WAS NOT SET YET" , + :hometown_location => (@userF.hometown_location != nil) ? @userF.hometown_location.country.to_s + "/"+ @userF.hometown_location.state.to_s + "/" + @userF.hometown_location.city.to_s : "", + :affiliations => @affiliation, + :usermail => @userF.email + + } + rescue + debug_message("Cannot get information about #{session[:facebook_session].user.uid}",false) + render :facebook_error + else + #saving user into DB + @fbuser = User.new(myParams) + debug_message("User #{session[:facebook_session].user.uid} was added to DB") + @fbuser.save + add_stat(@userF.uid, PERMISSION) + + #end of getting user info end - - #gathering other params - myParams = { - :uid => @userF.uid, - :birthday => birthday, - :relation => @userF.relationship_status, - :gender => @userF.sex, - :first_name => @userF.first_name, - :last_name => @userF.last_name, - :status => "WAS NOT SET YET" , - :hometown_location => (@userF.hometown_location != nil) ? @userF.hometown_location.country.to_s + "/"+ @userF.hometown_location.state.to_s + "/" + @userF.hometown_location.city.to_s : "", - :affiliations => @affiliation, - :usermail => @userF.email - - } - rescue - debug_message("Cannot get information about #{session[:facebook_session].user.uid}",false) - render :facebook_error - else - #saving user into DB - @fbuser = User.new(myParams) - debug_message("User #{session[:facebook_session].user.uid} was added to DB") - @fbuser.save - add_stat(@userF.uid, PERMISSION) - - #end of getting user info - end - #end if @fbuser == nil - end - today_question_select 0 - @question_number = "question1" - render :action => @question_number + #end if @fbuser == nil + end + today_question_select 0 + @question_number = "question1" + render :action => @question_number + #if @userF.has_permission?("publish_stream") + end + #if user not in DB end end -- 2.11.4.GIT