Module: Sinatra::DataMapperAuth

Defined in:
lib/sinatra/datamapperauth.rb

Defined Under Namespace

Modules: Helpers Classes: User

Class Method Summary collapse

Class Method Details

.registered(app) ⇒ Object



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/sinatra/datamapperauth.rb', line 57

def self.registered(app)
  app.helpers DataMapperAuth::Helpers

  app.get '/login' do
    '<form action="/login" method="post">
      <p>Login</p><input type="text" size="30" name="login"/>
      <p>Password</p><input type="password" size="30" name="password"/>
      <br/>
      <input type="submit" value="Submit" name="submit"/>
    </form>'
  end

  app.post '/login' do
    if session[:user] = User.authenticate(params[:login], params[:password])
      flash[:notice] = "Login succesful"
      redirect '/'
    else
      flash[:notice] = "Login failed - Try again"
      redirect '/login'
    end
  end

  app.get '/logout' do
    logout!
    flash[:notice] = "Logged out"
    redirect '/'
  end
  
end