이메일 주소로 회원 가입 없이 주제 구독하기

코드를 꼼꼼히 살펴봤습니다. 아래처럼 하면 이메일만으로도 사용자가 답변을 게시할 수 있을 것 같습니다(경고: 아직 테스트해 보지 않아 작동하지 않을 가능성이 높음). 여러분의 의견이 있다면 알려주시면 감사하겠습니다.

특히 이렇게 스테이징(staged) 사용자를 생성하는 것이 최선의 방법인지 확신이 서지 않습니다. 스테이징 사용자를 명시적으로 생성하는 메서드를 아직 찾지 못했기 때문입니다.

class SomePluginController < ApplicationController

  # Make sure there is a staged user in the db
  def ensure_user

    # See if staged user exists
    user = User.where(staged: true).with_email(params[:email].strip.downcase).first

    # Create a staged user manually
    if !user
      user = User.new
      user.staged = true
      user.email = params[:email]
      user.active = false
      user.save!
    end
    
    user
  end

  # Watch topic as a staged user
  def staged_watch

    user = ensure_user

    topic = Topic.find(params[:topic_id].to_i)
    TopicUser.change(user, topic.id, notification_level: params[:notification_level].to_i)

  end

  # Reply to topic as a staged user
  def staged_reply
 
    user = ensure_user

    manager = NewPostManager.new(user,
                             raw: params[:body],
                             topic_id: params[:topic_id])
    result = manager.perform

  end

end
4개의 좋아요