Created
March 21, 2012 14:41
-
-
Save leucos/2147637 to your computer and use it in GitHub Desktop.
Ramaze user auth example (from Yorick Peterse)
This file contains hidden or 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
| ## foo.rb [ruby] | |
| require 'ramaze' | |
| class User | |
| def self.authenticate(credentials) | |
| credentials if credentials['name'] == 'manveru' && credentials['pass'] == 'foo' | |
| end | |
| end | |
| class Main < Ramaze::Controller | |
| map '/' | |
| helper :user | |
| def index | |
| redirect Users.r(:login) unless logged_in? | |
| 'Hi #{user["name"]} #{Users.a :logout}' | |
| end | |
| end | |
| class Users < Ramaze::Controller | |
| map '/user' | |
| helper :user | |
| def login | |
| if request.post? | |
| user_login(request.subset(:name, :pass)) | |
| redirect Main.r(:index) | |
| else | |
| <<-FORM | |
| <form method="post"> | |
| <input type="text" name="name"> | |
| <input type="password" name="pass"> | |
| <input type="submit"> | |
| </form> | |
| FORM | |
| end | |
| end | |
| def logout | |
| user_logout | |
| redirect r(:login) | |
| end | |
| end | |
| Ramaze.start |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment