teamster 0.3.4 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a6206844754e6167984d2917877c66c578b11754
4
- data.tar.gz: ca07df0e85a826f4e0d70fe699599acac6529d24
3
+ metadata.gz: 7d93ad44983fe5b937e8c559ec945eb74a45dda9
4
+ data.tar.gz: 838c9848d967b9ea66e17b372bb54cc51979a726
5
5
  SHA512:
6
- metadata.gz: 33d2f2642c2626cf1ac9b3f7156eda22925ac13fa6315f6406bbfc3a1eaf50b9dcd87fcd76347930ad6858a6545f0c0296dd86ee140662bb0cc3d400ceb58afd
7
- data.tar.gz: fb59b51f9aa89d9678f209945d18d4d1e40f51c9947f0cd29e79d11a1252525dd717b86729b05245dbb01b5917a5c441b49936063520b21c52b27a5dbd9436fb
6
+ metadata.gz: 825caf684e6dbf9711cb325e7543b6c3ff3627cf5605600702c464b27b5b1b88c7968977cfe2da59cd010e3818f164bcf5fe3809680177f9fb2f6ee9ee14b8dc
7
+ data.tar.gz: 66497ff2540821ce4deb8fa7bceadf39d6482fcde393274895c60a0e4933c69991b6802d73b24ef45d995dfd16ccc5995e8c87f42c0975daa8e2a3690c94d180
data/.gitignore CHANGED
@@ -1,2 +1,2 @@
1
1
  pkg/
2
-
2
+ todo/
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.4
1
+ 0.4.0
data/bin/teamster CHANGED
@@ -1,7 +1,10 @@
1
1
  #!/usr/bin/env ruby
2
- ['fileutils', 'getoptlong', 'yaml', 'rubygems/package', 'zlib'].each do |gemfile|
3
- require gemfile
4
- end
2
+
3
+ require 'fileutils'
4
+ require 'getoptlong'
5
+ require 'yaml'
6
+ require 'bcrypt'
7
+ require 'base64'
5
8
 
6
9
  DEFAULT_UNIX_SOCKET_FILE = '/tmp/teamster.app.sock'
7
10
  DEFAULT_APP_STATE_FILE = '/srv/my-site/teamster.app.state'
@@ -67,6 +70,8 @@ class TeamsterApp
67
70
  puts "Creating required content..."
68
71
  FileUtils.mkdir_p "conf"
69
72
  create_config
73
+ FileUtils.mkdir_p "data"
74
+ create_user
70
75
  FileUtils.cp_r "#{content}/views", current_working_folder
71
76
  FileUtils.cp_r "#{content}/public", current_working_folder
72
77
  create_file "config.ru", "config_ru"
@@ -125,6 +130,19 @@ class TeamsterApp
125
130
  File.open(CONFIG_FILE, 'w') {|fh| fh.write @config.to_yaml}
126
131
  end
127
132
 
133
+ def create_user
134
+ puts "Creating default user.."
135
+ users = [{"name" => "Administrator", "pass" => b64_enc(BCrypt::Password.create("password"))}]
136
+ File.open("./data/users", "w") do |fh|
137
+ fh.write({"users" => users}.to_yaml)
138
+ end
139
+ FileUtils.chmod 0600, './data/users'
140
+ end
141
+
142
+ def b64_enc(obj)
143
+ Base64.strict_encode64(obj)
144
+ end
145
+
128
146
  def ask_user_for(opt, question)
129
147
  unless @config[opt]
130
148
  @config[opt] = ask_user question
