|
1 | 1 | require_relative "../commands/feeds/import_from_opml" |
2 | 2 | require_relative "../commands/users/create_user" |
| 3 | +require_relative "../commands/users/complete_setup" |
3 | 4 | require_relative "../repositories/user_repository" |
4 | 5 | require_relative "../repositories/story_repository" |
| 6 | +require_relative "../tasks/fetch_feeds" |
5 | 7 |
|
6 | 8 | class Stringer < Sinatra::Base |
7 | | - #before /\/(password|import)/ do |
8 | | - # if first_run_completed? |
9 | | - # redirect to("/news") |
10 | | - # end |
11 | | - #end |
12 | | - |
13 | | - get "/" do |
14 | | - if first_run_completed? |
15 | | - redirect to("/news") |
16 | | - else |
17 | | - redirect to("/password") |
| 9 | + namespace "/setup" do |
| 10 | + before do |
| 11 | + if UserRepository.setup_complete? |
| 12 | + redirect to("/news") |
| 13 | + end |
18 | 14 | end |
19 | | - end |
20 | | - |
21 | | - get "/password" do |
22 | | - erb :"first_run/password" |
23 | | - end |
24 | 15 |
|
25 | | - post "/password" do |
26 | | - if no_password(params) or password_mismatch?(params) |
27 | | - flash.now[:error] = "Hey, your password confirmation didn't match. Try again." |
| 16 | + get "/password" do |
28 | 17 | erb :"first_run/password" |
29 | | - else |
30 | | - CreateUser.new.create(params[:password]) |
| 18 | + end |
31 | 19 |
|
32 | | - redirect to("/import") |
| 20 | + post "/password" do |
| 21 | + if no_password(params) or password_mismatch?(params) |
| 22 | + flash.now[:error] = "Hey, your password confirmation didn't match. Try again." |
| 23 | + erb :"first_run/password" |
| 24 | + else |
| 25 | + user = CreateUser.new.create(params[:password]) |
| 26 | + session[:user_id] = user.id |
| 27 | + |
| 28 | + redirect to("/setup/import") |
| 29 | + end |
33 | 30 | end |
34 | | - end |
35 | 31 |
|
36 | | - get "/import" do |
37 | | - erb :import |
38 | | - end |
| 32 | + get "/import" do |
| 33 | + erb :import |
| 34 | + end |
39 | 35 |
|
40 | | - post "/import" do |
41 | | - ImportFromOpml.import(params["opml_file"][:tempfile].read, true) |
| 36 | + post "/import" do |
| 37 | + ImportFromOpml.import(params["opml_file"][:tempfile].read, true) |
42 | 38 |
|
43 | | - redirect to("/") |
44 | | - end |
| 39 | + redirect to("/setup/tutorial") |
| 40 | + end |
45 | 41 |
|
46 | | - get "/tutorial" do |
47 | | - @sample_stories = StoryRepository.samples |
48 | | - erb :tutorial |
49 | | - end |
| 42 | + get "/tutorial" do |
| 43 | + FetchFeeds.enqueue(Feed.all) |
| 44 | + CompleteSetup.complete(current_user) |
50 | 45 |
|
51 | | - private |
52 | | - def first_run_completed? |
53 | | - UserRepository.any? |
| 46 | + @sample_stories = StoryRepository.samples |
| 47 | + erb :tutorial |
| 48 | + end |
54 | 49 | end |
55 | 50 |
|
| 51 | + private |
56 | 52 | def no_password(params) |
57 | 53 | params[:password].nil? || params[:password] == "" |
58 | 54 | end |
|
0 commit comments