Class: Ditty::Auth
- Inherits:
-
Application
- Object
- Sinatra::Base
- Application
- Ditty::Auth
- Defined in:
- lib/ditty/controllers/auth.rb
Instance Method Summary collapse
- #failed_login ⇒ Object
- #find_template(views, name, engine, &block) ⇒ Object
- #omniauth_callback(provider) ⇒ Object
- #redirect_path ⇒ Object
- #register_user ⇒ Object
- #successful_login(user) ⇒ Object
Instance Method Details
#failed_login ⇒ Object
28 29 30 31 32 |
# File 'lib/ditty/controllers/auth.rb', line 28 def failed_login broadcast(:user_failed_login, target: self, details: "IP: #{request.ip}") flash[:warning] = 'Invalid credentials. Please try again.' redirect "#{settings.map_path}/auth/login" end |
#find_template(views, name, engine, &block) ⇒ Object
9 10 11 12 |
# File 'lib/ditty/controllers/auth.rb', line 9 def find_template(views, name, engine, &block) super(views, name, engine, &block) # Root super(::Ditty::App.view_folder, name, engine, &block) # Basic Plugin end |
#omniauth_callback(provider) ⇒ Object
20 21 22 23 24 25 26 |
# File 'lib/ditty/controllers/auth.rb', line 20 def omniauth_callback(provider) return failed_login unless env['omniauth.auth'] user = User.first(email: env['omniauth.auth']['info']['email']) user = register_user if user.nil? && ['ldap', 'google_oauth2'].include?(provider) return failed_login if user.nil? successful_login(user) end |
#redirect_path ⇒ Object
14 15 16 17 18 |
# File 'lib/ditty/controllers/auth.rb', line 14 def redirect_path return "#{settings.map_path}/" unless env['omniauth.origin'] return "#{settings.map_path}/" if env['omniauth.origin'] =~ %r{/#{settings.map_path}/auth/?} env['omniauth.origin'] end |
#register_user ⇒ Object
42 43 44 45 46 47 |
# File 'lib/ditty/controllers/auth.rb', line 42 def register_user user = User.create(email: env['omniauth.auth']['info']['email']) broadcast(:user_register, target: self, values: { user: user }, details: "IP: #{request.ip}") flash[:info] = 'Successfully Registered.' user end |
#successful_login(user) ⇒ Object
34 35 36 37 38 39 40 |
# File 'lib/ditty/controllers/auth.rb', line 34 def successful_login(user) halt 200 if request.xhr? self.current_user = user broadcast(:user_login, target: self, details: "IP: #{request.ip}") flash[:success] = 'Logged In' redirect redirect_path end |