-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Andrea Rossi
committed
Sep 20, 2016
1 parent
9da2ff5
commit 1fc7f75
Showing
10 changed files
with
108 additions
and
146 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -58,8 +58,5 @@ class Root < Grape::API | |
mount API::V3::Countries | ||
end | ||
end | ||
|
||
end | ||
end | ||
|
||
Grape::CORS.apply! |
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 |
---|---|---|
|
@@ -5,6 +5,7 @@ | |
|
||
# Sinatra | ||
require 'rack/csrf' | ||
require 'rack/cors' | ||
require 'sinatra' | ||
|
||
# Grape | ||
|
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,53 +1,50 @@ | ||
module Web | ||
module AdminController | ||
# Routes implementation | ||
####################### | ||
SHOW_ADMIN = -> { | ||
protected! | ||
erb :admin, layout: :layout | ||
} | ||
|
||
UPDATE_API_USER = -> { | ||
protected! | ||
user = ApiUser.find(params[:id]) | ||
|
||
if params.has_key?("destroy") | ||
user.destroy | ||
elsif params.has_key?("save") | ||
UPDATE_USER[user, params["api_user"]] | ||
user.save | ||
end | ||
|
||
redirect back | ||
} | ||
|
||
SIGN_OUT = -> { | ||
protected! | ||
session.destroy | ||
|
||
redirect "/" | ||
} | ||
|
||
# Private implementation | ||
######################## | ||
UPDATE_USER = -> (user, params) { | ||
if params["active"].present? | ||
user.activate! | ||
else | ||
user.deactivate! | ||
end | ||
|
||
params["permissions"].each do |(api_object, attrs)| | ||
user.permissions[api_object] = attrs.keys | ||
end | ||
} | ||
|
||
# Register to Sinatra app | ||
######################### | ||
def self.registered(app) | ||
app.get "/admin", &SHOW_ADMIN | ||
app.get "/admin/sign_out", &SIGN_OUT | ||
app.post "/admin/api_users/:id", &UPDATE_API_USER | ||
module Web; end | ||
require "web/helpers" | ||
|
||
class Web::AdminController < Sinatra::Base | ||
helpers Web::Helpers | ||
set :views, File.join(settings.root, '../views') | ||
|
||
get("/admin") do | ||
protected! | ||
erb :admin, layout: :layout | ||
end | ||
|
||
post("/admin/api_users/:id") do | ||
protected! | ||
user = ApiUser.find(params[:id]) | ||
|
||
if params.has_key?("destroy") | ||
user.destroy | ||
elsif params.has_key?("save") | ||
update_user(user, params["api_user"]) | ||
user.save | ||
end | ||
|
||
redirect back | ||
end | ||
|
||
get("/admin/sign_out") do | ||
protected! | ||
session.destroy | ||
|
||
redirect "/" | ||
end | ||
|
||
private | ||
|
||
def update_user user, params | ||
if params["active"].present? | ||
user.activate! | ||
|
||
documentation_url = url("/documentation") | ||
Mailer.send_new_activation_notification(user, documentation_url) | ||
else | ||
user.deactivate! | ||
end | ||
|
||
params["permissions"].each do |(api_object, attrs)| | ||
user.permissions[api_object] = attrs.keys | ||
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 |
---|---|---|
@@ -1,16 +1,10 @@ | ||
module Web | ||
module DocumentationController | ||
# Routes | ||
######## | ||
SHOW_DOCUMENTATION = -> { | ||
erb :documentation, layout: :layout | ||
} | ||
module Web; end | ||
|
||
# Register to Sinatra app | ||
######################### | ||
def self.registered(app) | ||
app.get "/documentation", &SHOW_DOCUMENTATION | ||
end | ||
class Web::DocumentationController < Sinatra::Base | ||
set :views, File.join(settings.root, '../views') | ||
|
||
get("/documentation") do | ||
erb :documentation, layout: :layout | ||
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 |
---|---|---|
@@ -1,28 +1,36 @@ | ||
module Web | ||
module RequestsController | ||
# Routes | ||
######## | ||
SHOW_REQUEST = -> { | ||
erb :request, layout: :layout | ||
} | ||
module Web; end | ||
|
||
POST_REQUEST = -> { | ||
if @new_user = create_api_user(params) | ||
Thread.new { | ||
activation_url = url("/admin") | ||
Mailer.send_new_request_notification(@new_user, activation_url) | ||
} | ||
erb :request_success, layout: :layout | ||
else | ||
erb :request_error, layout: :layout | ||
end | ||
} | ||
class Web::RequestsController < Sinatra::Base | ||
set :views, File.join(settings.root, '../views') | ||
|
||
# Register to Sinatra app | ||
######################### | ||
def self.registered(app) | ||
app.get "/request", &SHOW_REQUEST | ||
app.post "/request", &POST_REQUEST | ||
get("/request") do | ||
erb :request, layout: :layout | ||
end | ||
|
||
post("/request") do | ||
if @new_user = create_api_user(params) | ||
Thread.new{ send_notification(@new_user) } | ||
erb :request_success, layout: :layout | ||
else | ||
erb :request_error, layout: :layout | ||
end | ||
end | ||
|
||
private | ||
|
||
def send_notification(new_user) | ||
activation_url = url("/admin") | ||
Mailer.send_new_request_notification(new_user, activation_url) | ||
end | ||
|
||
def create_api_user params | ||
ApiUser.create( | ||
email: params["email"], | ||
full_name: params["fullname"], | ||
company: params["company"], | ||
reason: params["reason"], | ||
active: false, | ||
token: ApiUser.new_token | ||
) | ||
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