-
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.
[ADD] Example application with authentication
- Loading branch information
1 parent
5dc35d4
commit f1edb0c
Showing
8 changed files
with
100 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# config.ru | ||
require './example_app.rb' | ||
|
||
# Map applications | ||
run Rack::URLMap.new \ | ||
"/" => ExampleApp.new |
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,7 @@ | ||
# -*- encoding : utf-8 -*- | ||
|
||
Mailer.delivery_method[:type] = :sendmail | ||
|
||
Mailer.credentials[:from] = 'ondrej@bartas.cz' | ||
Mailer.credentials[:subject] = "Password reset" | ||
Mailer.credentials[:body] = "Someone hopefully you, requested password rest" |
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 @@ | ||
test: | ||
host: "127.0.0.1" | ||
port: 6379 | ||
db: 3 | ||
session_db: 5 | ||
development: | ||
host: "127.0.0.1" | ||
port: 6379 | ||
db: 0 | ||
session_db: 1 | ||
stage: | ||
host: "127.0.0.1" | ||
port: 6379 | ||
db: 0 | ||
session_db: 1 | ||
production: | ||
host: "127.0.0.1" | ||
port: 6379 | ||
db: 0 | ||
session_db: 1 |
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,22 @@ | ||
# -*- encoding : utf-8 -*- | ||
require 'sinatra' | ||
require 'sinatra/base' | ||
require 'erb' | ||
require 'yaml' | ||
require '../lib/sinatra-redis-auth' | ||
require './user' | ||
|
||
class ExampleApp < Sinatra::Base | ||
register Sinatra::SinatraRedisAuth | ||
set :views, File.dirname(__FILE__) + '/views' | ||
|
||
get "/" do | ||
erb :index | ||
end | ||
|
||
get "/protected_page" do | ||
login_required | ||
erb :protected_page | ||
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 @@ | ||
# -*- encoding : utf-8 -*- | ||
class User | ||
REDIS_MODEL_CONF = { | ||
:fields => { | ||
:email => :to_s, | ||
:password => :to_s, | ||
:salt => :to_s, | ||
:reset_token => :to_s, | ||
}, | ||
:required => [:email,:password], | ||
:redis_key => [:email], | ||
:redis_aliases => { | ||
:reset_token => [:reset_token] | ||
} | ||
} | ||
include RedisModel | ||
initialize_redis_model_methods REDIS_MODEL_CONF | ||
include UserAuthModel | ||
|
||
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,3 @@ | ||
<h1>Index page of Example Auth App</h1> | ||
|
||
<a href="/protected_page">Protected page</a> |
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,21 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<title>Example sinatra auth app</title> | ||
<body> | ||
<% if @current_user %> | ||
<%= @current_user.email %> | <a href="/sign_out"> Sign Out </a> | ||
<% else %> | ||
<a href="/sign_in"> Sign In </a> | <a href="/sign_up"> Sign Up </a> | ||
<% end %> | ||
<% if flash[:notice] %> | ||
<i><%= flash[:notice] %></i> | ||
<% end %> | ||
<% if flash[:error] %> | ||
<b><%= flash[:error] %></b> | ||
<% end %> | ||
<%= yield %> | ||
</body> | ||
</html> |
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 @@ | ||
<h1>Protected page of Example Auth App</h1> |