Class: Thoth::AdminController
- Inherits:
-
Controller
- Object
- Ramaze::Controller
- Controller
- Thoth::AdminController
- Defined in:
- lib/thoth/controller/admin.rb
Instance Method Summary collapse
- #index ⇒ Object
-
#login ⇒ Object
Authenticates an admin login by checking the username and password request parameters against the
ADMIN_USERandADMIN_PASSvalues in the Thoth config file. -
#logout ⇒ Object
Deletes the thoth_auth cookie and redirects to the home page.
Methods inherited from Controller
Instance Method Details
#index ⇒ Object
34 35 36 37 38 39 40 41 42 |
# File 'lib/thoth/controller/admin.rb', line 34 def index if auth_key_valid? @title = 'Welcome to Thoth' @public_root = PUBLIC_DIR @view_root = VIEW_DIR else @title = 'Login' end end |
#login ⇒ Object
Authenticates an admin login by checking the username and password request parameters against the ADMIN_USER and ADMIN_PASS values in the Thoth config file.
On a successful login, an auth cookie named thoth_auth will be set and the user will be redirected to the referring URL. On an unsuccessful login attempt, a flash message named login_error will be set and the user will be redirected to the referring URL without an auth cookie.
53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/thoth/controller/admin.rb', line 53 def login username, password = request[:username, :password] if username == Config.admin['user'] && password == Config.admin['pass'] # Set an auth cookie that expires in two weeks. response.('thoth_auth', :expires => Time.now + 1209600, :path => '/', :value => auth_key) redirect_referrer end flash[:error] = 'Invalid username or password.' redirect_referrer end |
#logout ⇒ Object
Deletes the thoth_auth cookie and redirects to the home page.
69 70 71 72 |
# File 'lib/thoth/controller/admin.rb', line 69 def logout response.('thoth_auth', :path => '/') redirect(MainController.r()) end |