I've added omniauth to my 1.3 app based on the app from
https://github.com/enwood/hobo-omniauth-bare-app/

The thing is the app was set to send an activation link and there is
no way to resend one tho it should. There is also no way to reset the
password if the user isn't active (It works if he is active.)

I'm not sure if its due to omniauth as it has an active transition or
what but it seems to process the controller but doesn't send the
email. Any ideas?

Relevant models and controllers below.

class UsersController < ApplicationController

  hobo_user_controller

  auto_actions :all, :except => [ :index, :new, :create ]
  index_action :omniauth_callback

  # Normally, users should be created via the user lifecycle, except
  #  for the initial user created via the form on the front screen on
  #  first run.  This method creates the initial user.
  def create
    hobo_create do
      if valid?
        self.current_user = this
        flash[:notice] =
t("hobo.messages.you_are_site_admin", :default=>"You are now the site
administrator")
        redirect_to home_page
      end
    end
  end

  def omniauth_callback
    # Try and find a user with matching authorization credentials
    if self.this = Authorization.auth(request.env["omniauth.auth"],
current_user)
      sign_user_in(self.this.user)
    else
      if !request.env["omniauth.auth"].nil?
        raise request.env["omniauth.auth"].to_yaml
      else
        raise request.env["message"].to_yaml
      end
    end
  end

end

class User < ActiveRecord::Base

  hobo_user_model # Don't put anything above this

  fields do
    name          :string, :required, :unique
    email_address :email_address, :login => true,  :validate => false
    administrator :boolean, :default => false
    timestamps
  end


  # --- Associations --- #
  has_many :authorizations
  has_many :comments, :class_name => "Comment", :foreign_key =>
"owner_id"
  has_many :chapters, :class_name => "Chapter", :foreign_key =>
"owner_id"
  has_many :pages, :class_name => "Page", :foreign_key => "owner_id"


  # This gives admin rights and an :active state to the first sign-up.
  # Just remove it if you don't want that
  before_create do |user|
    if !Rails.env.test? && user.class.count == 0
      user.administrator = true
      user.state = "active"
    end
  end


  # --- Signup lifecycle --- #

  lifecycle do

    state :inactive, :default => true
    state :active

    # Called from Authorization#auth to create a new user with the
name
    # supplied by the provider.
    create :authorize, :params => [:name], :become => :active

    create :signup, :available_to => "Guest",
      :params =>
[:name, :email_address, :password, :password_confirmation],
      :become => :inactive, :new_key => true  do
      UserMailer.activation(self, lifecycle.key).deliver
    end

    transition :activate, { :inactive => :active }, :available_to
=> :key_holder

    transition :request_password_reset, { :inactive
=> :inactive }, :new_key => true do
      UserMailer.activation(self, lifecycle.key).deliver
    end

    transition :request_password_reset, { :active
=> :active }, :new_key => true do
      UserMailer.forgot_password(self, lifecycle.key).deliver
    end

    transition :reset_password, { :active => :active }, :available_to
=> :key_holder,
               :params => [ :password, :password_confirmation ]

  end

  def signed_up?
    state=="active"
  end

  # --- Permissions --- #

  def create_permitted?
    # Only the initial admin user can be created
    self.class.count == 0
  end

  def update_permitted?
    acting_user.administrator? ||
      (acting_user == self && only_changed?
(:email_address, :crypted_password,
                                            :current_password, :password, 
:password_confirmation))
    # Note: crypted_password has attr_protected so although it is
permitted to change, it cannot be changed
    # directly from a form submission.
  end

  def destroy_permitted?
    acting_user.administrator?
  end

  def view_permitted?(field)
    true
  end
end


class UserMailer < ActionMailer::Base
  default :from => "no-reply@#{host}"

  def forgot_password(user, key)
    @user, @key = user, key
    mail( :subject => "#{app_name} -- forgotten password",
          :to      => user.email_address )
  end


  def activation(user, key)
    @user, @key = user, key
    mail( :subject => "#{app_name} -- activate",
          :to      => user.email_address )
  end

end

-- 
You received this message because you are subscribed to the Google Groups "Hobo 
Users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/hobousers?hl=en.

Reply via email to