Skip to content

Commit 9da45d3

Browse files
author
Matt Swanson
committed
add redirects once first-run is done.
1 parent ff39651 commit 9da45d3

3 files changed

Lines changed: 28 additions & 10 deletions

File tree

‎app.rb‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,6 @@ def render_partial(name, locals = {})
3333
redirect '/login'
3434
end
3535
end
36-
37-
get "/" do
38-
redirect to("/news")
39-
end
4036
end
4137

4238
require_relative "app/controllers/stories_controller"

‎app/controllers/first_run_controller.rb‎

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
require_relative "../commands/feeds/import_from_opml"
22
require_relative "../commands/users/create_user"
3+
require_relative "../repositories/user_repository"
34

45
class Stringer < Sinatra::Base
5-
get "/import" do
6-
erb :import
6+
before /\/(password|import)/ do
7+
if first_run_completed?
8+
redirect to("/news")
9+
end
710
end
811

9-
post "/import" do
10-
ImportFromOpml.import(params["opml_file"][:tempfile].read, true)
11-
12-
redirect to("/")
12+
get "/" do
13+
redirect to("/password")
1314
end
1415

1516
get "/password" do
@@ -27,7 +28,21 @@ class Stringer < Sinatra::Base
2728
end
2829
end
2930

31+
get "/import" do
32+
erb :import
33+
end
34+
35+
post "/import" do
36+
ImportFromOpml.import(params["opml_file"][:tempfile].read, true)
37+
38+
redirect to("/")
39+
end
40+
3041
private
42+
def first_run_completed?
43+
UserRepository.any?
44+
end
45+
3146
def no_password(params)
3247
params[:password].nil? || params[:password] == ""
3348
end
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
require_relative "../models/user"
2+
3+
class UserRepository
4+
def self.any?
5+
User.any?
6+
end
7+
end

0 commit comments

Comments
 (0)