Skip to content

Commit

Permalink
[ADD] Example application with authentication
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejbartas committed Mar 6, 2012
1 parent 5dc35d4 commit f1edb0c
Show file tree
Hide file tree
Showing 8 changed files with 100 additions and 0 deletions.
6 changes: 6 additions & 0 deletions example/config.ru
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
7 changes: 7 additions & 0 deletions example/config/mail_config.rb
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"
20 changes: 20 additions & 0 deletions example/config/redis_config.yml
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
22 changes: 22 additions & 0 deletions example/example_app.rb
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
20 changes: 20 additions & 0 deletions example/user.rb
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
3 changes: 3 additions & 0 deletions example/views/index.erb
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>
21 changes: 21 additions & 0 deletions example/views/layout.erb
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>
1 change: 1 addition & 0 deletions example/views/protected_page.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<h1>Protected page of Example Auth App</h1>

0 comments on commit f1edb0c

Please sign in to comment.