@@ -0,0 +1,19 @@
1
+ <div class="col-lg-12">
2
+ <div class="col-lg-4"></div>
3
+ <div class="col-lg-4">
4
+ <div class="panel panel-default">
5
+ <div class="panel-body">
6
+ <form role="form" name="login-form" action="/login" method="post">
7
+ <div class="form-group">
8
+ <input type="text" class="form-control" name="user" placeholder="Username">
9
+ </div>
10
+ <div class="form-group">
11
+ <input type="password" class="form-control" name="pass" placeholder="Password">
12
+ </div>
13
+ <button id="login-btn" type="submit" class="btn btn-default">Submit</button>
14
+ </form>
15
+ </div>
16
+ </div>
17
+ </div>
18
+ <div class="col-lg-4"></div>
19
+ </div>
@@ -0,0 +1,26 @@
1
+ module Teamster
2
+ module Core
3
+ module CoreHelper
4
+ def summary_div_class_for(index)
5
+ size = all_modules.size
6
+ if size == 1
7
+ "col-lg-12"
8
+ elsif size%2 == 0
9
+ "col-lg-6"
10
+ else
11
+ last = size - 1
12
+ index == last ? "col-lg-12" : "col-lg-6"
13
+ end
14
+ end
15
+
16
+ def summary_of(module_name)
17
+ name = module_name.downcase
18
+ if send(:"#{name}_summary?")
19
+ send(:"#{name}_summary")
20
+ else
21
+ erb :no_summary
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -85,8 +85,8 @@ module Teamster
85
85
  shuffle ? all_modules.shuffle : all_modules
86
86
  end
87
87
 
88
- def find_template(views, name, engine, &block)
89
- App.views.each {|v| super(v, name, engine, &block)}
88
+ def find_template(views, *args, &block)
89
+ App.views.each {|v| super(v, *args, &block)}
90
90
  end
91
91
  end
92
92
  end
@@ -1,22 +1,54 @@
1
+ require 'bcrypt'
2
+ require 'base64'
3
+ require_relative 'login_helper'
4
+
1
5
  module Teamster
2
6
  module Core
3
7
  class Login < Sinatra::Base
4
- helpers do
5
- def redirect_back
6
- referrer = URI::parse(request.referrer)
7
- redirect to referrer.path
8
- end
8
+ @@referrer = nil
9
+ @@root = Dir.pwd
10
+ USERS_FILE = './data/users'
11
+
12
+ configure do
13
+ set :root, @@root
14
+ set :views, "#{settings.root}/views"
15
+ set :users, YAML.load_file("#{settings.root}/#{USERS_FILE}").fetch("users")
16
+ set :referrer, nil
9
17
  end
10
18
 
19
+ helpers GeneralHelper, LoginHelper
20
+
11
21
  get '/login/?' do
12
- session[:current_user] = "A Registered User (Login Not Implemented)"
13
- redirect_back
22
+ referrer URI::parse(request.referrer)
23
+ erb :login
24
+ end
25
+
26
+ post '/login' do
27
+ if user = settings.users.find {|u| u['name'] == params[:user]}
28
+ if BCrypt::Password.new(decode(user['pass'])) == params[:pass]
29
+ session[:current_user] = user['name']
30
+ redirect_back
31
+ else
32
+ login_error
33
+ end
34
+ else
35
+ login_error
36
+ end
14
37
  end
15
38
 
16
39
  get '/logout/?' do
40
+ referrer URI::parse(request.referrer)
17
41
  session[:current_user] = nil
18
42
  redirect_back
19
43
  end
44
+
45
+ def self.referrer
46
+ @@referrer
47
+ end
48
+
49
+ def self.set_referrer_to(path)
50
+ @@referrer = path
51
+ end
20
52
  end
21
53
  end
22
54
  end
@@ -0,0 +1,23 @@
1
+ module Teamster
2
+ module Core
3
+ module LoginHelper
4
+ def decode(obj)
5
+ Base64.decode64 obj
6
+ end
7
+
8
+ def referrer(ref)
9
+ settings.referrer = ref.path
10
+ end
11
+
12
+ def redirect_back
13
+ ref = settings.referrer || '/'
14
+ settings.referrer = nil
15
+ redirect to ref
16
+ end
17
+
18
+ def login_error
19
+ halt 403, 'Wrong username or password provided!'
20
+ end
21
+ end
22
+ end
23
+ end
data/lib/teamster.rb CHANGED
@@ -2,9 +2,9 @@ require 'sinatra/base'
2
2
  require 'yaml'
3
3
  require 'json'
4
4
  require 'uri'
5
- require_relative 'teamster/login'
6
5
  require_relative 'teamster/general_helper'
