parent
0bc22be618
commit
2ac652efcd
@ -0,0 +1,95 @@ |
||||
#-- copyright |
||||
# OpenProject is a project management system. |
||||
# Copyright (C) 2012-2017 the OpenProject Foundation (OPF) |
||||
# |
||||
# This program is free software; you can redistribute it and/or |
||||
# modify it under the terms of the GNU General Public License version 3. |
||||
# |
||||
# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows: |
||||
# Copyright (C) 2006-2017 Jean-Philippe Lang |
||||
# Copyright (C) 2010-2013 the ChiliProject Team |
||||
# |
||||
# This program is free software; you can redistribute it and/or |
||||
# modify it under the terms of the GNU General Public License |
||||
# as published by the Free Software Foundation; either version 2 |
||||
# of the License, or (at your option) any later version. |
||||
# |
||||
# This program is distributed in the hope that it will be useful, |
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
# GNU General Public License for more details. |
||||
# |
||||
# You should have received a copy of the GNU General Public License |
||||
# along with this program; if not, write to the Free Software |
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
||||
# |
||||
# See doc/COPYRIGHT.rdoc for more details. |
||||
#++ |
||||
|
||||
## |
||||
# Intended to be used by the AccountController to implement the user consent |
||||
# check. |
||||
module Concerns::UserConsent |
||||
def consent |
||||
if !consent_required? |
||||
consent_finished |
||||
else |
||||
render 'account/consent', locals: { |
||||
consent_info: consent_info[I18n.locale], |
||||
consent_label: consent_label[I18n.locale] |
||||
} |
||||
end |
||||
end |
||||
|
||||
def confirm_consent |
||||
user = consenting_user |
||||
|
||||
if user.present? |
||||
update_user_consent! user |
||||
|
||||
consent_finished |
||||
else |
||||
consent_failed |
||||
end |
||||
end |
||||
|
||||
def consent_required? |
||||
Setting.consent_required? && consent_expired? |
||||
end |
||||
|
||||
def consent_expired? |
||||
return true if Setting.consent_date.blank? |
||||
|
||||
consented_at = consenting_user.try(:consented_at) |
||||
|
||||
if consented_at.present? |
||||
consented_at >= Setting.consent_date |
||||
else |
||||
false |
||||
end |
||||
end |
||||
|
||||
def consent_info |
||||
Setting.consent_info |
||||
end |
||||
|
||||
def consent_label |
||||
Setting.consent_label |
||||
end |
||||
|
||||
def consenting_user |
||||
User.find_by id: session[:authenticated_user_id] |
||||
end |
||||
|
||||
def update_user_consent!(user) |
||||
user.update consented_at: DateTime.now |
||||
end |
||||
|
||||
def consent_finished |
||||
redirect_to authentication_stage_complete_path(:consent) |
||||
end |
||||
|
||||
def consent_failed |
||||
redirect_to Stage.failure_path(:consent) |
||||
end |
||||
end |
@ -0,0 +1,55 @@ |
||||
<%#-- copyright |
||||
OpenProject is a project management system. |
||||
Copyright (C) 2012-2017 the OpenProject Foundation (OPF) |
||||
|
||||
This program is free software; you can redistribute it and/or |
||||
modify it under the terms of the GNU General Public License version 3. |
||||
|
||||
OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows: |
||||
Copyright (C) 2006-2017 Jean-Philippe Lang |
||||
Copyright (C) 2010-2013 the ChiliProject Team |
||||
|
||||
This program is free software; you can redistribute it and/or |
||||
modify it under the terms of the GNU General Public License |
||||
as published by the Free Software Foundation; either version 2 |
||||
of the License, or (at your option) any later version. |
||||
|
||||
This program is distributed in the hope that it will be useful, |
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
GNU General Public License for more details. |
||||
|
||||
You should have received a copy of the GNU General Public License |
||||
along with this program; if not, write to the Free Software |
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
||||
|
||||
See doc/COPYRIGHT.rdoc for more details. |
||||
|
||||
++#%> |
||||
|
||||
<% disable_accessibility_css! %> |
||||
|
||||
<% breadcrumb_paths("Consent") %> |
||||
<% html_title "Consent" %> |
||||
<%= call_hook :view_account_consent_top %> |
||||
<div id="login-form" class="form -bordered"> |
||||
<h1>Consent</h1> |
||||
|
||||
<%= format_text consent_info %> |
||||
|
||||
<%= form_tag(account_confirm_consent_path, method: :post, class: "form -wide-labels") do %> |
||||
<section class="form--section"> |
||||
<label class="form--label-with-check-box"> |
||||
<div class="form--check-box-container"> |
||||
<input type="checkbox" class="form--check-box" required="required"> |
||||
</div> |
||||
|
||||
<%= format_text consent_label %> |
||||
</label> |
||||
</section> |
||||
<section class="form--section"> |
||||
<input type="submit" class="button -highlight" value="OK"/> |
||||
</section> |
||||
<% end %> |
||||
</div> |
||||
<%= call_hook :view_account_consent_bottom %> |
@ -0,0 +1,7 @@ |
||||
OpenProject::Authentication::Stage |
||||
.register( |
||||
:consent, |
||||
active: ->() { Setting.consent_required? } |
||||
) { |
||||
account_consent_path |
||||
} |
@ -0,0 +1,5 @@ |
||||
class AddConsentTimestampToUser < ActiveRecord::Migration[5.0] |
||||
def change |
||||
add_column :users, :consented_at, :datetime |
||||
end |
||||
end |
Loading…
Reference in new issue