Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class ProfilesController < ApplicationController
- layout "application_old"
- before_filter CASClient::Frameworks::Rails::Filter, :only => [:index, :update_state, :update_location, :screen_availability]
- before_filter :valid_rest_challenge?, :only => [:check_screen_name, :show, :new, :create, :update]
- def index
- if admin?
- redirect_to admin_dashboard_index_path
- elsif parent?
- redirect_to parent_profiles_path
- else
- redirect_to student_profile_path
- end
- end
- def check_screen_name
- @profile = Profile.find_by_screen_name(params[:screen_name])
- respond_to do |format|
- format.xml { render :xml => {:has_screen_name => !@profile.nil?} }
- end
- end
- def show
- @profile = Profile.find_by_user_id(params[:id])
- respond_to do |format|
- format.xml { render :xml => @profile }
- end
- end
- def new
- @profile = Profile.new
- respond_to do |format|
- format.xml { render :xml => @profile }
- end
- end
- def create
- @profile = Profile.new(params[:profile])
- if @profile.parent_id
- profile = Profile.find_by_user_id @profile.parent_id
- @profile.parent_id = profile.nil? ? nil : profile.id
- end
- respond_to do |format|
- if @profile.save
- format.xml { render :xml => @profile, :status => :created, :location => @profile }
- else
- format.xml { render :xml => @profile.errors, :status => :unprocessable_entity }
- end
- end
- end
- def update
- @profile = Profile.find(params[:id])
- respond_to do |format|
- if @profile.update_attributes(params[:profile])
- if @profile.parent_id
- profile = Profile.find_by_user_id @profile.parent_id
- @profile.parent_id = profile.nil? ? nil : profile.id
- @profile.save
- end
- format.xml { head :ok }
- else
- format.xml { render :xml => @profile.errors, :status => :unprocessable_entity }
- end
- end
- end
- def destroy
- @profile = Profile.find(params[:id])
- @profile.destroy
- respond_to do |format|
- format.xml { head :ok }
- end
- end
- # API methods end here ------------
- # update_state_profile
- # GET /profile/update_state
- def update_state
- if params[:request]
- @country = Country.find(params[:requested_profile][:country_id])
- @request = true
- elsif params[:reward_transaction]
- @country = Country.find(params[:real_reward_transaction_log][:country_id])
- else
- @country = Country.find(params[:profile][:country_id])
- @request = false
- end
- @states = @country.states
- respond_to do |format|
- format.js {
- render :partial => "state", :locals => { :states => @states, :request => @request }
- }
- end
- end
- # screen_availability_profile
- # GET /profile/screen_availability
- # def screen_availability
- # if params[:request]
- # @screen_name = params[:requested_profile][:screen_name].strip
- # else
- # @screen_name = params[:profile][:screen_name].strip
- # end
- #
- # all_screen_names = Validation::ScreenName.all_scren_names
- # screen_name_available = all_screen_names.include?(@screen_name)
- # check_format = Validation::ScreenName.match_format(@screen_name)
- #
- # if check_format.nil?
- # @available = 3
- # @screen_availibility_check_msg = " <strong style='color:#FF5D4A;'>Screen name can only contain letters , numbers and some punctuation like _ , @ and spaces are permitted.</strong>"
- # else
- # if screen_name_available
- # if params[:screen_name] == @screen_name or (!current_user_profile.is_parent and current_user_profile.screen_name == @screen_name)
- # @screen_availibility_check_msg = " <strong style='color:#358F63;'>is available.</strong>"
- # else
- # @screen_availibility_check_msg = " <strong style='color:#FF5D4A;'>is not available.</strong>"
- # end
- # else
- # @screen_availibility_check_msg = " <strong style='color:#358F63;'>is available.</strong>"
- # end
- # end
- # respond_to do |format|
- # format.js{
- # render :partial => "check_screen_availability", :locals => { :screen_name => @screen_name, :screen_availibility_check_msg => @screen_availibility_check_msg }
- # }
- # end
- # end
- end
Add Comment
Please, Sign In to add comment