7
- require_relative 'teamster/base_module'
6
+ require_relative 'teamster/core_helper'
7
+ require_relative 'teamster/login'
8
8
 
9
9
  module Teamster
10
10
  module Core
@@ -12,7 +12,8 @@ module Teamster
12
12
  @@modules = []
13
13
  @@views = []
14
14
  @@title = 'TEAMSTER'
15
- CORE_CONFIG = 'conf/teamster.conf'
15
+ @@root = Dir.pwd
16
+ CORE_CONFIG = './conf/teamster.conf'
16
17
 
17
18
  # NOTE: Class methods used in configure block needs be declared
18
19
  # before the configure block.
@@ -20,47 +21,23 @@ module Teamster
20
21
  @@title = core_opts[:title]
21
22
  end
22
23
 
23
- def self.current_working_folder
24
- Dir.pwd
25
- end
26
-
27
24
  configure do
28
- set :root, current_working_folder
25
+ set :root, @@root
26
+ set :referrer, nil
29
27
  @@views << "#{settings.root}/views"
30
28
  enable :sessions
31
29
  set :session_secret, 'THIS IS MY SESSION SECRET KEY'
32
- set :core_opts, YAML.load_file(CORE_CONFIG)
30
+ set :core_opts, YAML.load_file("#{settings.root}/#{CORE_CONFIG}")
33
31
  set_default_options_from settings.core_opts
34
32
  use Login
35
33
  end
36
34
 
37
- helpers GeneralHelper
35
+ helpers GeneralHelper, CoreHelper
38
36
 
39
37
  get '/' do
40
38
  erb :index
41
39
  end
42
40
 
43
- def summary_div_class_for(index)
44
- size = all_modules.size
45
- if size == 1
46
- "col-lg-12"
47
- elsif size%2 == 0
48
- "col-lg-6"
49
- else
50
- last = size - 1
51
- index == last ? "col-lg-12" : "col-lg-6"
52
- end
53
- end
54
-
55
- def summary_of(module_name)
56
- name = module_name.downcase
57
- if send(:"#{name}_summary?")
58
- send(:"#{name}_summary")
59
- else
60
- erb :no_summary
61
- end
62
- end
63
-
64
41
  def self.modules
65
42
  @@modules
66
43
  end
@@ -73,6 +50,10 @@ module Teamster
73
50
  @@title
74
51
  end
75
52
 
53
+ def self.current_working_folder
54
+ @@root
55
+ end
56
+
76
57
  def self.use_module(teamster_module)
77
58
  if @@modules.include? teamster_module
78
59
  puts "Module #{teamster_module} already registered!"
@@ -91,3 +72,5 @@ module Teamster
91
72
  end
92
73
  end
93
74
  end
75
+
76
+ require_relative 'teamster/base_module'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: teamster
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.4
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nur Muhammad Bin Sirat
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-04-24 00:00:00.000000000 Z
11
+ date: 2014-04-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: puma
@@ -53,7 +53,6 @@ files:
53
53
  - Rakefile
54
54
  - VERSION
55
55
  - bin/teamster
56
- - config.ru
57
56
  - content/public/css/bootstrap.min.css
58
57
  - content/public/css/styles.css
59
58
  - content/public/fonts/glyphicons-halflings-regular.eot
@@ -66,13 +65,16 @@ files:
66
65
  - content/views/footer.erb
67
66
  - content/views/index.erb
68
67
  - content/views/layout.erb
68
+ - content/views/login.erb
69
69
  - content/views/login_required.erb
70
70
  - content/views/navbar.erb
71
71
  - content/views/no_summary.erb
72
72
  - lib/teamster.rb
73
73
  - lib/teamster/base_module.rb
74
+ - lib/teamster/core_helper.rb
74
75
  - lib/teamster/general_helper.rb
75
76
  - lib/teamster/login.rb
77
+ - lib/teamster/login_helper.rb
76
78
  - teamster.gemspec
77
79
  homepage: https://github.com/Umartyya/teamster
78
80
  licenses:
data/config.ru DELETED
@@ -1,2 +0,0 @@
1
- require './lib/teamster'
2
- run Teamster::App