summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
Diffstat (limited to 'app')
-rw-r--r--app/assets/stylesheets/leap.scss3
-rw-r--r--app/controllers/sessions_controller.rb9
-rw-r--r--app/controllers/users_controller.rb6
-rw-r--r--app/models/anonymous_user.rb5
-rw-r--r--app/models/invite_code.rb1
-rw-r--r--app/models/invite_code_validator.rb7
-rw-r--r--app/models/user.rb7
-rw-r--r--app/views/layouts/_footer.html.haml1
-rw-r--r--app/views/layouts/_navigation.html.haml6
-rw-r--r--app/views/users/_user.html.haml34
-rw-r--r--app/views/users/index.html.haml3
11 files changed, 71 insertions, 11 deletions
diff --git a/app/assets/stylesheets/leap.scss b/app/assets/stylesheets/leap.scss
index dddcc1a..9fe2195 100644
--- a/app/assets/stylesheets/leap.scss
+++ b/app/assets/stylesheets/leap.scss
@@ -307,3 +307,6 @@ html, body {
margin: 0 2px;
}
}
+.modal-footer form{
+ margin: 0;
+}
diff --git a/app/controllers/sessions_controller.rb b/app/controllers/sessions_controller.rb
index 66eba40..34d4f53 100644
--- a/app/controllers/sessions_controller.rb
+++ b/app/controllers/sessions_controller.rb
@@ -32,4 +32,13 @@ class SessionsController < ApplicationController
# throw :warden, response.finish
#end
+ Warden::Manager.after_set_user do |user, auth, opts|
+ scope = opts[:scope]
+ unless user.enabled?
+ auth.logout(scope)
+ throw(:warden, scope: scope, reason: "User not active")
+ end
+ end
+
+
end
diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb
index 3943afc..446b726 100644
--- a/app/controllers/users_controller.rb
+++ b/app/controllers/users_controller.rb
@@ -49,13 +49,15 @@ class UsersController < ApplicationController
def deactivate
@user.enabled = false
@user.save
- respond_with @user
+ flash[:notice] = I18n.t("actions.user_disabled_message", username: @user.username)
+ redirect_to :back
end
def enable
@user.enabled = true
@user.save
- respond_with @user
+ flash[:notice] = I18n.t("actions.user_enabled_message", username: @user.username)
+ redirect_to :back
end
def destroy
diff --git a/app/models/anonymous_user.rb b/app/models/anonymous_user.rb
index 0c1f540..73e95e5 100644
--- a/app/models/anonymous_user.rb
+++ b/app/models/anonymous_user.rb
@@ -12,6 +12,10 @@ class AnonymousUser < Object
def id
nil
end
+
+ def has_payment_info?
+ false
+ end
def email
nil
@@ -32,4 +36,5 @@ class AnonymousUser < Object
def is_anonymous?
true
end
+
end
diff --git a/app/models/invite_code.rb b/app/models/invite_code.rb
index 6fcc427..5666a4f 100644
--- a/app/models/invite_code.rb
+++ b/app/models/invite_code.rb
@@ -5,6 +5,7 @@ class InviteCode < CouchRest::Model::Base
use_database 'invite_codes'
property :invite_code, String, :read_only => true
property :invite_count, Integer, :default => 0, :accessible => true
+ property :max_uses, Integer, :default => 1
timestamps!
diff --git a/app/models/invite_code_validator.rb b/app/models/invite_code_validator.rb
index f96ca4a..676e4fa 100644
--- a/app/models/invite_code_validator.rb
+++ b/app/models/invite_code_validator.rb
@@ -1,4 +1,5 @@
class InviteCodeValidator < ActiveModel::Validator
+
def validate(user)
user_invite_code = InviteCode.find_by_invite_code user.invite_code
@@ -6,7 +7,7 @@ class InviteCodeValidator < ActiveModel::Validator
if not_existent?(user_invite_code)
add_error_to_user("This is not a valid code", user)
- elsif count_greater_than_zero?(user_invite_code)
+ elsif has_no_uses_left?(user_invite_code)
add_error_to_user("This code has already been used", user)
end
end
@@ -16,8 +17,8 @@ class InviteCodeValidator < ActiveModel::Validator
code == nil
end
- def count_greater_than_zero?(code)
- code.invite_count > 0
+ def has_no_uses_left?(code)
+ code.invite_count >= code.max_uses
end
def add_error_to_user(error, user)
diff --git a/app/models/user.rb b/app/models/user.rb
index 3daee0f..4bb1e79 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -9,6 +9,9 @@ class User < CouchRest::Model::Base
property :contact_email, String, :accessible => true
property :contact_email_key, String, :accessible => true
property :invite_code, String, :accessible => true
+ property :braintree_customer_id, Integer, :accessible => true
+ property :subscription_id, String, :accessible => true
+
property :enabled, TrueClass, :default => true
# these will be null by default but we shouldn't ever pull them directly, but only via the methods that will return the full ServiceLevel
@@ -177,6 +180,10 @@ class User < CouchRest::Model::Base
end
+ def has_payment_info?
+ braintree_customer_id
+ end
+
protected
##
diff --git a/app/views/layouts/_footer.html.haml b/app/views/layouts/_footer.html.haml
index fa523d4..ff84dff 100644
--- a/app/views/layouts/_footer.html.haml
+++ b/app/views/layouts/_footer.html.haml
@@ -15,3 +15,4 @@
= link_to icon('comment') + t(:contact), contact_path
- if paid_service_level?
= link_to icon('shopping-cart') + t(:pricing), pricing_path
+ = link_to icon('barcode') + t(:Donations), new_payment_path if APP_CONFIG[:payment].present?
diff --git a/app/views/layouts/_navigation.html.haml b/app/views/layouts/_navigation.html.haml
index dccba0c..63a361a 100644
--- a/app/views/layouts/_navigation.html.haml
+++ b/app/views/layouts/_navigation.html.haml
@@ -7,6 +7,8 @@
= link_to_navigation ".tickets", auto_tickets_path,
active: controller?(:tickets)
- if APP_CONFIG[:billing]
- = link_to_navigation :billing_settings, billing_top_link(@user),
- active: controller?(:customer, :payments, :subscriptions, :credit_card_info)
+ = link_to_navigation :donations, new_payment_path,
+ active: (controller?(:donations) and action?(:new))
+ = link_to_navigation :subscriptions, billing_top_link(@braintree_customer_id),
+ active: controller?(:subscriptions)
= link_to_navigation :logout, logout_path, method: :delete
diff --git a/app/views/users/_user.html.haml b/app/views/users/_user.html.haml
index 583d22f..1cabcf5 100644
--- a/app/views/users/_user.html.haml
+++ b/app/views/users/_user.html.haml
@@ -1,4 +1,32 @@
%tr
- %td= link_to user.login, user
- %td= l(user.created_at, :format => :short)
- %td= l(user.updated_at, :format => :short)
+ %td
+ = link_to user.username, user
+ %td
+ = user.created_at.strftime("%d %b, %Y, %H:%M")
+ %td
+ = user.updated_at.strftime("%d %b, %Y, %H:%M")
+ %td
+ - if user.enabled
+ %button.btn.btn-default{:"data-toggle" => "modal", :"data-target" => "#user-form-#{user.id}", :type => "button"}
+ = t("actions.disable_user")
+ .modal.fade.hide{:id => "user-form-#{user.id}"}
+ .modal-dialog
+ .modal-content
+ .modal-header
+ %button.close{:"data-dismiss" => "modal"} ×
+ = t("actions.confirm_user_deactivation", username: user.username)
+ .modal-footer
+ = form_tag deactivate_user_path(user) do
+ %input.btn.btn-default.btn-danger{:type => "submit", :value => "#{t("actions.disable_user")}"}
+ - else
+ %button.btn.btn-default{:"data-toggle" => "modal", :"data-target" => "#user-form-#{user.id}", :type => "button"}
+ = t("actions.enable_user")
+ .modal.fade.hide{:id => "user-form-#{user.id}"}
+ .modal-dialog
+ .modal-content
+ .modal-header
+ %button.close{:"data-dismiss" => "modal"} ×
+ = t("actions.confirm_user_activation", username: user.username)
+ .modal-footer
+ = form_tag enable_user_path(user) do
+ %input.btn.btn-default.btn-danger{:type => "submit", :value => "#{t("actions.enable_user")}"}
diff --git a/app/views/users/index.html.haml b/app/views/users/index.html.haml
index 3ed8835..e1136d8 100644
--- a/app/views/users/index.html.haml
+++ b/app/views/users/index.html.haml
@@ -1,4 +1,5 @@
- @show_navigation = false
= search :users
-= table @users, %w(username, created, updated)
+= table @users, %w(username, created, updated, actions.toggle_user)
+