Elixir issue with Bamboo.SentEmailViewerPlug - email

I do have an issue with mentioned function. This is the error from browser:
function Bamboo.SentEmailViewerPlug.init/1 is undefined (module Bamboo.SentEmailViewerPlug is not available)
And this is from console :
[error] #PID<0.868.0> running RewardappWeb.Endpoint (connection #PID<0.829.0>, stream id 4) terminated
Server: localhost:4000 (http)
Request: GET /mailbox
** (exit) an exception was raised:
** (UndefinedFunctionError) function Bamboo.SentEmailViewerPlug.init/1 is undefined (module Bamboo.SentEmailViewerPlug is not available)
Bamboo.SentEmailViewerPlug.init([])
(phoenix 1.6.6) lib/phoenix/router/route.ex:41: Phoenix.Router.Route.call/2
(phoenix 1.6.6) lib/phoenix/router.ex:355: Phoenix.Router.__call__/2
(rewardapp 0.1.0) lib/rewardapp_web/endpoint.ex:1: RewardappWeb.Endpoint.plug_builder_call/2
(rewardapp 0.1.0) lib/plug/debugger.ex:136: RewardappWeb.Endpoint."call (overridable 3)"/2
(rewardapp 0.1.0) lib/rewardapp_web/endpoint.ex:1: RewardappWeb.Endpoint.call/2
(phoenix 1.6.6) lib/phoenix/endpoint/cowboy2_handler.ex:54: Phoenix.Endpoint.Cowboy2Handler.init/4
(cowboy 2.9.0) /Users/mateuszosinski/Desktop/elixir/rewardapp/deps/cowboy/src/cowboy_handler.erl:37: :cowboy_handler.execute/2
(cowboy 2.9.0) /Users/mateuszosinski/Desktop/elixir/rewardapp/deps/cowboy/src/cowboy_stream_h.erl:306: :cowboy_stream_h.execute/3
(cowboy 2.9.0) /Users/mateuszosinski/Desktop/elixir/rewardapp/deps/cowboy/src/cowboy_stream_h.erl:295: :cowboy_stream_h.request_process/3
(stdlib 3.17.1) proc_lib.erl:226: :proc_lib.init_p_do_apply/3
Here is my router.ex file :
defmodule RewardappWeb.Router do
use RewardappWeb, :router
use Phoenix.Router
pipeline :browser do
plug :accepts, ["html"]
plug :fetch_session
plug :fetch_live_flash
plug :put_root_layout, {RewardappWeb.LayoutView, :root}
plug :protect_from_forgery
plug :put_secure_browser_headers
end
pipeline :api do
plug :accepts, ["json"]
end
scope "/", RewardappWeb do
pipe_through :browser
#get "/", PageController, :index
#NEW ROUTES
#get "/users", GrantController, :login
get "/admin", GrantController, :admin
get "/main", GrantController, :main
get "/", GrantController, :index
post "/", GrantController, :login
get "/add", GrantController, :add
post "/add/:id", GrantController, :update
get "/admin/delete/:id", GrantController, :delete
end
if Mix.env == :dev do
forward "/mailbox", Bamboo.SentEmailViewerPlug
end
# Other scopes may use custom stacks.
# scope "/api", RewardappWeb do
# pipe_through :api
# end
# Enables LiveDashboard only for development
#
# If you want to use the LiveDashboard in production, you should put
# it behind authentication and allow only admins to access it.
# If your application does not have an admins-only section yet,
# you can use Plug.BasicAuth to set up some basic authentication
# as long as you are also using SSL (which you should anyway).
if Mix.env() in [:dev, :test] do
import Phoenix.LiveDashboard.Router
scope "/" do
pipe_through :browser
live_dashboard "/dashboard", metrics: RewardappWeb.Telemetry
end
end
# Enables the Swoosh mailbox preview in development.
#
# Note that preview only shows emails that were sent by the same
# node running the Phoenix server.
if Mix.env() == :dev do
scope "/dev" do
pipe_through :browser
#forward "/mailbox", Plug.Swoosh.MailboxPreview
end
end
end
Mails are being sent totally fine - I have inspected that with IO.inspect, and right now, they are sent fine. However, I can not attempt to see localhost:4000/mailbox. Where is my mistake? Thank you in advance!!

