No commit activity in last 3 years
No release in over 3 years
Sinatra authentification with saving user data to redis
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.2.5
~> 1.0.0
~> 1.8.3
~> 3.12
>= 0
~> 0.8.2

Runtime

>= 0
~> 1.3.0
>= 0
~> 1.2.6
~> 1.3.2
 Project Readme

Sinatra Redis Auth

Simple authetication for sinatra based applications. It saves all datas -> user data + session data to redis.

It is absolutely insane to use slow databases (MySQL, Postgre ...) for those datas. redis provides very fast possibility to acces thousands user datas per second.

Installation of requirments

Redis - detailed instructions:

wget http://redis.googlecode.com/files/redis-2.4.8.tar.gz
tar xzf redis-2.4.8.tar.gz
cd redis-2.4.8
make

or you can use brew

brew install redis

Example of usage

In example/ you can find functional application with all needed parts.

Including to existing application

#Gemfile
gem "sinatra-redis-auth"
#your_sinatra_app.rb
register Sinatra::SinatraRedisAuth

create two files in config/ directory: mail_config.rb, redis_config.yml

#config/mail_config.rb
Mailer.delivery_method[:type] = :sendmail
Mailer.credentials[:from] = 'askme@weps.cz'
Mailer.credentials[:subject] = "Password reset"
Mailer.credentials[:body] = "Someone hopefully you, requested password rest"

settings for emailing when user need's to reset password

#config/redis_config.yml
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

settings for connecting application to redis

You need to create user model too (do not forget to require it in your app)

# user.rb
# -*- 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

Options you can set

You can set sinatra options for path to your edited sign in, sign out, password_change, password_reset

Or you can set where user will be redirected after sign in, up and out.

#your_sinatra_app.rb
set :sinatra_redis_auth_views, "views/"
set :default_url_after_sign_in, "/"
set :default_url_after_sign_up, "/"
set :default_url_after_sign_out, "/"

Contributing to redis-auth

  • Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
  • Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
  • Fork the project.
  • Start a feature/bugfix branch.
  • Commit and push until you are happy with your contribution.
  • Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
  • Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.

Copyright

Copyright (c) 2012 Ondrej Bartas.