-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refac: Use sinatra instead of Roda. Add more specs
- Loading branch information
Jurgens du Toit
committed
Nov 20, 2016
1 parent
e19a86b
commit 95ebb7f
Showing
56 changed files
with
973 additions
and
454 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,3 @@ | ||
require 'proxes/version' | ||
require 'proxes/base' | ||
require 'proxes/app' | ||
require 'proxes/security' | ||
require 'proxes/es_request' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,49 @@ | ||
require 'proxes/base' | ||
require 'proxes/routes' | ||
require 'proxes/controllers/application' | ||
|
||
module ProxES | ||
# Manage your Elasticsearch cluster, user and user sessions | ||
class App < ProxES::Base | ||
plugin :multi_route | ||
class App < Application | ||
get '/' do | ||
authenticate! | ||
haml :index | ||
end | ||
|
||
def logger | ||
require 'logger' | ||
@logger ||= Logger.new($stdout) | ||
['/unauthenticated', '/_proxes/unauthenticated'].each do |path| | ||
get path do | ||
redirect '/auth/identity' | ||
end | ||
end | ||
|
||
def root_url | ||
@root_url = opts[:root_url] || '/_proxes' | ||
post '/auth/identity/new' do | ||
identity = Identity.new(params['identity']) | ||
if identity.valid? && identity.save | ||
flash[:info] = 'Successfully Registered. Please log in' | ||
redirect '/auth/identity' | ||
else | ||
flash.now[:warning] = 'Could not complete the registration. Please try again.' | ||
view 'security/register', locals: { identity: identity } | ||
end | ||
end | ||
|
||
route do |r| | ||
r.multi_route | ||
post '/auth/identity/callback' do | ||
user = User.find_or_create(email: env['omniauth.auth']['info']['email']) | ||
user.add_user_role role: 'user' unless user.has_role? 'user' | ||
user.add_user_role(role: 'super_admin') if (user.id == 1 && user.has_role?('super_admin') == false) | ||
|
||
r.get do | ||
authenticate! | ||
identity = Identity.find(username: user.email) | ||
user.add_identity identity unless identity.user == user | ||
|
||
view 'index' | ||
end | ||
set_user user | ||
flash[:success] = 'Logged In' | ||
redirect '/_proxes' | ||
end | ||
|
||
delete '/auth/identity' do | ||
logout | ||
|
||
flash[:info] = 'Logged Out' | ||
|
||
redirect '/_proxes' | ||
end | ||
end | ||
end |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
require 'proxes/controllers/users' | ||
require 'proxes/controllers/user_roles' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
require 'sinatra/base' | ||
require 'sinatra/flash' | ||
require 'proxes/helpers/views' | ||
require 'proxes/helpers/pundit' | ||
require 'proxes/helpers/authentication' | ||
|
||
module ProxES | ||
class Application < Sinatra::Base | ||
set :root, ::File.expand_path(::File.dirname(__FILE__) + '/../../../') | ||
register Sinatra::Flash | ||
helpers ProxES::Helpers::Pundit, ProxES::Helpers::Views, ProxES::Helpers::Authentication | ||
|
||
configure :production do | ||
disable :show_exceptions | ||
end | ||
|
||
configure :development do | ||
set :show_exceptions, :after_handler | ||
end | ||
|
||
configure :production, :development do | ||
enable :logging | ||
end | ||
|
||
not_found do | ||
haml :'404', locals: { title: '4 oh 4' } | ||
end | ||
|
||
error do | ||
error = env['sinatra.error'] | ||
haml :error, locals: { title: 'Something went wrong', message: error } | ||
end | ||
|
||
error ::Pundit::NotAuthorizedError do | ||
flash[:warning] = 'Please log in first.' | ||
redirect '/auth/identity' | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
require 'proxes/controllers/application' | ||
|
||
module ProxES | ||
class AuthIdentity < Application | ||
get '/auth/identity' do | ||
haml :'identity/login', locals: { title: 'Log In' } | ||
end | ||
|
||
# Failed Login | ||
post '/_proxes/auth/identity/callback' do | ||
flash[:warning] = 'Invalid credentials. Please try again.' | ||
redirect '/auth/identity' | ||
end | ||
|
||
get '/auth/identity/register' do | ||
identity = Identity.new | ||
haml :'identity/register', locals: { title: 'Register', identity: identity } | ||
end | ||
end | ||
end |
Oops, something went wrong.