-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
105 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,7 @@ def update | |
private | ||
def set_user | ||
@user = Current.user | ||
redirect_to root_path, notice: "You can't change the demo email address" if @user.email == "[email protected]" | ||
end | ||
|
||
def user_params | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,7 @@ def update | |
private | ||
def set_user | ||
@user = Current.user | ||
redirect_to root_path, notice: "You can't change the demo password" if @user.email == "[email protected]" | ||
end | ||
|
||
def user_params | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ | |
# Sessions Controller | ||
class SessionsController < ApplicationController | ||
skip_before_action :authenticate, only: %i[new create] | ||
before_action :prep_demo, only: :create | ||
|
||
before_action :set_session, only: :destroy | ||
|
||
|
@@ -13,16 +14,15 @@ def index | |
def new; end | ||
|
||
def create | ||
if (user = User.authenticate_by(email: params[:email], password: params[:password])) | ||
@session = user.sessions.create! | ||
if @user ||= User.authenticate_by(email: params[:email], password: params[:password]) | ||
@session = @user.sessions.create! | ||
cookies.signed.permanent[:session_token] = { value: @session.id, httponly: true } | ||
|
||
redirect_to workspaces_path, notice: "Signed in successfully" | ||
else | ||
redirect_to sign_in_path(email_hint: params[:email]), notice: "That email or password is incorrect" | ||
end | ||
end | ||
# rubocop:enable Metrics/AbcSize | ||
|
||
def destroy | ||
@session.destroy | ||
|
@@ -33,4 +33,10 @@ def destroy | |
def set_session | ||
@session = Current.user.sessions.find(params[:id]) | ||
end | ||
|
||
def prep_demo | ||
if params[:email] == "[email protected]" | ||
@user = DemoPrep.initialize_demo("[email protected]") | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# frozen_string_literal: true | ||
|
||
class DemoPrep | ||
def self.initialize_demo(email) | ||
user = User.find_by(email: email) | ||
if !user | ||
user = FactoryBot.create(:user_with_workspace, email: email) | ||
populate_workspace(user.workspaces.first) | ||
elsif user.created_at.to_date != Date.today | ||
user.workspaces.each do |workspace| | ||
workspace.destroy | ||
end | ||
workspace = user.workspaces.create(name: "Workspace 1") | ||
populate_workspace(workspace) | ||
end | ||
user | ||
end | ||
|
||
def self.populate_workspace(workspace) | ||
b = workspace.boards.create(name: "Board 1") | ||
b.lists.create(title: "List 1") | ||
b.lists.create(title: "List 2") | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,13 @@ | |
<h1 class="my-8 text-3xl font-extrabold text-gray-900 dark:text-white md:text-5xl lg:text-6xl">I can has <span class="text-transparent bg-clip-text bg-gradient-to-r to-emerald-600 from-sky-400">Kanban?</span></h1> | ||
<h2 class="mb-4 text-3xl font-extrabold tracking-tight leading-none text-gray-900 md:text-4xl lg:text-5xl dark:text-white">Yes, you can!</h1> | ||
<p class="py-5 mb-8 text-lg font-normal text-gray-500 lg:text-xl sm:px-16 lg:px-48 dark:text-gray-400">Find out how Kanban boards can help you organize your work and your life. And with our low, low prices you can surely still afford that delicious cheezburger!</p> | ||
<div class="flex flex-col space-y-4 sm:flex-row sm:justify-center sm:space-y-0 mb-8"> | ||
<%= form_with(url: sign_in_path) do |form| %> | ||
<%= form.text_field :email, value: "[email protected]", readonly: "true", hidden: "true" %> | ||
<%= form.password_field :password, value: 'testtest123456', readonly: "true", hidden: "true" %> | ||
<%= form.button "Sign in as Demo User", class: "inline-flex justify-center items-center py-3 px-5 text-base font-medium text-center text-white rounded-lg bg-blue-700 hover:bg-blue-800 focus:ring-4 focus:ring-blue-300 dark:focus:ring-blue-900" %> | ||
<% end %> | ||
</div> | ||
</div> | ||
<img class="basis-1/3 object-scale-down" src="/images/i_kan_has_kanban.png" alt="Kanban Kat"> | ||
</div> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,6 +31,14 @@ class SessionsControllerTest < ActionDispatch::IntegrationTest | |
assert_response :success | ||
end | ||
|
||
test "should sign in [email protected] with any password" do | ||
post sign_in_url, params: { email: "[email protected]", password: "12345abcdefg" } | ||
|
||
assert assert_redirected_to workspaces_url | ||
get workspaces_url | ||
assert_response :success | ||
end | ||
|
||
test "should not sign in with wrong credentials" do | ||
post sign_in_url, params: { email: @user.email, password: "SecretWrong1*3" } | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# frozen_string_literal: true | ||
|
||
require "test_helper" | ||
|
||
class DemoPrepTest < ActiveSupport::TestCase | ||
test "initialize demo if no users exist" do | ||
user = User.find_by(email: "[email protected]") | ||
assert_nil user | ||
user = DemoPrep.initialize_demo("[email protected]") | ||
assert user | ||
end | ||
|
||
test "if user exists and was created today, do nothing" do | ||
user = create(:user_with_workspace, email: "[email protected]") | ||
user.workspaces.create(name: "Workspace 2") | ||
assert_equal 2, user.workspaces.count | ||
demo_user = DemoPrep.initialize_demo("[email protected]") | ||
assert_equal 2, demo_user.workspaces.count | ||
end | ||
|
||
test "if user exists and was not created today, create empty workspace" do | ||
user = create(:user_with_workspace, email: "[email protected]") | ||
user.workspaces.create(name: "Workspace 2") | ||
assert_equal 2, user.workspaces.count | ||
travel 1.day do | ||
demo_user = DemoPrep.initialize_demo("[email protected]") | ||
assert_equal 1, demo_user.workspaces.count | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters