picombo-auth 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,36 @@
|
|
1
|
+
# Picombo Auth Class
|
2
|
+
#
|
3
|
+
# Author:: Jeremy Bush
|
4
|
+
# Copyright:: Copyright (c) 2009 Jeremy Bush
|
5
|
+
# License:: See LICENSE
|
6
|
+
|
7
|
+
require 'digest/sha1'
|
8
|
+
|
9
|
+
module Picombo
|
10
|
+
class Auth
|
11
|
+
include Singleton
|
12
|
+
|
13
|
+
def login(user, password)
|
14
|
+
user = Picombo::Models::User.first(:username => user, :password => Digest::SHA1.hexdigest(password))
|
15
|
+
|
16
|
+
if user
|
17
|
+
# set the session as logged in
|
18
|
+
Picombo::Session.instance.set('loggedin', true)
|
19
|
+
Picombo::Session.instance.set('user', user)
|
20
|
+
|
21
|
+
return true
|
22
|
+
end
|
23
|
+
|
24
|
+
false
|
25
|
+
end
|
26
|
+
|
27
|
+
def logout
|
28
|
+
Picombo::Session.instance.unset('loggedin')
|
29
|
+
Picombo::Session.instance.unset('user')
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.logged_in?
|
33
|
+
! Picombo::Session.instance.get('loggedin').nil?
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module Picombo
|
2
|
+
module Controllers
|
3
|
+
class User < Picombo::Controllers::Template
|
4
|
+
def login
|
5
|
+
template = Picombo::View.new('template')
|
6
|
+
body = Picombo::View.new('user/login')
|
7
|
+
body.set('error', '')
|
8
|
+
|
9
|
+
if ! Picombo::Input.instance.post.empty?
|
10
|
+
if Picombo::Auth.instance.login(Picombo::Input.instance.post('username'), Picombo::Input.instance.post('password'))
|
11
|
+
Picombo::Core.redirect('admin/remove_banned')
|
12
|
+
else
|
13
|
+
body.set('error', 'Invalid password or unknown username')
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
template.set('body', body.render(true))
|
18
|
+
template.render
|
19
|
+
end
|
20
|
+
|
21
|
+
def logout
|
22
|
+
Picombo::Auth.instance.logout
|
23
|
+
|
24
|
+
Picombo::Core.redirect('admin/remove_banned')
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
<h2>User Login</h2>
|
2
|
+
<% if ! @error.empty? %><p><%= @error %></p><% end %>
|
3
|
+
<form action="<%= Picombo::Url.base%>user/login" method="post">
|
4
|
+
<ul>
|
5
|
+
<li><label for="username">Username:</label> <input name="username" /></li>
|
6
|
+
<li><label for="password">Password:</label> <input type="password" name="password" /></li>
|
7
|
+
<li><input type="submit" value="Login"></li>
|
8
|
+
</ul>
|
9
|
+
</form>
|
10
|
+
<%= Picombo::Auth.logged_in?.inspect %>
|
data/lib/picombo-auth.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__)+'/picombo-auth')
|
metadata
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: picombo-auth
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jeremy Bush
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2010-04-23 00:00:00 -05:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description: Provides authentication classes
|
17
|
+
email: contractfrombelow@gmail.com
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files: []
|
23
|
+
|
24
|
+
files:
|
25
|
+
- lib/picombo-auth.rb
|
26
|
+
- lib/picombo-auth/classes/auth.rb
|
27
|
+
- lib/picombo-auth/controllers/user.rb
|
28
|
+
- lib/picombo-auth/models/user.rb
|
29
|
+
- lib/picombo-auth/views/user
|
30
|
+
- lib/picombo-auth/views/user/login.rhtml
|
31
|
+
has_rdoc: false
|
32
|
+
homepage: http://www.picombo.net/
|
33
|
+
post_install_message:
|
34
|
+
rdoc_options: []
|
35
|
+
|
36
|
+
require_paths:
|
37
|
+
- lib
|
38
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
39
|
+
requirements:
|
40
|
+
- - ">="
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: "0"
|
43
|
+
version:
|
44
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - ">="
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: "0"
|
49
|
+
version:
|
50
|
+
requirements: []
|
51
|
+
|
52
|
+
rubyforge_project:
|
53
|
+
rubygems_version: 1.3.1
|
54
|
+
signing_key:
|
55
|
+
specification_version: 2
|
56
|
+
summary: Auth Extensions for Picombo - A lightweight MVC web framework
|
57
|
+
test_files: []
|
58
|
+
|