Add dashboard, allow password resets when signed in

This commit is contained in:
Basti 2020-11-11 18:56:06 +01:00
parent 674b0a0ff5
commit a09741ba28
Signed by untrusted user: basti
GPG Key ID: 9F88009D31D99C72
14 changed files with 86 additions and 13 deletions

View File

@ -2,4 +2,10 @@ class ApplicationController < ActionController::Base
rescue_from DeviseLdapAuthenticatable::LdapException do |exception|
render :text => exception, :status => 500
end
def require_user_signed_in
unless user_signed_in?
redirect_to welcome_path and return
end
end
end

View File

@ -0,0 +1,6 @@
class DashboardController < ApplicationController
before_action :require_user_signed_in
def index
end
end

View File

@ -1,4 +1,13 @@
class SettingsController < ApplicationController
before_action :require_user_signed_in
def index
end
def reset_password
current_user.send_reset_password_instructions
sign_out current_user
msg = "We have sent you an email with a link to reset your password."
redirect_to check_your_email_path, notice: msg
end
end

View File

@ -1,7 +1,10 @@
class WelcomeController < ApplicationController
def index
if user_signed_in?
redirect_to settings_path and return
redirect_to root_path and return
end
end
def reset_password_check_email
end
end

View File

@ -0,0 +1,2 @@
module DashboardHelper
end

View File

@ -0,0 +1,9 @@
<h2>Dashboard</h2>
<p>Ohai.</p>
<h3>Password change</h3>
<p>
<%= form_with(url: settings_reset_password_path, method: :post) do %>
<%= submit_tag("Send me a password reset link") %>
<% end %>
</p>

View File

@ -16,9 +16,12 @@
Signed in as <strong><%= current_user.cn %>@kosmos.org</strong>.
<%= link_to "Log out", destroy_user_session_path, method: :delete %>
</p>
<% flash.each do |type, msg| %>
<% end %>
<% flash.each do |type, msg| %>
<div class="flash-msg-<%= type %>">
<p><%= msg %></p>
<% end %>
</div>
<% end %>
<%= yield %>

View File

@ -1,4 +1 @@
<h3>Password reset</h3>
<p>
<%= link_to "Reset my password" %>
</p>
<h2>Settings</h2>

View File

@ -0,0 +1,3 @@
<p>
You can close this window or tab now.
</p>

View File

@ -34,7 +34,7 @@ en:
no_token: "You can't access this page without coming from a password reset email. If you do come from a password reset email, please make sure you used the full URL provided."
send_instructions: "You will receive an email with instructions on how to reset your password in a few minutes."
send_paranoid_instructions: "If your email address exists in our database, you will receive a password recovery link at your email address in a few minutes."
updated: "Your password has been changed successfully. You are now signed in."
updated: "Your password has been changed successfully."
updated_not_active: "Your password has been changed successfully."
registrations:
destroyed: "Bye! Your account has been successfully cancelled. We hope to see you again soon."
@ -46,9 +46,9 @@ en:
updated: "Your account has been updated successfully."
updated_but_not_signed_in: "Your account has been updated successfully, but since your password was changed, you need to sign in again"
sessions:
signed_in: "Signed in successfully."
signed_out: "Signed out successfully."
already_signed_out: "Signed out successfully."
signed_in: ""
signed_out: ""
already_signed_out: ""
unlocks:
send_instructions: "You will receive an email with instructions for how to unlock your account in a few minutes."
send_paranoid_instructions: "If your account exists, you will receive an email with instructions for how to unlock it in a few minutes."

View File

@ -2,14 +2,17 @@ Rails.application.routes.draw do
devise_for :users
get 'settings', to: 'settings#index'
post 'settings_reset_password', to: 'settings#reset_password'
get 'welcome', to: 'welcome#index'
get 'check_your_email', to: 'welcome#check_your_email'
get 'ldap_users', to: 'ldap_users#index'
# Letter Opener (open "sent" emails in dev and staging)
if Rails.env.match(/staging|development/)
mount LetterOpenerWeb::Engine, at: "letter_opener"
end
root to: 'welcome#index'
root to: 'dashboard#index'
end

View File

@ -0,0 +1,15 @@
require 'rails_helper'
# Specs in this file have access to a helper object that includes
# the DashboardHelper. For example:
#
# describe DashboardHelper do
# describe "string concat" do
# it "concats two strings with spaces" do
# expect(helper.concat_strings("this","that")).to eq("this that")
# end
# end
# end
RSpec.describe DashboardHelper, type: :helper do
pending "add some examples to (or delete) #{__FILE__}"
end

View File

@ -0,0 +1,12 @@
require 'rails_helper'
RSpec.describe "Dashboards", type: :request do
describe "GET /index" do
it "returns http success" do
get "/dashboard/index"
expect(response).to have_http_status(:success)
end
end
end

View File

@ -0,0 +1,5 @@
require 'rails_helper'
RSpec.describe "dashboard/index.html.erb", type: :view do
pending "add some examples to (or delete) #{__FILE__}"
end