Guest User

Untitled

a guest
Jul 21st, 2018
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.37 KB | None | 0 0
  1. class ProfilesController < ApplicationController
  2. layout "application_old"
  3. before_filter CASClient::Frameworks::Rails::Filter, :only => [:index, :update_state, :update_location, :screen_availability]
  4. before_filter :valid_rest_challenge?, :only => [:check_screen_name, :show, :new, :create, :update]
  5.  
  6. def index
  7. if admin?
  8. redirect_to admin_dashboard_index_path
  9. elsif parent?
  10. redirect_to parent_profiles_path
  11. else
  12. redirect_to student_profile_path
  13. end
  14. end
  15.  
  16. def check_screen_name
  17. @profile = Profile.find_by_screen_name(params[:screen_name])
  18.  
  19. respond_to do |format|
  20. format.xml { render :xml => {:has_screen_name => !@profile.nil?} }
  21. end
  22. end
  23.  
  24. def show
  25. @profile = Profile.find_by_user_id(params[:id])
  26.  
  27. respond_to do |format|
  28. format.xml { render :xml => @profile }
  29. end
  30. end
  31.  
  32.  
  33. def new
  34. @profile = Profile.new
  35.  
  36. respond_to do |format|
  37. format.xml { render :xml => @profile }
  38. end
  39. end
  40.  
  41.  
  42. def create
  43. @profile = Profile.new(params[:profile])
  44.  
  45. if @profile.parent_id
  46. profile = Profile.find_by_user_id @profile.parent_id
  47. @profile.parent_id = profile.nil? ? nil : profile.id
  48. end
  49.  
  50. respond_to do |format|
  51. if @profile.save
  52. format.xml { render :xml => @profile, :status => :created, :location => @profile }
  53. else
  54. format.xml { render :xml => @profile.errors, :status => :unprocessable_entity }
  55. end
  56. end
  57. end
  58.  
  59.  
  60. def update
  61. @profile = Profile.find(params[:id])
  62. respond_to do |format|
  63. if @profile.update_attributes(params[:profile])
  64. if @profile.parent_id
  65. profile = Profile.find_by_user_id @profile.parent_id
  66. @profile.parent_id = profile.nil? ? nil : profile.id
  67. @profile.save
  68. end
  69. format.xml { head :ok }
  70. else
  71. format.xml { render :xml => @profile.errors, :status => :unprocessable_entity }
  72. end
  73. end
  74. end
  75.  
  76. def destroy
  77. @profile = Profile.find(params[:id])
  78.  
  79. @profile.destroy
  80. respond_to do |format|
  81.  
  82. format.xml { head :ok }
  83. end
  84. end
  85.  
  86. # API methods end here ------------
  87.  
  88. # update_state_profile
  89. # GET /profile/update_state
  90. def update_state
  91. if params[:request]
  92. @country = Country.find(params[:requested_profile][:country_id])
  93. @request = true
  94. elsif params[:reward_transaction]
  95. @country = Country.find(params[:real_reward_transaction_log][:country_id])
  96. else
  97. @country = Country.find(params[:profile][:country_id])
  98. @request = false
  99. end
  100.  
  101. @states = @country.states
  102. respond_to do |format|
  103. format.js {
  104. render :partial => "state", :locals => { :states => @states, :request => @request }
  105. }
  106. end
  107. end
  108.  
  109. # screen_availability_profile
  110. # GET /profile/screen_availability
  111. # def screen_availability
  112. # if params[:request]
  113. # @screen_name = params[:requested_profile][:screen_name].strip
  114. # else
  115. # @screen_name = params[:profile][:screen_name].strip
  116. # end
  117. #
  118. # all_screen_names = Validation::ScreenName.all_scren_names
  119. # screen_name_available = all_screen_names.include?(@screen_name)
  120. # check_format = Validation::ScreenName.match_format(@screen_name)
  121. #
  122. # if check_format.nil?
  123. # @available = 3
  124. # @screen_availibility_check_msg = " <strong style='color:#FF5D4A;'>Screen name can only contain letters , numbers and some punctuation like _ , @ and spaces are permitted.</strong>"
  125. # else
  126. # if screen_name_available
  127. # if params[:screen_name] == @screen_name or (!current_user_profile.is_parent and current_user_profile.screen_name == @screen_name)
  128. # @screen_availibility_check_msg = " <strong style='color:#358F63;'>is available.</strong>"
  129. # else
  130. # @screen_availibility_check_msg = " <strong style='color:#FF5D4A;'>is not available.</strong>"
  131. # end
  132. # else
  133. # @screen_availibility_check_msg = " <strong style='color:#358F63;'>is available.</strong>"
  134. # end
  135. # end
  136. # respond_to do |format|
  137. # format.js{
  138. # render :partial => "check_screen_availability", :locals => { :screen_name => @screen_name, :screen_availibility_check_msg => @screen_availibility_check_msg }
  139. # }
  140. # end
  141. # end
  142. end
Add Comment
Please, Sign In to add comment