The issue was with wrong name Bamboo module name.

Related

Authorization graphql subscriptions with elixir and absinthe using cookies

I'm trying make authorization/authentication graphql subscriptions with elixir and absinthe using cookies and I used the follow link:
https://nts.strzibny.name/graphql-subscriptions-with-elixir-and-absinth/
I'm trying authenticate the user for subscribe the right topic but I don't have access to the cookies in the subscription connection. Why?
After I saw the follow link:
https://hexdocs.pm/absinthe_phoenix/Absinthe.Phoenix.Socket.html
And in my user_socket.ex I pass the user_id as query param, this works, but it's not secure at all... I can pass the id that I want ??!!
Can someone help me?
#moduledoc false
use Phoenix.Socket
use Absinthe.Phoenix.Socket,
schema: MyAppGraphQL.Schema
## Channels
# channel "room:*", MyAppWeb.RoomChannel
# Socket params are passed from the client and can
# be used to verify and authenticate a user. After
# verification, you can put default assigns into
# the socket that will be set for all channels, ie
#
# {:ok, assign(socket, :user_id, verified_user_id)}
#
# To deny connection, return `:error`.
#
# See `Phoenix.Token` documentation for examples in
# performing token verification on connect.
def connect(%{"user_id" => user_id}, socket) do
case current_user(user_id) do
nil ->
:error
current_user ->
socket =
Absinthe.Phoenix.Socket.put_options(socket,
context: %{
current_user: current_user
}
)
{:ok, socket}
end
end
def connect(_, _), do: :error
defp current_user(user_id), do: MyApp.Accounts.lookup_user_with_company(user_id)
# Socket id's are topics that allow you to identify all sockets for a given user:
#
# def id(socket), do: "user_socket:#{socket.assigns.user_id}"
#
# Would allow you to broadcast a "disconnect" event and terminate
# all active sockets and channels for a given user:
#
# MyAppWeb.Endpoint.broadcast("user_socket:#{user.id}", "disconnect", %{})
#
# Returning `nil` makes this socket anonymous.
def id(_socket), do: nil
end```

Derby.js with Derby Auth errors

I just start with Derby and started out with integrating MongoDB and derby-auth. However, I am having troubles with that and can't figure it out. The following code returns the stacktrace below it. Finding out what causes the error is really hard. This is a new project generated with derby -c new project. All I know is that it's related to the auth.store(store) line.
UPDATE: I am also having this problem with the example/ in derby-auth, but only on my first request so I guess it would be relate to the database connection.
http = require 'http'
path = require 'path'
express = require 'express'
gzippo = require 'gzippo'
derby = require 'derby'
app = require '../app'
serverError = require './serverError'
auth = require('derby-auth')
MongoStore = require('connect-mongo')(express)
## SERVER CONFIGURATION ##
expressApp = express()
server = http.createServer expressApp
derby.use(require 'racer-db-mongo')
derby.use(derby.logPlugin)
store = derby.createStore
listen: server
db:
type: 'Mongo'
uri: 'mongodb://localhost/admin'
module.exports = server
auth.store(store)
ONE_YEAR = 1000 * 60 * 60 * 24 * 365
root = path.dirname path.dirname __dirname
publicPath = path.join root, 'public'
# Authentication strategies (providers actually)
strategies =
facebook:
strategy: require('passport-facebook').Strategy
conf:
clientID: 'boo'
clientSecret: 'boo'
# Authentication optionss
options =
domain: (if process.env.NODE_ENV is 'production' then "http://www.mydomain.com" else "http://localhost:3000" )
expressApp
.use(express.favicon())
# Gzip static files and serve from memory
.use(gzippo.staticGzip publicPath, maxAge: ONE_YEAR)
# Gzip dynamically rendered content
.use(express.compress())
# Uncomment to add form data parsing support
.use(express.bodyParser())
.use(express.methodOverride())
# Uncomment and supply secret to add Derby session handling
# Derby session middleware creates req.session and socket.io sessions
.use(express.cookieParser())
.use(store.sessionMiddleware
secret: 'mooo'
cookie: {maxAge: ONE_YEAR}
store: new MongoStore({ url: 'mongodb://localhost/admin' })
)
# Adds req.getModel method
.use(store.modelMiddleware())
# Authentication
.use(auth.middleware(strategies, options))
# Creates an express middleware from the app's routes
.use(app.router())
.use(expressApp.router)
.use(serverError root)
## SERVER ONLY ROUTES ##
expressApp.all '*', (req) ->
throw "404: #{req.url}"
Stack Trace:
TypeError: Cannot read property '_at' of undefined
at Model.mixin.proto._createRef ($derbypath/node_modules/derby/node_modules/racer/lib/refs/index.js:158:20)
at Model.mixin.proto.ref ($derbypath/node_modules/derby/node_modules/racer/lib/refs/index.js:124:19)
at $derbypath/lib/app/index.js:18:11
at Object.fail ($derbypath/node_modules/derby/node_modules/racer/lib/descriptor/descriptor.Model.js:268:21)
at Object.module.exports.events.middleware.middleware.subscribe.add._res.fail ($derbypath/node_modules/derby/node_modules/racer/lib/pubSub/pubSub.Store.js:80:40)
at module.exports.events.init.store.eachContext.context.guardReadPath.context.guardReadPath ($derbypath/node_modules/derby/node_modules/racer/lib/accessControl/accessControl.Store.js:25:26)
at next ($derbypath/node_modules/derby/node_modules/racer/lib/middleware.js:7:26)
at guard ($derbypath/node_modules/derby/node_modules/racer/lib/accessControl/accessControl.Store.js:156:36)
at next ($derbypath/node_modules/derby/node_modules/racer/lib/middleware.js:7:26)
at run ($derbypath/node_modules/derby/node_modules/racer/lib/middleware.js:10:12)
at $derbypath/node_modules/derby/node_modules/racer/lib/pubSub/pubSub.Store.js:88:11
at next ($derbypath/node_modules/derby/node_modules/racer/lib/middleware.js:7:26)
at Object.run [as subscribe] ($derbypath/node_modules/derby/node_modules/racer/lib/middleware.js:10:12)
at module.exports.server._addSub ($derbypath/node_modules/derby/node_modules/racer/lib/descriptor/descriptor.Model.js:237:26)
at Object.Promise.on ($derbypath/node_modules/derby/node_modules/racer/lib/util/Promise.js:29:7)
at Model.module.exports.server._addSub ($derbypath/node_modules/derby/node_modules/racer/lib/descriptor/descriptor.Model.js:221:29)
at subscribe ($derbypath/node_modules/derby/node_modules/racer/lib/descriptor/descriptor.Model.js:267:9)
at Model.module.exports.proto.subscribe ($derbypath/node_modules/derby/node_modules/racer/lib/descriptor/descriptor.Model.js:106:7)
at $derbypath/lib/app/index.js:17:16
at onRoute ($derbypath/node_modules/derby/lib/derby.server.js:69:7)
at app.router ($derbypath/node_modules/derby/node_modules/tracks/lib/index.js:96:16)
at callbacks ($derbypath/node_modules/derby/node_modules/tracks/node_modules/express/lib/router/index.js:160:37)
at param ($derbypath/node_modules/derby/node_modules/tracks/node_modules/express/lib/router/index.js:134:11)
at param ($derbypath/node_modules/derby/node_modules/tracks/node_modules/express/lib/router/index.js:131:11)
at pass ($derbypath/node_modules/derby/node_modules/tracks/node_modules/express/lib/router/index.js:141:5)
at Router._dispatch ($derbypath/node_modules/derby/node_modules/tracks/node_modules/express/lib/router/index.js:169:5)
at dispatch ($derbypath/node_modules/derby/node_modules/tracks/lib/index.js:43:21)
at Object.middleware [as handle] ($derbypath/node_modules/derby/node_modules/tracks/lib/index.js:58:7)
at next ($derbypath/node_modules/express/node_modules/connect/lib/proto.js:190:15)
at app.use.fn ($derbypath/node_modules/express/lib/application.js:121:9)
at next ($derbypath/node_modules/express/node_modules/connect/lib/proto.js:127:23)
at pass ($derbypath/node_modules/express/lib/router/index.js:107:24)
at Router._dispatch ($derbypath/node_modules/express/lib/router/index.js:170:5)
at Object.router ($derbypath/node_modules/express/lib/router/index.js:33:10)
at Context.next ($derbypath/node_modules/express/node_modules/connect/lib/proto.js:190:15)
at Context.actions.pass ($derbypath/node_modules/derby-auth/node_modules/passport/lib/passport/context/http/actions.js:77:8)
at SessionStrategy.authenticate ($derbypath/node_modules/derby-auth/node_modules/passport/lib/passport/strategies/session.js:52:10)
at attempt ($derbypath/node_modules/derby-auth/node_modules/passport/lib/passport/middleware/authenticate.js:243:16)
at Passport.authenticate ($derbypath/node_modules/derby-auth/node_modules/passport/lib/passport/middleware/authenticate.js:244:7)
at next ($derbypath/node_modules/express/node_modules/connect/lib/proto.js:190:15)
at Passport.initialize ($derbypath/node_modules/derby-auth/node_modules/passport/lib/passport/middleware/initialize.js:69:5)
at next ($derbypath/node_modules/express/node_modules/connect/lib/proto.js:190:15)
at Object.handle ($derbypath/node_modules/derby-auth/index.js:71:16)
at next ($derbypath/node_modules/express/node_modules/connect/lib/proto.js:190:15)
at Object.module.exports [as handle] ($derbypath/node_modules/derby-auth/node_modules/connect-flash/lib/flash.js:20:5)
at next ($derbypath/node_modules/express/node_modules/connect/lib/proto.js:190:15)
at Object.expressInit [as handle] ($derbypath/node_modules/express/lib/middleware.js:31:5)
at next ($derbypath/node_modules/express/node_modules/connect/lib/proto.js:190:15)
at Object.query [as handle] ($derbypath/node_modules/express/node_modules/connect/lib/middleware/query.js:44:5)
at next ($derbypath/node_modules/express/node_modules/connect/lib/proto.js:190:15)
at Function.app.handle ($derbypath/node_modules/express/node_modules/connect/lib/proto.js:198:3)
at Object.app.use.fn [as handle] ($derbypath/node_modules/express/lib/application.js:117:11)
at next ($derbypath/node_modules/express/node_modules/connect/lib/proto.js:190:15)
at Object.modelMiddleware [as handle] ($derbypath/node_modules/derby/node_modules/racer/lib/session/session.Store.js:119:5)
at next ($derbypath/node_modules/express/node_modules/connect/lib/proto.js:190:15)
at store.get.next ($derbypath/node_modules/derby/node_modules/racer/node_modules/connect/lib/middleware/session.js:313:9)
at $derbypath/node_modules/derby/node_modules/racer/node_modules/connect/lib/middleware/session.js:337:9
at sessStore.load.sessStore.get ($derbypath/node_modules/derby/node_modules/racer/lib/session/session.Store.js:262:11)
at process.startup.processNextTick.process._tickCallback (node.js:245:9)
Check this line at $derbypath/lib/app/index.js:18:11

Setting env when using rspec to test omniauth callbacks

I'm having a strange problem when trying to set a callback for Facebook Authentication via Omniauth. In my controller (simplified to just the code necessary to show the error) I have:
class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController
def facebook
raise env.inspect
# auth_hash = env["omniauth.auth"]
end
end
this works in production mode, showing me the hash. However in test mode env is set to nil.
I have the following set in my spec_helper.rb file
OmniAuth.config.test_mode = true
OmniAuth.config.add_mock(:facebook, {"credentials" => {
"token" => "foo-token"
}
})
and my spec looks like this:
require 'spec_helper'
describe Users::OmniauthCallbacksController do
describe "Facebook" do
before(:each) do
request.env["devise.mapping"] = Devise.mappings[:user]
request.env["omniauth.auth"] = OmniAuth.config.mock_auth[:facebook]
end
it "should be a redirect" do
get :facebook
response.should redirect_to(root_path)
end
end
end
Can anyone enlighten me on what I need to do to have env not be nil when running my tests?
I use the following in my spec_helper.rb :
RACK_ENV = ENV['ENVIRONMENT'] ||= 'test'
I don't use Rails or Devise though so YMMV. I've also seen various threads saying that someone had to do this before their requires to get it to work.

Redirected to http://localhost:3000/session/new

So I have a rails app 2.x app that works fine via the web, but when trying to perform a POST I keep getting "Redirected to http://localhost:3000/session/new Filter chain halted as [:require_user] rendered_or_redirected.". In my iPhone app, I can create a new session and sign-in via my iPhone app, but cannot POST to say the POSTS_Controller.
I have this in my code
Posts_Controller
before_filter :require_user, :only => [:create, :update, :destroy]
Application_Controller
# Filters added to this controller apply to all controllers in the application.
# Likewise, all the methods added will be available for all controllers.
class ApplicationController < ActionController::Base
include AuthenticatedSystem
include Geokit::Geocoders
helper :all # include all helpers, all the time
#session :session_key => '_cwa_session_id'
#filter_parameter_logging :password
# See ActionController::RequestForgeryProtection for details
# Uncomment the :secret if you're not using the cookie session store
protect_from_forgery # :secret => 'eejj7eded74769099999944a729b4f'
#filter_parameter_logging(:password)
before_filter :login_from_cookie
before_filter :find_user_interests
before_filter :find_user_posts
protected
def find_user_interests
#user_interests = cur_user ? cur_user.interesting_posts : []
logger.debug "User interests hash: #{current_user.inspect}"
end
def find_user_posts
#user_posts = cur_user ? cur_user.posts : []
end
def cur_user
User.find(session[:user_id]) if session[:user_id]
end
def require_user
unless cur_user
flash[:error] = "You must be logged in to do that."
redirect_to '/session/new'
return false
end
end
geocode_ip_address
def geokit
#location = session[:geo_location]
end
end
I have been working on this for 2 months and cannot figure out the issue. In my iPhone app I am using ObjectiveResource. I am sending over json and have "Mime::Type.register_alias "application/json", :json" set up on the rails side.
I am not a rails developer, but the before filter for require_user is unable to pass the cur_user test in that is cannot find :user_id in the session hash. Are you sure that you have a session that persists when using the iPhone? Are you using devise for authentication? Just for kicks, does it work if you manually pass the user_id as params?

MMS2R and Multiple Images Rails

Here's my code:
require 'mms2r'
class IncomingMailHandler < ActionMailer::Base
##
# Receives email(s) from MMS-Email or regular email and
# uploads that content the user's photos.
# TODO: Use beanstalkd for background queueing and processing.
def receive(email)
begin
mms = MMS2R::Media.new(email)
##
# Ok to find user by email as long as activate upon registration.
# Remember to make UI option that users can opt out of registration
# and either not send emails or send them to a username+32523#example.com
# type address.
##
# Remember to get SpamAssasin
if (#user = User.find_by_email(email.from) && email.has_attachments?)
mms.media.each do |key, value|
if key.include?('image')
value.each do |file|
#user.photos.push Photo.create!(:uploaded_data => File.open(file), :title => email.subject.empty? ? "Untitled" : email.subject)
end
end
end
end
ensure
mms.purge
end
end
end
and here's my error:
/usr/local/lib/ruby/gems/1.8/gems/rails-2.3.4/lib/commands/runner.rb:48: undefined method `photos' for true:TrueClass (NoMethodError)
from /usr/home/xxx/app/models/incoming_mail_handler.rb:23:in `each'
from /usr/home/xxx/app/models/incoming_mail_handler.rb:23:in `receive'
from /usr/home/xxx/app/models/incoming_mail_handler.rb:21:in `each'
from /usr/home/xxx/app/models/incoming_mail_handler.rb:21:in `receive'
from /usr/local/lib/ruby/gems/1.8/gems/actionmailer-2.3.4/lib/action_mailer/base.rb:419:in `receive'
from (eval):1
from /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `eval'
from /usr/local/lib/ruby/gems/1.8/gems/rails-2.3.4/lib/commands/runner.rb:48
from /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require'
from /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require'
from /home/xxx/script/runner:3
I sent an email to the server with two image attachments. Upon receiving the email the server runs
"| ruby /xxx/script/runner 'IncomingMailHandler.receive STDIN.read'"
What is going on? What am I doing wrong?
(MMS2R docs)
Please replace
if (#user = User.find_by_email(email.from) && email.has_attachments?)
with
if ((#user = User.find_by_email(email.from)) && email.has_attachments?)