app/controllers/users_controller.rb
# GET named route /users/:user_id/verify/:validation_code
# users come here from the activation email they receive after registering with EOL credentials
GET named route /users/:user_id/verify/:validation_code
users come here from the activation email they receive after registering with EOL credentials
GET named route / users / : user_id / verify / : validation_code users come here from the activation email they receive after registering with EOL credentials
def verify
    user_id = params[:user_id] || 0
    User.with_master do
      @user = User.find_by_username(User.username_from_verify_url(user_id))
      if user_id.is_numeric? && (!@user || (@user.validation_code && !params[:validation_code].blank? && @user.validation_code != params[:validation_code]))
        @user = User.find(user_id.to_i)
      end
    end
    if @user && @user.active
      flash[:notice] = I18n.t(:user_already_active_notice)
      redirect_to login_path, status: :moved_permanently
    elsif @user && @user.validation_code == params[:validation_code] && !params[:validation_code].blank?
      @user.activate
      Notifier.user_activated(@user).deliver
      flash[:notice] = I18n.t(:user_activation_successful_notice, username: @user.username)
      session[:conversion_code] = User.generate_key
      redirect_to activated_user_path(@user, success: session[:conversion_code]), status: :moved_permanently
    elsif @user
      @user.validation_code = User.generate_key if @user.validation_code.blank?
      send_verification_email
      flash[:error] = I18n.t(:user_activation_failed_resent_validation_email_error)
      redirect_to pending_user_path(@user), status: :moved_permanently
    else
      flash[:error] = I18n.t(:user_activation_failed_user_not_found_error)
      redirect_to new_user_path
    end
  end
def verify user_id = params [ :user_id ] || 0 User . with_master do @user = User . find_by_username ( User . username_from_verify_url ( user_id ) ) if user_id . is_numeric? && ( ! @user || ( @user . validation_code && ! params [ :validation_code ] . blank? && @user . validation_code != params [ :validation_code ] ) ) @user = User . find ( user_id . to_i ) end end if @user && @user . active flash [ :notice ] = I18n . t ( :user_already_active_notice ) redirect_to login_path , status : :moved_permanently elsif @user && @user . validation_code == params [ :validation_code ] && ! params [ :validation_code ] . blank? @user . activate Notifier . user_activated ( @user ) . deliver flash [ :notice ] = I18n . t ( :user_activation_successful_notice , username : @user . username ) session [ :conversion_code ] = User . generate_key redirect_to activated_user_path ( @user , success : session [ :conversion_code ] ) , status : :moved_permanently elsif @user @user . validation_code = User . generate_key if @user . validation_code . blank? send_verification_email flash [ :error ] = I18n . t ( :user_activation_failed_resent_validation_email_error ) redirect_to pending_user_path ( @user ) , status : :moved_permanently else flash [ :error ] = I18n . t ( :user_activation_failed_user_not_found_error ) redirect_to new_user_path end end
GET named route /users/:user_id/verify/:validation_code
users come here from the activation email they receive after registering with EOL credentials
GET named route / users / : user_id / verify / : validation_code users come here from the activation email they receive after registering with EOL credentials
# we need to first check for usernames as some people may have received the validation # link with the username before we changed the links to use user IDs on 10.26.2011 # we couldn't find the user by username (we're searching for usernames matching the user_id parameter) # OR we did find a user, but it had a different validation code, so look it up by ID