Discussion:
Sinatra Authentication
Surya Poojary
2018-10-20 09:13:57 UTC
Permalink
Hello rubyists!

I'm trying to learn Sinatra and want to implement an authentication system
like

If username == "me" and password == "she" // go to the next page

Else

// Take to some page that says "you are not authorised"

How do I do this ?

Gracias,

Rubyists.
Raj Sahae
2018-10-20 16:30:23 UTC
Permalink
http://lmgtfy.com/?q=Authentication+sinatra

- Raj
Post by Surya Poojary
Hello rubyists!
I'm trying to learn Sinatra and want to implement an authentication system
like
If username == "me" and password == "she" // go to the next page
Else
// Take to some page that says "you are not authorised"
How do I do this ?
Gracias,
Rubyists.
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk>
Arup Rakshit
2018-10-20 16:56:12 UTC
Permalink
Hi Raj,


This is not welcoming. Please don’t do this. It happened with me long before, and I know how does it feel.
http://lmgtfy.com/?q=Authentication+sinatra <http://lmgtfy.com/?q=Authentication+sinatra>
- Raj
Hello rubyists!
I'm trying to learn Sinatra and want to implement an authentication system like
If username == "me" and password == "she" // go to the next page
Else
// Take to some page that says "you are not authorised"
How do I do this ?
Gracias,
Rubyists.
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk <http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk>>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk>
Dmitriy Non
2018-10-23 09:54:35 UTC
Permalink
As Raj suggested, you should've just googled it:)

Though I would recommend to decompose your problem.
Obviously, you need to learn how to recieve parameters in your sinatra app.
Then you need to learn how to keep user data. Session will do, right?
And last, you need to learn how to redirect user.

So, google this topics:

1. sinatra parameters
2. sinatra session
3. sinatra redirect

and go from there
Post by Surya Poojary
Hello rubyists!
I'm trying to learn Sinatra and want to implement an authentication system like
If username == "me" and password == "she" // go to the next page
Else
// Take to some page that says "you are not authorised"
How do I do this ?
Gracias,
Rubyists.
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk>
Unsubscribe: <mailto:ruby-talk-***@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk>
Ale Miralles
2018-10-23 13:17:58 UTC
Permalink
I recommend you to check the Sinatra's home page. They put in there almost
all you need to get a Sinatra app off the ground.
Anyway, here is a minimum example you can use to fiddle around a little bit.

This is the contents of the main file. (i.e., app.rb):

require 'sinatra'
enable :sessions

get "/" do
if session[:usr]
erb :index
else
erb :login
end
end

post "/create_session" do
if params[:usr] == "amiralles" && params[:pwd] == "123"
session[:usr] = params[:usr]
redirect "/"
else
erb :login
end
end

Now, create a directory called "views" and place this files on it:

Homepage: index.erb
<h1>
Wellcome <%= session[:usr] %>!
</h1>

Login page: login.erb
<form action="/create_session" method="POST">
<input name="usr" type="text"></input> <br/>
<input name="pwd" type="password"></input> <br/>
<input type="submit" value="Login"></input>
</form>


Finally, run `ruby app.rb` and you will be ready to go.

Hope this helps!

~ Ale Miralles.
https://medium.com/amiralles
http://amiralles.com.ar
Post by Surya Poojary
Hello rubyists!
I'm trying to learn Sinatra and want to implement an authentication system
like
If username == "me" and password == "she" // go to the next page
Else
// Take to some page that says "you are not authorised"
How do I do this ?
Gracias,
Rubyists.
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk>
Loading...