Segui l'argomento usando l'indirizzo email senza richiedere la registrazione

Ho passato del tempo di qualità a scavare nel codice. Penso che qualcosa del genere (avviso: molto probabilmente non funzionante perché non l’ho ancora provato) funzionerebbe per consentire all’utente di pubblicare una risposta con solo un’email. Apprezzerei qualsiasi commento tu abbia.

Non sono particolarmente sicuro se questo sia il modo migliore per creare un utente “staged”. Non ho trovato alcun metodo che crei specificamente utenti “staged”, tuttavia.

class SomePluginController < ApplicationController

  # Assicurati che ci sia un utente "staged" nel db
  def ensure_user

    # Controlla se esiste un utente "staged"
    user = User.where(staged: true).with_email(params[:email].strip.downcase).first

    # Crea manualmente un utente "staged"
    if !user
      user = User.new
      user.staged = true
      user.email = params[:email]
      user.active = false
      user.save!
    end
    
    user
  end

  # Guarda il topic come utente "staged"
  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

  # Rispondi al topic come utente "staged"
  def staged_reply
 
    user = ensure_user

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

  end

end
3 Mi Piace